Asynchronously invoke Alibaba Cloud Bailian applications via the OpenAI-compatible Responses API
This document describes how to asynchronously invoke Alibaba Cloud Bailian applications (agent applications and workflow applications) using the OpenAI-compatible Responses API. For long-running tasks, simply set
Related References
Set
Use the task ID to check the execution status and result of an asynchronous task:
You may cancel an asynchronous task that has not yet completed:
If the API call fails and returns an error message, consult the Responses API reference for troubleshooting.
background to true in your request. The API will immediately return a task ID, which you can use later to query or manage the task. This “submit first, then retrieve” approach effectively avoids request timeouts or prolonged waiting.
Streaming output (
stream=true) is not supported for asynchronous tasks.- Synchronous invocation: For real-time interactive scenarios where immediate results are required, see the Synchronous Invocation API Reference.
- DashScope API: For additional features, refer to the DashScope API.
Prerequisites
- You have obtained an API key and configured it in your environment variables. If invoking via the OpenAI SDK, ensure the OpenAI SDK is installed.
- You have created an Alibaba Cloud Bailian application and obtained its application ID.
Endpoint
- SDK base_url:
https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/ - HTTP Endpoint:
POST https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/responses
Replace
{APP_ID} with your actual application ID.Creating an Asynchronous Task
Set background to true in your request to create an asynchronous task:
Querying Task Status
Use the task ID to check the execution status and result of an asynchronous task:
Canceling a Task
You may cancel an asynchronous task that has not yet completed:
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| input | string/array | Yes | User input content. |
| background | boolean | Yes | Set to true to create an asynchronous task. |
| model | string | No | Model name. |
| previous_response_id | string | No | ID of the previous response, used for multi-turn conversations. |
Response Object
| Parameter | Type | Description |
|---|---|---|
| id | string | Unique identifier for the task. |
| status | string | Task status: queued, in_progress, completed, failed, or cancelled. |
| output | array | List of output messages after task completion. |
| usage | object | Token usage information (returned only upon completion). |