Use the OpenAI-compatible Responses API to call the Qwen model. This topic describes the input and output parameters and provides a call example.
Advantages over the OpenAI Chat Completions API:
-
Built-in tools: Get better results on complex tasks with built-in tools like web search, web scraping, a code interpreter, text-to-image, image-to-image, and knowledge base search. For more information, see tool calling.
-
More flexible input: Supports both direct string input and message arrays in the chat format.
-
Simplified context management: Avoid manually constructing a message history array by passing the
previous_response_idfrom the last response. -
Convenient context caching: Add
x-dashscope-session-cache: enable(default value: disable) to the request header to enable automatic server-side caching of the conversation context. This reduces inference latency and costs for multi-turn conversations with no code changes required. For details, see session cache.
Compatibility and limitations
This API is compatible with OpenAI to reduce developer migration cost, but differs in its parameters, functionality, and behavior.
Core Principle: Only the parameters explicitly listed in this document are processed. Any OpenAI parameters not mentioned are ignored.
The following key differences will help you adapt quickly:
-
Unsupported Parameters: This API does not support some OpenAI API parameters, such as the asynchronous execution parameter
background. The API currently supports only synchronous calls. -
Reasoning Effort Control: Use the
reasoning.effortparameter to control the model's reasoning effort. For usage details, see the description of this parameter.
Singapore
The base_url for the SDK call configuration is https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1.
HTTP request endpoint: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responses
China (Beijing)
The base_url for the SDK call configuration: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
HTTP request endpoint: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses
US (Virginia)
SDK call configuration base_url: https://dashscope-us.aliyuncs.com/compatible-mode/v1
HTTP request endpoint: POST https://dashscope-us.aliyuncs.com/compatible-mode/v1/responses
Germany (Frankfurt)
SDK call configuration base_url: https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1/responses
HTTP request endpoint: POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1/responses
China (Hong Kong)
SDK call configuration base_url: https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1
HTTP request endpoint: POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/responses
Japan (Tokyo)
SDK call configuration base_url: https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1
HTTP request endpoint: POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1/responses
Replace {WorkspaceId} with your actual workspace ID.
Alibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing), Singapore, and China (Hong Kong) regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
China (Beijing): from
https://dashscope.aliyuncs.comtohttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.comSingapore: from
https://dashscope-intl.aliyuncs.comtohttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.comChina (Hong Kong): from
https://cn-hongkong.dashscope.aliyuncs.comtohttps://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domain remains fully functional.
The legacy URL path /api/v2/apps/protocols/compatible-mode/v1/responses for the OpenAI-compatible Responses API will be deprecated soon. Please migrate to the new path /compatible-mode/v1/responses as soon as possible.
Request body |
Basic callPython
Node.js
curl
Stream outputPython
Node.js
curl
Multi-turn conversationPython
Node.js
Built-in toolsPython
Node.js
curl
Function callingPython
Node.js
Document understandingPython
Node.js
curl
Session cachePython
Node.js
curl
|
|
model The ID of the model to use. |
|
|
input The input for the model. The following formats are supported:
|
|
|
instructions It is inserted at the beginning of the context as a system instruction. When |
|
|
previous_response_id The unique ID of the previous response. A response's |
|
|
conversation The conversation that the current response belongs to (see the Conversations API). The conversation's history is automatically included as context. The input and output of this request are added to the conversation upon completion. Cannot be used with |
|
|
stream Enables stream output. If set to |
|
|
store Specifies whether to store the model response generated for this session.
|
|
|
tools An array of tools the model can call when generating a response. Supports both built-in tools and custom For best results, enable the |
|
|
tool_choice Controls how the model selects and calls tools. This parameter supports two formats: string mode and object mode. String mode
Object mode Restricts the model to a specific set of tools for selection and calling. |
|
|
temperature The sampling temperature, which controls the diversity of the generated text. Higher values make the output more random and diverse, while lower values make it more focused and deterministic. Value range: [0, 2) Both |
|
|
top_p The probability threshold for top-p sampling, which controls the diversity of the generated text. Higher values make the output more random and diverse, while lower values make it more focused and deterministic. Value range: (0, 1.0] Both |
|
|
enable_thinking Enables or disables reasoning mode. When enabled, the model performs a reasoning step before it responds. The reasoning process is returned as an output item of type Valid values:
For default values for different models, see Supported models. This parameter is not a standard OpenAI parameter. In the Python SDK, pass it using |
|
|
reasoning Controls the model's reasoning effort. The model performs a reasoning step before replying, and the reasoning process is returned through an output item of type
|
|
|
ocr_options OCR built-in task parameters. Only applicable to the This parameter is not a standard OpenAI parameter. In the Python SDK, pass it using |
Response object (non-streaming output) |
|
|
id A unique identifier for this response, a UUID. This ID is valid for 7 days and can be used in the |
|
|
created_at The Unix timestamp (in seconds) for this request. |
|
|
object The object type, which is always |
|
|
status The status of the response generation. Valid values:
|
|
|
model The ID of the model used to generate the response. |
|
|
output An array of output items generated by the model. The type and order of elements in the array depend on the model's response. |
|
|
usage Information about the token consumption for this request. |
|
|
error An error object is returned when the model fails to generate a response. Otherwise, the value is |
|
|
tools Echos the full content of the |
|
|
tool_choice Echoes the value of the |
Response chunk object (streaming output) |
Basic call
Web extraction
Text-to-image search
Image-to-image search
MCP
Knowledge base search
|
|
Streaming output returns a series of JSON objects. Each object includes a |
|
|
type The event type identifier. Possible values include:
|
|
|
sequence_number The event sequence number, starting at 0 and incrementing with each event. Use this number to process events in the correct order. |
|
|
response The response object. Appears in the |
|
|
item An output item object. It appears in the |
|
|
part The content part object. Appears in the |
|
|
delta The incremental text segment. This field appears in the |
|
|
text The complete text content. This field appears in the |
|
|
item_id The unique identifier for the output item. Use this ID to correlate events that belong to the same item. |
|
|
output_index The index of the output item in the |
|
|
content_index The index of the content part in the |
|
|
summary_index The index of the item in the |
FAQ
Q: How do I pass context for a multi-turn conversation?
A: When making a new conversation request, pass the id from the model's previous successful response as the previous_response_id parameter.
Q: Why are some fields in the response example not described in this topic?
A: The official OpenAI SDK may output extra fields defined by the OpenAI protocol. Our service does not support these fields, so they are typically null. Focus only on the fields described in this topic.