This document describes the input and output parameters of calling Alibaba Cloud Model Studio applications (agents, workflows) through the DashScope API, and provides call examples in typical scenarios.
This document applies only to the China (Beijing) region.
HTTP API callsRequest URL: POST https://dashscope.aliyuncs.com/api/v1/apps/APP_ID/completion
Where APP_ID must be replaced with your actual application ID
SDK callsPython/Java SDK: This document has the correct endpoint configured by defaultCustom endpoint: configurable via the base_url parameter
Online testing: Go to Application card -> Publish -> API testing to open the testing page, then fill in the parameters and click Run.
Request body
app_idstring(required)Application identifier.You can obtain the application ID on the application card of the My Applications page.
In the Java SDK, it is appId.For HTTP calls, put your actual application ID in the URL to replace APP_ID.
promptstring(required)The user's input instruction, used to guide the application to generate a reply.
For HTTP calls, put prompt into the input object.
session_idstring (optional)Session identifier for conversation history.When session_id is passed, the request automatically carries the conversation history stored in the cloud. In this case, prompt must be passed.This ID automatically expires after 1 consecutive hour without any requests.
In the Java SDK, this is setSessionId. When calling via HTTP, put session_id into the input object.
messagesarray (optional)The context passed to the model, arranged in conversation order.When using the messages parameter for multi-turn conversations, you do not need to pass prompt and session_id.If both session_id and messages are passed, the model prioritizes the content in messages and ignores session_id and prompt.
When calling via HTTP, put messages into the input object.
To use this parameter, the Python Dashscope SDK version must be at least 2.0.1, and the Java Dashscope SDK version must be at least 2.17.0.
Message type
System Messageobject (optional)The system message, used to define the model's role, tone, task objectives, or constraints. It is generally placed first in the messages array.
Property
contentstring (required)The system instruction, used to specify the model's role, behavior rules, response style, and task constraints.rolestring (required)The role of the system message, fixed as system.
User Messageobject (required)The user message, used to pass questions, instructions, or context to the model.
Property
contentstring (required)The message content.
Property
textstring (required)The input text.
rolestring (required)The role of the user message, fixed as user.
Assistant Messageobject (optional)The model's reply. It is usually passed back to the model as context in multi-turn conversations.
Property
contentstring (required)The text content of the model's reply.rolestring (required)The role of the assistant message, fixed as assistant.
workspacestring (optional)The workspace identifier. Related documentation: Obtain Workspace ID.Pass workspace ID only when calling applications in a sub-workspace.
When calling via HTTP, specify X-DashScope-WorkSpace in the header.
streamboolean (optional) Default value: FalseWhether to respond in streaming output mode.It is recommended to set it to True, which improves the reading experience and reduces the risk of timeouts.Parameter values:
False (default): The model returns all content at once after generation is complete.
True (recommended): Content is output while being generated, and a data chunk is returned each time part of the content is generated. You need to read these chunks one by one in real time to assemble the complete reply.
To implement streaming output with the Java SDK, call the streamCall interface; to implement streaming output over HTTP, specify X-DashScope-SSE as enable in the Header.
incremental_outputboolean (optional) Default value: FalseWhether to enable incremental output in streaming output mode.It is recommended to set it to True to improve the reading experience.Parameter values:
False (default): Each output returns the entire sequence generated so far, and the last output is the complete generated result.
Copy
II likeI like appleI like apple.
True (recommended): Incremental output, that is, subsequent output does not include content that has already been output. You need to read these fragments one by one in real time to obtain the complete result.
Copy
Ilikeapple.
In the Java SDK, it is incrementalOutput. When calling over HTTP, put incremental_output into the parameters object.
flow_stream_modestring (optional) Default value: full_thoughtsThe streaming output mode of workflow applications. Related documentation: Streaming output.Parameter values:
message_format_plus (recommended): Enhanced message mode.Outputs the execution process and results of all nodes in the workflow_message field, covering all node types. It returns the same data structure as message_format, but supports streaming push for all node types.
Client-side processing rules: for text nodes (OUTPUT / END text mode), message.content is an incremental delta and must be appended; for JSON nodes (LLM / Component / AgentGroup, etc.), message.content is a complete JSON snapshot and must be replaced as a whole. When node_is_completed=true, the node is marked as completed.
Sub-canvas node streaming: nodes inside the sub-canvas of loop nodes and batch processing nodes are also pushed in a streaming manner, identified by the response field parent_node_id that indicates the parent node they belong to.
Nested sub-canvas is not supported yet: loop or batch processing nodes cannot be placed inside the sub-canvas of loop/batch processing nodes.
In the Java SDK, it is FlowStreamMode.MESSAGE_FORMAT_PLUS.
message_format (recommended): Message mode.Outputs the results of specified nodes (Output nodes or End nodes) in the message field.
Enable the streaming output switch for the target node in the application in the console to return results in a streaming manner; if not enabled, the final result of the node is returned all at once.
In the Java SDK, it is FlowStreamMode.MESSAGE_FORMAT.
full_thoughts (default): Full thoughts mode.
Not recommended for new business. We recommend using message_format or message_format_plus instead.
Outputs the results of all nodes in the thoughts field.
When using this mode, you must also set the has_thoughts parameter to True.
In the Java SDK, it is FlowStreamMode.FULL_THOUGHTS.
The Python SDK must be 2.0.1 or later, and the Java SDK must be 2.22.23 or later. When calling over HTTP, put flow_stream_mode into the parameters object.
In the Java SDK, this is bizParams. When calling via HTTP, put biz_params into the input object.
For workflow applications, the custom variables of the start node are passed directly. Example:
Copy
biz_params = {"city": "杭州"}
For agent applications, prompt variables or plug-in variable parameters are passed via the following fields:
Property
user_prompt_paramsobject (optional)Represents custom prompt variable parameter information.Variable names within an application must be unique, with a limit of 10.Usage steps:
user_defined_paramsobject (optional)Represents custom plug-in parameter information.Plug-ins added within an application must be unique, with a limit of 10.
Property
tool_idstring (optional)The plug-in ID, which can be obtained from the plug-in card.${plugin_params}string (optional)Multiple key-value pairs contained in the innermost level of the object. Each key-value pair represents a user-defined parameter name to be passed and its specified value. For example:
Copy
"article_index": 2
Usage steps:
Associate the specified plug-in in the application, and publish the application.
The API call passes plug-in information through this parameter.
You can provide multiple key-value pairs, where each key is the plug-in's TOOL_ID and the value is the parameter object required by that plug-in. Example:
user_defined_tokensobject (optional)Represents user-level authentication information for custom plug-ins.Plug-ins added within an application must be unique, with a limit of 10.
Property
tool_idstring (optional)The plug-in ID, which can be obtained from the plug-in card. Passed via the <TOOL_ID> field.user_tokenstring (optional)Passes the user authentication information required by the plug-in, such as the actual value of DASHSCOPE_API_KEY.
Usage steps:
Associate the specified plug-in in the application, and publish the application.
The API call passes the plug-in's user-level authentication information through this parameter.
You can provide multiple key-value pairs, where each key is the plug-in's TOOL_ID and the value is a user_token object.
memory_idstring (optional)The long-term memory ID. See CreateMemory to create one. Related document: long-term memory.
Only agent applications support this parameter.
Enable the long-term memory switch in the application, and publish the application.
When calling the application with a specified memory_id, the system automatically builds and saves long-term memories based on user preferences.
On subsequent calls with the same memory_id, the system restores these long-term memories and merges them with the latest user message before providing them to the model for processing.
In the Java SDK, this is memoryId. When calling via HTTP, put memory_id into the input object.
has_thoughtsboolean (Optional) The default value is FalseWhether to output the process of plug-in calls and knowledge retrieval, or the thinking process of a model with thinking mode enabled. You can view it in the thoughts field.Parameter values:
True: Output.
False (default): Do not output.
In the Java SDK, this is hasThoughts. When calling via HTTP, put has_thoughts in the parameters object.
image_listarray (Optional)A list of images. Supports image URLs and Data URLs (Base64-encoded). You must select a vision and video understanding model in the application.The base64 encoding format can be constructed as a Data URL: data:[MIME_type];base64,{base64_image}. For details and code examples, see the visual understanding section on the right side of this document.Scenarios:
Image retrieval (agent applications): Retrieve structured knowledge bases that contain image links based on the uploaded image links.
Visual understanding: Use the visual understanding capability of the Qwen VL series models to analyze image content for question answering.
In the Java SDK, this is files. When calling via HTTP, put file_list in the input object.
The Python DashScope SDK version must be 2.0.1 or later, and the Java DashScope SDK version must be 2.21.13 or later.
rag_optionsobject (Optional)Used to configure retrieval-related parameters, including but not limited to retrieving from specified knowledge bases or documents. For more information, see Retrieve knowledge bases.
Only agent applications support this parameter.
In the Java SDK, this is ragOptions. When calling via HTTP, put rag_options in the parameters object.
Property
pipeline_idsarray (Required)A list that contains one or more knowledge base IDs. The maximum is 5.Retrieve all documents in the specified knowledge bases.How to obtain:
Obtain the knowledge base ID on the Knowledge Base page;
Or use the Data.Id returned by the CreateIndex API (only supports unstructured knowledge bases).
In the Java SDK, this is pipelineIds.
file_idsarray (Optional)A list that contains one or more unstructured document IDs. The maximum is 5.Retrieve unstructured documents in the specified knowledge bases.When passing in document IDs, you must also pass the knowledge base IDs to which these documents belong in the pipeline_ids field.How to obtain:
In Collections, click Details for the target file dataset. Get the document ID from the file list.
Or through the ID returned by the AddFile API for importing documents.
In the Java SDK, it is fileIds.
metadata_filterobject (Optional)Used to filter the metadata of unstructured documents. By specifying one or more key-value pairs, unstructured documents with this metadata in the specified knowledge base are retrieved.Prerequisites:When passing in metadata, you must also pass the knowledge base IDs to which the metadata belongs in the pipeline_ids field.How to view:
Visit the Knowledge Base page and click View Details Meta Information on the knowledge base card to view it.
This object consists of one or more key-value pairs:
Key: of type String, representing the name of the metadata.
Value:
Single-value matching: The value is a String, indicating that only documents whose field value is exactly equal to this string are retrieved.
Example: "author": "John.Doe"
Multiple-value "OR" matching: The value is an Array or List containing multiple String values. This indicates retrieving documents whose field value matches any value in the array (the logic is OR).
Combination logic: Different keys are combined with "AND" logic. For example, "author": "John.Doe", "source": ["internal_wiki", "public_docs"] means filtering out documents whose author is "John.Doe" and whose source is "internal_wiki" or "public_docs".
In the Java SDK, it is metadataFilter.
tagsarray (Optional)A list containing one or more unstructured document tags.Retrieves unstructured documents that have these tags.How to view:
In Collections, click Details for the target file dataset and check the tags on the document.
structured_filterobject (Optional)Used to perform metadata filtering on structured data. By specifying one or more key-value pairs, you can filter out document chunks that meet the conditions.How to view:
On the Knowledge Base page, click View Details View Index on the knowledge base card to view it.
This object consists of one or more key-value pairs:
Each key (column name) must have a corresponding value; filtering by column name only is not supported.
Key: Must be of type String, representing the name of the metadata field (column name) to filter.
Value:
Single-condition matching: The value is a String or Number, indicating that only documents whose field value exactly matches are retrieved. Example: "category": "Company News".
Multiple-value "OR" matching: The value is an Array or List containing multiple String or Number values. This indicates retrieving documents whose field value matches any value in the array (the logic is OR). Example: "year": 2024, "department": ["Engineering", "Product"].
Combination logic: Different keys are combined with "AND" logic. For example, "year": 2024, "department": ["Engineering", "Product"] means filtering out document chunks whose year is 2024 and whose department is "Engineering" or "Product".
In the Java SDK, it is structuredFilter.
session_file_idsarray(Optional)A list containing one or more file IDs. The maximum is 10.
Only agent applications support this parameter.
When calling an agent application, pass the file IDs, and the system will extract the text content from the files as the content basis for LLM question answering.Related document: Upload files (documents, images, videos, or audio).
The session file ID must start with "file_session_" and the file status must be FILE_IS_READY. Otherwise, the call fails.
In the Java SDK, it is sessionFileIds.
The Python DashScope SDK must be at least 2.0.1, and the Java DashScope SDK must be at least 2.17.0.
model_idstring(Optional)The model name.
Only agent applications support this parameter.
When calling the API, you can pass the model name used for this call through this parameter.Priority: When the model_id passed through the API differs from the console configuration, the API parameter value takes precedence.
In the Java SDK, it is modelId. When calling through HTTP, put model_id into the parameters object.
The Java DashScope SDK must be at least 2.19.3.
enable_system_timeboolean (Optional) Default value: TrueControls whether the model automatically obtains the current time (Beijing time).
Only agent applications support this parameter.
Parameter values:
True (default): The current time is enabled, and the model can directly respond to real-time requests (such as "today's date").
False: The current time is disabled. You need to manually pass in the time through custom variables. For example:
You need to customize the time source instead of relying on the current time.
Avoid changes in model output caused by changes in the current time.
In the Java SDK, it is enableSystemTime. When calling through HTTP, put enable_system_time into the parameters object.
The Java DashScope SDK must be at least 2.19.3.
enable_web_searchboolean (Optional) Default value: falseWhether the model uses internet search results as reference when generating a reply.
Only agent applications support this parameter.
Parameter values:
True: Internet search is enabled, and the model uses the search results as reference information when generating a reply.
The model decides on its own whether and when to trigger an internet search.
False (default): Disables internet search.
Priority:
If this parameter is not set during the call, the status of the in-app web searchswitch takes precedence.
If enable_web_search is set during the call, the API parameter takes precedence.
Enabling the internet search feature may increase Token consumption.
In the Java SDK, it is enableWebSearch. When calling through HTTP, put enable_web_search into the parameters object.
The Java DashScope SDK must be at least 2.19.3.
dialog_roundinteger (Optional)The number of context rounds carried.
Only agent applications support this parameter.
Sets the maximum number of historical conversation rounds input to the model. The more rounds, the stronger the conversation relevance.Priority: When the dialog_round passed through the API differs from the console configuration, the API parameter value takes precedence.
In the Java SDK, it is dialogRound. When calling through HTTP, put dialog_round into the parameters object.
The Java DashScope SDK must be at least 2.19.3.
enable_thinkingboolean (Optional) Default value: falseThis parameter is used to switch between thinking mode and non-thinking mode in deep thinking models. It applies only to agent applications.
Workflow applications do not support dynamically controlling the thinking mode through this parameter; you need to set it in each LLM node separately.
Parameter values:
False (default): Non-thinking mode. The final answer is returned directly (in the text field).
True: Thinking mode is enabled. The model first outputs the thinking process and then returns the final answer.
Priority:
If this parameter is not set at the call, the thinking mode switch state of the model in the application takes precedence.
If enable_thinking is set at the call, the API parameter takes precedence.
To obtain the content of the thinking process, you must also set has_thoughts to True. Then:
Thinking process: for agent applications, obtain it through the thought field; for workflow applications, obtain it through the reasoningContent field.
Final answer: obtain it through the text field.
There is a very small chance that the thinking process is not output even after enable_thinking is enabled.
In the Java SDK, this parameter is enableThinking. When you call the API over HTTP, put enable_thinking in the parameters object.
The Java DashScope SDK version must be 2.20.0 or later.
Replace APP_ID with the actual application ID. In the next turn, replace the value of the session_id input parameter with the session_id value returned in the previous turn.
After you release a new version of an application, the APP_ID always points to the latest released version. Requests in progress at release time are not interrupted and complete normally based on the pre-release configuration; after the release is complete, new requests initiated through the same APP_ID use the new version's configuration (including the prompt, model, tools, and so on).The API does not support specifying a historical version to call through parameters. The request body contains only the input and parameters fields, and does not provide a version number or historical version parameter.If the session_id of a multi-turn conversation continues to be used after a new version is released, context understanding deviations or tool call exceptions may occur, because the historical context of that session was generated based on the pre-release configuration. We recommend ending active multi-turn conversations before releasing major changes, or starting a new session with a new session_id after the release.To restore the pre-release configuration, perform a version rollback on the application details page in the Alibaba Cloud Model Studio console:
Click Version management.
Select the historical version to restore.
Click Overwrite current draft.
Click Release to make the rollback take effect.
To reduce the impact on live calls, we recommend releasing major changes during off-peak business hours; if you need to provide multiple versions of capabilities externally at the same time, you can manage versions by creating multiple applications (using different APP_IDs).
To view retrieval process information: add has_thoughts to your code and set it to True when you make the call. The retrieval process information will then be returned in the thoughts field of the response.
When you call an agent application, specify memory_id to enable long-term memory. Related document: Long-term memory.
Enable the visual understanding feature by passing an image URL or Data URL (Base64-encoded) through the image_list parameter.Application configuration: The application must use an image and video understanding model. Related document: File Q&A.
Base64 encoding of local images is supported. After the image is encoded into a Base64 string, build a Data URL in the data:[MIME_type];base64,{base64_image} format and pass it in. MIME_type must match the image format. Common formats: PNG uses image/png, JPEG uses image/jpeg, and WebP uses image/webp.
status_codestringThe HTTP status code returned (only appears in the response for HTTP calls).200 indicates a successful request; otherwise, the request failed.
When a call fails, both the Python SDK and Java SDK throw an exception; you can obtain the status code, error code, and detailed error information from the exception attributes e.status_code/e.code/e.message.
request_idstringThe unique identifier of this call.
The Java SDK returns this parameter as requestId.
codestringThe error code; empty when the call succeeds (only returned in the HTTP response body).
When an SDK call fails, the error code is returned through the code attribute of the DashScopeError exception (ApiException in Java).
messagestringDetailed error information; ignored when the request succeeds (only returned in the HTTP response body).
When an SDK call fails, the error message is returned through the message attribute of the DashScopeError exception (ApiException in Java).
outputobjectThe call result information.
output Properties
textstringThe reply content generated by the model.finish_reasonstringThe reason for completion.stop indicates a natural end (a preset marker was encountered); null indicates forced termination (such as reaching the maximum length limit or a manual stop).session_idstringThe unique identifier of the current conversation.Pass it in subsequent requests to carry the conversation history.thoughtsarraySet the has_thoughts parameter to True when calling to view the plugin call and knowledge retrieval process, or the thinking process of deep-thinking models, in thoughts.
thoughts Properties
thoughtstringThe model's thinking process.After you select a deep-thinking model in the agent application in the console and successfully publish the application, if you set the has_thoughts parameter to True in the API call, the model's thinking process will be returned in this field.reasoningContentstringThe model's thinking process.After you select a deep-thinking model in the workflow application in the console and successfully publish the application, if you set the has_thoughts parameter to True in the API call, the model's thinking process will be returned in this field.action_typestringThe type of execution step returned by the LLM. For example, API indicates executing an API plugin, agentRag indicates performing knowledge retrieval, and reasoning indicates the thinking process of a deep-thinking model.action_namestringThe name of the executed action, such as knowledge retrieval, API plugin, or thinking process.actionstringThe executed step.action_input_streamstringThe streaming result of the input parameters.action_inputstringThe input parameters of the plugin.observationstringThe retrieval or plugin process.
doc_referencesarrayInformation about the documents cited by the model from the retrieved recall documents.Only after you turn on the Show answer sources switch and publish the application in the agent application in the Model Studio console can doc_references contain valid information.
doc_references Properties
index_idstringThe index of the recalled document cited by the model, such as [1].titlestringThe title of the text chunk cited by the model.doc_idstringThe document ID cited by the model.doc_namestringThe document name cited by the model.doc_urlstringThe document link cited by the model; null if the document is stored in the secure storage space of the Alibaba Cloud Model Studio platform.textstringThe specific text content cited by the model.biz_idstringThe business association identifier cited by the model.imagesarrayThe list of image URLs cited by the model.page_numberarrayThe page number of the text chunk cited by the model.
This parameter is only supported for knowledge bases created after October 25, 2024.
To use this parameter, the Python Dashscope SDK must be version 2.0.1 or later, and the Java Dashscope SDK must be version 2.16.10 or later.
workflow_messageobjectThe object containing workflow node statuses and messages.
Output field specific to workflow applications:
This field is only returned when calling a workflow application; agent applications do not return it.
In streaming output mode, when flow_stream_mode is set to message_format or message_format_plus, this field returns the execution status and messages of each workflow node in real time.
In non-streaming output mode, this field returns the status and messages of the final node (the End node or Process output node).
Differences from agent application output:
Agent applications: the final reply is mainly returned via the output.text field, and the thoughts field (requires has_thoughts=true) returns the plugin call and knowledge retrieval process.
Workflow applications: in addition to output.text, the workflow_message field returns detailed execution information of workflow nodes, including node name, type, status, and the output content of each node.
workflow_message Properties
node_statusstringThe execution status of the current node, for example, executing.node_typestringThe type of the current node, for example, End (end node).node_msg_seq_idintegerThe sequence number of messages within a node.node_namestringThe name of the current node, for example, End.messageobjectThe object containing the specific message content.
message Properties
contentstringThe specific text content of the message.rolestringThe role of the message sender, for example, Assistant.
node_is_completedbooleanIndicates whether the current node has finished execution. true means completed; false means not completed.node_idstringThe unique identifier ID of the current node.parent_node_idstringThe ID of the parent node (loop node / batch node) that the current node belongs to.
Main canvas nodes: return null.
Sub-canvas nodes: return the node_id of the loop node or batch node they belong to.
Only in message_format_plus mode do sub-canvas nodes return non-null values.
Sub-canvas node content structure (message_format_plus)When flow_stream_mode=message_format_plus and the node is in a sub-canvas (parent_node_id is non-null), message.content is the complete NodeResult JSON of that iteration/branch.
Sub-canvas node content fields
nodeIdstringThe node ID within the sub-canvas.nodeNamestringThe node name.nodeTypestringThe node type, such as LLM, Plugin, or Output.nodeStatusstringThe node execution status: success / fail / skip (skipped, not executed) / executing.inputstringThe node input content.outputstringThe node output content.indexintegerThe sub-canvas iteration/branch index, incrementing from 0.parentNodeIdstringThe parent node (loop node / batch node) ID.nodeExecTimestringThe node execution time, such as 100ms.errorCodestringReturned when node execution fails.errorInfostringReturned when node execution fails.
The processing rules for text nodes (Output / End text mode) and JSON nodes such as LLM are the same as on the main canvas: text nodes are deltas that must be concatenated, and JSON nodes are snapshots that must be replaced as a whole; node_is_completed=true marks the end of a node.
usageobjectThe data usage information of this request.
usage Properties
modelsarrayThe model information of this call.
models Properties
model_idstringThe model ID invoked by this application call.input_tokensintegerThe length of the user input text after being converted into tokens.output_tokensintegerThe length of the model-generated reply after being converted into tokens.
Single-turn conversation response exampleThe following is the raw response returned by the HTTP interface (the Python SDK returns a flattened response object, which can be read directly via response.text/response.finish_reason/response.session_id).
Response example with a specified knowledge baseWhen calling the application knowledge base feature, to output the document information cited by the model from the recalled documents, click Retrieval settings in the agent application in the Model Studio console, turn on the Show answer sources switch, and publish the application.The following is the response object shape of the Python SDK 2.0.
Exception response exampleWhen a request fails, the Python SDK throws an exception whose code and message attributes indicate the cause of the error.The following shows an example of an exception response when a valid API-KEY is not provided.
Application calls are rate-limited on two independent dimensions, the application and the account. If either limit is reached, a rate limit error is returned:
Per-application concurrency: the number of requests per second counted by application ID (app_id), with a default upper limit of 100 QPS. Submission requests for asynchronous workflow tasks share this quota with synchronous calls.
Total account traffic: the number of requests per minute counted at the level of the same Alibaba Cloud primary account, with a default upper limit of 15000 QPM.
Requests that exceed the threshold are rejected with HTTP 429 and the error code Throttling.RateQuota, and usually recover automatically within one minute. If you expect a significant increase in business concurrency or call volume, contact your Alibaba Cloud business manager in advance to evaluate and request a quota increase.
If the call fails (the Python SDK throws a DashScopeError exception, and HTTP calls return an error message), refer to Error codes for troubleshooting.