Skip to main content
Application Calling

Application DashScope API reference

Input and output parameters for calling Model Studio applications ( Agent , Workflow ) via the DashScope API, with examples for typical scenarios.

This topic is applicable only to the Singapore region.
Related guides Application invocation.

Prerequisites

Complete the following tasks:
  1. Create an application: Go to Application Management to create a Model Studio application and get its application ID.
  2. Get an API key: Get your API key from Key Management and configure the API key as an environment variable.
  3. Install the SDK (optional): If you use an SDK to make calls, install the DashScope SDK for your programming language.

Invocation methods

  • HTTP API call Request URL: POST https://dashscope-intl.aliyuncs.com/api/v1/apps/APP_ID/completion
    Replace APP_ID with your actual application ID.
  • SDK call Python/Java SDK: The correct endpoint is configured by default. Custom endpoint: Configure it using the base_url parameter.

Request body

app_idstring(required)Application ID.Get the application ID from the application card on the Application Management page.
In the Java SDK, this is appId. When calling via HTTP, put your actual application ID in the URL, replacing APP_ID.
promptstring(required)User input that guides the application to generate a response.
When calling via HTTP, put prompt in the input object.
session_idstring (optional)Conversation history identifier.Pass session_id to automatically carry cloud-stored conversation history. Requires prompt.Expires after 1 hour of inactivity.
In the Java SDK, this is setSessionId. When calling via HTTP, put session_id in the input object.
messagesarray(optional)Conversation context passed to the model, arranged in chronological order.For multi-turn conversations, pass messages instead of prompt or session_id.If you pass both session_id and messages, the model uses the content in messages and ignores session_id and prompt.
When calling via HTTP, put messages in the input object.
To use this parameter, your Python Dashscope SDK version must be at least 1.20.14, and your Java Dashscope SDK version must be at least 2.17.0.

Message types

System Messageobject (optional)System message that sets the model's role, tone, task objectives, or constraints. Usually placed first in the messages array.
contentstring(required)System instruction that defines the model's role, behavior guidelines, response style, and task constraints.rolestring(required)Role of the system message, fixed as system.
User Messageobject(required)User message that passes questions, instructions, or context to the model.
contentstring(required)Message content.
textstring(required)Input text.
rolestring(required)Role of the user message, fixed as user.
Assistant Messageobject (optional)Model response. Typically used as context passed back to the model in multi-turn conversations.
contentstring(required)Text content of the model response.rolestring(required)Role of the assistant message, fixed as assistant.
workspace string (optional)Business space identifier. Related documentation: Get Workspace ID.You only need to pass the workspace ID when invoking applications in a sub-workspace.
When calling via HTTP, specify the X-DashScope-WorkSpace header.
stream boolean (optional) Default value is FalseEnable streaming output.Set to True to improve reading experience and reduce timeout risk.Parameter values:
  • False (default): The model returns all content at once after generation completes.
  • True (recommended): The model streams content incrementally. Read chunks in real time to assemble the complete response.
To implement streaming output with the Java SDK, use the streamCall interface. To implement streaming output via HTTP, set the X-DashScope-SSE header to enable.
incremental_output boolean (optional) Default value is FalseEnable incremental output in streaming mode.Set to True to improve reading experience.Parameter values:
  • False (default): Each output contains the full sequence generated so far.
I
I like
I like apple
I like apple.
  • True (recommended): Incremental output. Each chunk contains only new content. Read segments in real time to assemble the complete result.
I
like
apple
.
In the Java SDK, this is incrementalOutput. When calling via HTTP, put incremental_output in the parameters object.
flow_stream_mode string (optional) Default value is full_thoughtsStreaming output mode for Workflow Application.Parameter values:
  • message_format (recommended): Outputs results from specified nodes (either a Output node or an End node) in the message field.
    In the console application, enable the Stream switch for the target node to return results in streaming mode. If disabled, the node's final result is returned all at once.
    In the Java SDK, this is FlowStreamMode.MESSAGE_FORMAT.
  • full_thoughts (default): Outputs results from all nodes in the thoughts field.
    When using this mode, you must also set the has_thoughts parameter to True.
    In the Java SDK, this is FlowStreamMode.FULL_THOUGHTS.
  • agent_format: Outputs results from specified nodes (LLM nodes or end nodes) in the textfield. In the console application, enable the Response switch for the target node to return results in streaming mode.
    Do not use this mode with parallel nodes, as it may cause content mixing. Ensure the enabled nodes have a clear execution order.
    In the Java SDK, this is FlowStreamMode.AGENT_FORMAT.
Your Python SDK version must be at least 1.24.0, and your Java SDK version must be at least 2.21.0. When calling via HTTP, put flow_stream_mode in the parameters object.
biz_paramsobject (optional)Pass parameters for custom variables, nodes, or plugins.
In the Java SDK, this is bizParams. When calling via HTTP, put biz_params in the input object.
For Workflow Application, pass custom variables for the start node directly, for example:
biz_params = {"city": "Hangzhou"}
For Agent Application, pass prompt variables or plugin variables using the following fields:

Properties

user_defined_params object (optional)Custom plugin parameters.Plugins cannot be duplicated. Maximum: 10.

Properties

tool_idstring (optional)Plugin ID, available on the plugin card.${plugin_params}string (optional)The innermost object contains multiple key-value pairs. Each key-value pair represents a user-defined parameter name and its specified value. For example:
"article_index": 2
Usage steps:
  1. Associate the specified plugin with your application and Publish the application.
  2. Pass plugin information through this parameter during API calls.
You can provide multiple key-value pairs, where each key is the plugin's TOOL_ID and the value is the parameter object required by that plugin. Example:
"user_defined_params": {
        "<TOOL_ID>": {
            "article_index": 2},
        "<TOOL_ID>": {
            "article_index": 8}
        }
user_defined_tokens object (optional)User-level authentication for custom plugins.Plugins cannot be duplicated. Maximum: 10.

Properties

tool_idstring (optional)Plugin ID, available on the plugin card. Pass through the <TOOL_ID> field.user_token string (optional)Pass the user authentication information required by this plugin, such as the actual value of DASHSCOPE_API_KEY.
Usage steps:
  1. Associate the specified plugin with your application and Publish the application.
  2. Pass plugin user-level authentication information through this parameter during API calls.
You can provide multiple key-value pairs, where each key is the plugin's TOOL_ID and the value is the user_token object.
has_thoughts boolean (optional) Default value is FalseControls whether plugin invocation, knowledge retrieval appear in the thoughts field.Parameter values:
  • True: Output included.
  • False (default): Output not included.
In the Java SDK, this is hasThoughts. When calling via HTTP, put has_thoughts in the parameters object.
rag_options object (optional)Configure retrieval parameters, including retrieving specified knowledge bases or documents.
Only Agent Application support this parameter.
In the Java SDK, this is ragOptions. When calling via HTTP, put rag_optionsin the parameters object.

Properties

pipeline_ids array(required)A list containing one or more knowledge base IDs. Maximum of 5.Retrieves all documents within the specified knowledge bases.How to get:
  • Knowledge Base page to get the knowledge base ID;
  • Or through the CreateIndex API (supports only unstructured knowledge bases), which returns Data.Id.
In the Java SDK, this is pipelineIds.
file_idsarray(optional)A list containing one or more unstructured document IDs. Maximum of 5.Retrieves unstructured documents within the specified knowledge bases.When passing document IDs, you must also pass the knowledge base ID that these documents belong to in the pipeline_ids field.How to get:
In the Java SDK, this is fileIds.
metadata_filterobject (optional)Filter unstructured documents by specifying one or more metadata key-value pairs within the specified knowledge base.Prerequisites:When passing metadata, you must also pass the knowledge base ID that this metadata belongs to in the pipeline_ids field.How to view:
  • Visit the Knowledge Base page, click the View DetailsMetadata Information on the knowledge base card to view.
  • Or through the ListChunks API to get.
This object consists of one or more key-value pairs:
  • Key: String type, representing the metadata name.
  • Value:
    • Exact match: Value is a String, meaning only documents with this field value exactly equal to this string are retrieved.
      • Example: "author": "John.Doe"
    • Multi-value "OR" match: Value is an Array (array) or List (list) containing multiple Strings. This means documents with this field value matching any value in the array are retrieved (logical OR).
      • Example: "source": ["internal_wiki", "public_docs"]
Combination logic: Different keys use "AND" logic. For example, "author": "John.Doe", "source": ["internal_wiki", "public_docs"] means filtering documents authored by "John.Doe" AND sourced from either "internal_wiki" OR "public_docs".
In the Java SDK, this is metadataFilter.
tags array (optional)A list containing one or more tags for unstructured documents.You can retrieve unstructured documents with this tag.How to view:
  • Single-turn conversation
  • Multi-turn conversation
  • Pass parameters
  • Streaming output
  • Knowledge base retrieval
  • Python
  • Java
  • HTTP
Request example
import os
from http import HTTPStatus
from dashscope import Application
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
response = Application.call(
    # Configure API key: use environment variable or replace with your Model Studio API key (do not hard code in production).
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    app_id='APP_ID',# Replace with your actual application ID
    prompt='Who are you?')

if response.status_code != HTTPStatus.OK:
    print(f'request_id={response.request_id}')
    print(f'code={response.status_code}')
    print(f'message={response.message}')
    print(f'See documentation: https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code')
else:
    print(response.output.text)

Response object

status_code stringHTTP status code.200 indicates success; other codes indicate failure.On failure, check code for the error code and message for details.
The Java SDK does not return this parameter. On failure, it throws an exception containing the status_code and message content.
request_id stringUnique ID for this invocation.
The Java SDK returns this as requestId.
code stringError code. Empty on success.
Only returned by the Python SDK.
message stringError details. Empty on success.
Only returned by the Python SDK.
output objectInvocation result.

output properties

text stringModel response content.finish_reason stringReason the response ended.stop means natural completion (encountering a preset marker), null means forced interruption (e.g., reaching maximum length limit or manual stop).session_idstringUnique ID for the current conversation.Pass this in subsequent requests to carry historical conversation records.thoughtsarrayWhen you set the has_thoughts parameter to True during invocation, you can view plugin invocation, knowledge retrieval processes, or the deep thinking model's thinking process in thoughts.
thought stringModel thinking process.When you select a deep thinking model in your console's Agent Application and successfully publish it, if you set the has_thoughts parameter to True during API invocation, the model's thinking process will be returned in this field.reasoningContentstringModel thinking process.When you select a deep thinking model in your console's Workflow Application and successfully publish it, if you set the has_thoughts parameter to True during API invocation, the model's thinking process will be returned in this field.action_type stringType of execution step returned by the model. For example, API means executing an API plugin, agentRag means executing knowledge retrieval, and reasoning means executing the deep thinking model's thinking process.action_name stringName of the executed action, such as knowledge retrieval, API plugin, or thinking process.action stringExecution steps.action_input_stream stringStreaming result of input parameters.action_input stringPlugin input parameters.observation stringProcess of retrieval or plugin execution.
doc_references arrayReferenced documents that the model cited.In your Model Studio console's Agent Application, enable the Show Source switch and Publish the application for doc_references to possibly contain valid information.
index_id stringIndex of the referenced document, e.g., [1].title stringTitle of the referenced text segment.doc_id stringID of the referenced document.doc_name stringName of the referenced document.text stringSpecific text content referenced by the model.biz_id stringBusiness association identifier referenced by the model.images arrayList of image URLs referenced by the model.
usage objectToken usage for this request.

usage properties

modelsarrayModel information for this invocation.
model_id stringModel ID used by this application.input_tokens integerInput token count.output_tokens integerOutput token count.
Single-turn conversation response example
{
    "output": {
        "finish_reason": "stop",
        "session_id": "6105c965c31b40958a43dc93c28c7a59",
        "text": "I am Qwen, an AI assistant developed by Alibaba Cloud. I'm designed to answer various questions, provide information, and converse with users. How can I help you?"
    },
    "usage": {
        "models": [
            {
                "output_tokens": 36,
                "model_id": "qwen-plus",
                "input_tokens": 74
            }
        ]
    },
    "request_id": "f97ee37d-0f9c-9b93-b6bf-bd263a232bf9"
}
Specified knowledge base response exampleTo output referenced document information from retrieved documents, open your application's Agent Application, click Retrieve Configuration, enable Show Source, and Publish the application.
{
    "text": "Based on your budget, I recommend considering the Bailian Zephyr Z9. This phone is lightweight and portable, featuring a 6.4-inch screen with 1080 x 2340 pixel resolution, paired with 128GB storage and 6GB RAM, making it perfect for daily use<ref>[1]</ref>. Additionally, it comes with a 4000mAh battery and a 30x digital zoom lens to capture distant details, priced between 2499-2799 yuan, fully meeting your budget requirements<ref>[1]</ref>.",
    "finish_reason": "stop",
    "session_id": "6c1d47fa5eca46b2ad0668c04ccfbf13",
    "thoughts": null,
    "doc_references": [
        {
            "index_id": "1",
            "title": "Bailian Phone Product Introduction",
            "doc_id": "file_7c0e9abee4f142f386e488c9baa9cf38_10317360",
            "doc_name": "Bailian Series Phone Product Introduction",
            "doc_url": null,
            "text": "【Document Name】:Bailian Series Phone Product Introduction\n【Title】:Bailian Phone Product Introduction\n【Content】:Reference Price: 5999- 6499. Bailian Ace Ultra ——For Gamers: Equipped with a 6.67-inch 1080 x 2400 pixel screen, built-in 10GB RAM and 256GB storage, ensuring smooth gaming. Bailian Ace Ultra ——For Gamers: Equipped with a 6.67-inch 1080 x 2400 pixel screen, built-in 10GB RAM and 256GB storage, ensuring smooth gaming. 5500mAh battery with liquid cooling system keeps your device cool during extended gaming sessions. High-dynamic dual speakers enhance immersive audio for gaming. Reference Price: 3999- 4299. Bailian Zephyr Z9 ——Art of Slim Design: Lightweight 6.4-inch 1080 x 2340 pixel design, paired with 128GB storage and 6GB RAM, handles daily tasks effortlessly. 4000mAh battery ensures all-day usage, while the 30x digital zoom lens captures distant details without compromising on power. Reference Price: 2499- 2799. Bailian Flex Fold+ ——New Era of Foldable Phones: Combines innovation and luxury with a 7.6-inch 1800 x 2400 pixel main screen and 4.7-inch 1080 x 2400 pixel outer screen, supporting multi-angle free-stop design for different scenarios. 512GB storage, 12GB RAM, plus a 4700mAh battery and UTG ultra-thin flexible glass, ushering in a new chapter for foldable phones. Additionally, this phone supports Dual SIM Dual Standby and satellite calls, keeping you connected worldwide. Reference Retail Price: 9999- 10999.\n",
            "biz_id": null,
            "images": [

            ],
            "page_number": [
                0]
        }]
}
Error response exampleWhen a request fails, the response includes error details through code and message.This example shows an error response for an invalid API-KEY.
request_id=1d14958f-0498-91a3-9e15-be477971967b,
code=401,
message=Invalid API-key provided.

Rate limits

Default QPM (queries per minute) for a single application is 15,000.

Error codes

If the invocation fails and returns an error, see Error information for solutions.