This topic describes how to make an asynchronous call to Alibaba Cloud Model Studio applications ( Agent and Workflow ) using the OpenAI-compatible Responses API. For long-running tasks, set the background parameter to true in your request. The API then immediately returns a task ID for querying and managing the task. This "submit first, query later" pattern helps avoid request timeouts and long waits.
- Synchronous invocation: For immediate responses to real-time interactions, see the Synchronous Invocation API Reference.
- DashScope API: For additional capabilities, see DashScope API.
stream=true).Prerequisites
- You have obtained an API Key and set it as an environment variable. To make calls through the OpenAI SDK, you must also install the SDK.
- You have created an Alibaba Cloud Model Studio application and obtained its application ID. You can copy the ID from the application card on the Application Management page.
Quick start
This section provides complete Python and Java examples to demonstrate how to start an asynchronous task, poll for its status until it is complete, and retrieve the final result.
This example covers the core workflow for asynchronous invocation:
- Create a task: Call the
createmethod and setbackground=Trueto get the task ID. - Poll for status: Periodically call the
retrievemethod to query the task status. - Process the result: When the task status is
completed,failed, orcancelled, exit the loop and process the final result.
Code example
Code example
Workflow
The following sections describe the API operations for creating, querying, canceling, and deleting asynchronous tasks.
Create a task
Set the background parameter to true to enable asynchronous mode. This creates an asynchronous task and immediately returns a task ID.
Endpoint:POST https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/responses
Replace {APP_ID} with your application ID.
Request example
- Single-turn conversation
- Parameter passing
Request fields
Parameter | Type | Required | Description |
|---|---|---|---|
| string/array | Yes | The core input for the request, which can be a single string or an array of messages representing a multi-turn conversation history. |
| boolean | Yes | Specifies whether to execute the task asynchronously.
|
extra_body | object | No | A field for additional parameters. |
extra_body.biz_params | object | No | Used to pass parameters defined in the application, such as custom variables, node inputs, or plugin arguments. |
user_defined_params | object | No | Custom plugin parameter information. An application supports up to 10 unique plugins. |
user_defined_tokens | object | No | User-level authentication information for a custom plugin. An application supports up to 10 unique plugins. |
user_defined_tokens.user_token | string | No | The user authentication information required by the plugin. |
Response example
Response fields
Parameter | Type | Description |
|---|---|---|
| string | A unique identifier for the asynchronous task. Use it to retrieve, cancel, or delete the task. |
| string | The initial status of the task, which is typically |
| integer | The task's creation time, represented as a Unix timestamp in seconds. |
| string | The object type. This value is always |
Retrieve task
Retrieves the status and result of a specified asynchronous task.
Endpoint:GET https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/responses/{RESPONSE_ID}
Replace{APP_ID}with your App ID and{RESPONSE_ID}with the Response ID from the task creation response.
Request example
Response example
Response fields
Parameter | Type | Description |
|---|---|---|
| string | The unique identifier for the asynchronous task. |
| string | The current status of the asynchronous task. For details, see Task Lifecycle. |
| array | The output of the task. When |
Cancel a task
Cancels an asynchronous task in the queued or running state.
Endpoint:POST https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/responses/{RESPONSE_ID}/cancel
Replace{APP_ID}with your application ID and{RESPONSE_ID}with the task ID returned on task creation.
Request example
Response example
Response fields
Field | Type | Description |
|---|---|---|
| string | Unique identifier of the task. |
| string | The status of the task after cancellation. For example:
|
| string | The object type, always |
Delete a response
Deletes a response that is in a final state (completed, failed, or cancelled). This operation is irreversible.
Endpoint:DELETE https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/responses/{RESPONSE_ID}
Replace{APP_ID}with your application ID and{RESPONSE_ID}with the response ID returned when the asynchronous task was created.
Request example
Response example
Response fields
Field | Type | Description |
|---|---|---|
| string | The unique identifier of the deleted response. |
| boolean | Set to |
| string | The object type. This value is always |
Task lifecycle
An asynchronous task has the following states:
State | Description |
|---|---|
| The task is created and awaits scheduling in the queue. |
| The task is running. |
| The task completed successfully. The |
| The user cancelled the task before it completed. |
| The task failed to execute. The |


