Alibaba Cloud Model Studio supports the OpenAI-compatible Responses API. Building on the Chat Completions API, the Responses API streamlines native agent functionality.
Advantages over the OpenAI Chat Completions API:
First, get an API key and set it as an environment variable. If you use the OpenAI SDK, install the SDK.
Send a message and get a response.
Example response
The
Second-round response example
Note: In the second round, the
Use the
Example response
Receive content from the model in real time, especially useful for long-form text generation.
Example response
Enable built-in tools for complex tasks. The web extractor and code interpreter are free for a limited time. See tool calling for supported tools.
Example response
In multi-turn conversations, enable the session cache to let the server cache conversation context automatically. This reduces latency and costs without manual cache management.
Usage: To enable the session cache, add
The Responses API simplifies the Chat Completions API interface while maintaining compatibility. To migrate, follow these steps.
Update the endpoint address from
The Responses API returns a different response structure. Use the
With the Chat Completions API, you must manually manage the message history array. The Responses API simplifies this process by using the
The Responses API includes built-in tools. Specify them in the
A: Pass the
A: This attribute is missing in some versions of the OpenAI Python SDK, such as 1.99.2. To resolve this error, update the SDK to the latest version.
- Built-in tools: Improve results for complex tasks with web search, web scraping, a code interpreter, text-to-image, and image-to-image. For details, see Call built-in tools.
- More flexible input: The API supports both direct string inputs and message arrays in the standard chat format.
- Simplified context management: Passing the
previous_response_ideliminates the need to manually build a complete message history array.
Prerequisites
First, get an API key and set it as an environment variable. If you use the OpenAI SDK, install the SDK.
Supported models
- Singapore
- US (Virginia)
- Germany (Frankfurt)
- China (Beijing)
- Hong Kong (China)
- Japan (Tokyo)
International deployment scope
qwen3.8-max, qwen3.8-flash, qwen3.7-max, qwen3.7-max-2026-05-20, qwen3.7-max-2026-06-08, qwen3-max, qwen3-max-2026-01-23, qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.5-plus, qwen3.5-plus-2026-04-20, qwen3.5-plus-2026-02-15, qwen3.7-flash, qwen3.7-flash-2026-07-15, qwen3.6-flash, qwen3.6-flash-2026-04-16, qwen3.5-flash, qwen3.5-flash-2026-02-23, qwen3.8-2.4t-a95b, qwen3.8-27b, qwen3.6-35b-a3b, qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b, qwen-plus, qwen-flash, qwen3-coder-plus, qwen3-coder-flash, qwen-plus-character, qwen-flash-character, deepseek-v4-pro, deepseek-v4-flash, deepseek-v4-flash-0731、glm-5.2Endpoints
- Singapore
- China (Beijing)
- US (Virginia)
- China (Hong Kong)
- Germany (Frankfurt)
- Japan (Tokyo)
SDK call configuration
base_url: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1HTTP request URL: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responsesReplace WorkspaceId with your actual Workspace ID.Code examples
Basic call
Send a message and get a response.
Python
This is a complete API response.
Multi-turn conversation
The previous_response_id parameter automatically maintains the conversation context, so you do not need to manually build the message history. Each response id is valid for 7 days.
Theprevious_response_idmust be the top-levelidfrom the previous response (e.g.,resp_xxx, in UUID format), not the messageidfrom within theoutputarray (e.g.,msg_56c860c4-3ad8-4a96-8553-d2f94c259xxx).
Python
input_tokens count is 78. This number includes context from the first round, showing that the model successfully remembered the name "John".
Deep thinking
Use the reasoning parameter to control the model's reasoning strength. When you set reasoning.effort, the model thinks before replying, and returns the thinking process in a reasoning output item. The effort parameter supports the following values:
none: Disables thinking and provides a direct answer.minimal: Minimizes thinking for the fastest response.low: Performs light thinking, prioritizing a quick response.medium(default): Performs moderate thinking, balancing speed and depth.high: Performs deep thinking, focusing on complex and specialized problems.
You cannot use thethinking_budgetparameter to control the maximum thinking length.reasoning.efforttakes precedence overenable_thinking. Usereasoning.effort, asenable_thinkingwill be deprecated.
Python
Stream output
Receive content from the model in real time, especially useful for long-form text generation.
Python
Use built-in tools
Enable built-in tools for complex tasks. The web extractor and code interpreter are free for a limited time. See tool calling for supported tools.
Python
Session cache
In multi-turn conversations, enable the session cache to let the server cache conversation context automatically. This reduces latency and costs without manual cache management.
Usage: To enable the session cache, add x-dashscope-session-cache: enable to the request header. To disable it, set the value to disable. The default value is disable.
Caching behavior:
-
Session cache enabled:
- Model supports explicit cache: Uses explicit cache. For billing and constraints, see Explicit cache.
- Model does not support explicit cache but supports implicit cache: Uses implicit cache. For billing and constraints, see Implicit cache.
- Session cache not enabled: Same as normal API calls. Implicit cache is still automatically enabled for models that support it, but without the session cache benefits.
Python
Migrate from Chat Completions API to Responses API
The Responses API simplifies the Chat Completions API interface while maintaining compatibility. To migrate, follow these steps.
1. Update the endpoint address
Update the endpoint address from /v1/chat/completions to /v1/responses.
Python
2. Update response handling
The Responses API returns a different response structure. Use the output_text shortcut to retrieve the text output, or access detailed information through the output array.
Response comparison
3. Simplify multi-turn conversations
With the Chat Completions API, you must manually manage the message history array. The Responses API simplifies this process by using the previous_response_id parameter to automatically link conversation context. The response id is valid for 7 days.
- Python
- Node.js
4. Use built-in tools
The Responses API includes built-in tools. Specify them in the tools parameter. The Code Interpreter and web search tools are free for a limited time. See tool calling.
- Python
- Node.js
- Curl
FAQ
Q: How to pass multi-turn conversation context?
A: Pass the id from the previous successful model response as the previous_response_id parameter in your next conversation request.