This topic describes how to use the OpenAI-compatible Responses API to make a synchronous call to an Alibaba Cloud Model Studio application, such as an agent or a workflow . This method is suitable for real-time interactive scenarios that require immediate results and lets you easily reuse existing OpenAI codebases or quickly integrate various tools from the OpenAI ecosystem.
- Asynchronous invocation: For long-running tasks, such as generating reports or multi-step tool calling, see the Asynchronous Invocation API Reference to avoid request timeouts.
- DashScope API: For more comprehensive features and better performance, see the DashScope API Reference.
Prerequisites
- You have obtained an API key and configured the API key as an environment variable.
- You have created an Alibaba Cloud Model Studio application and obtained its application ID by copying it from the application card on the Application Management page.
- If you make calls using the SDK, you also need to install the OpenAI Python SDK.
base_url to configure for SDK calls: https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1
The Endpoint to configure for HTTP calls: POST https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/responses
{APP_ID} with your actual application ID.Request bodyapp_id string(Required)The ID of the application.On the Application Management page, you can obtain the application ID from the application card.
When you make an HTTP call, replace inputstring/array(Required)The core input content for the request. This can be a simple string or an array of message objects that contains the multi-turn conversation history.
boolean(Optional)Specifies whether to stream the reply.
boolean(Optional)Specifies whether to execute the task asynchronously.Asynchronous invocation does not support streaming output.
|
Single-turn conversation input parameter. |
Response object (non-streaming)idstringThe unique identifier (ID) for this request. You can use it for log records and issue tracking. object stringThe object type, which is always response for this API.created_at integerThe Unix timestamp (in seconds) when the response was created. status stringThe final status of the response task. A value of completed indicates that the task finished successfully.outputarrayAn array that contains all the output content generated by the model.
Sub-properties output message objectA message object that contains the model's output content.
Sub-properties content arrayAn array of core message content, which can include various types of content blocks, such as text, code, and images.
Sub-properties text stringThe actual text reply generated by the model. type stringThe type of the content block. A value of output_text indicates an output text block.stringThe unique ID of this output message. role stringThe role of the message. A value of assistant indicates that this message was generated by the AI assistant.status stringThe generation status of the message. A value of completed indicates that the message was generated successfully.type stringThe type of the element in the output array. A value of message indicates a message object. |
Response object (streaming)idstringThe message ID of the event.code stringThe error code. This field is empty if the call is successful.messagestringThe detailed error message. This field is ignored if the request is successful.event stringThe event type, which indicates the current status of the response.
Common event data sequence_number integerThe serial number of the event, which starts from 0 and increments.type stringThe event type. The value is the same as the event field.
Detailed event types
Overall response lifecycle events response.created: Indicates that the response has been created.response.in_progress: Indicates that the response is being processed.response.completed: The response is complete.
Common data response objectThe response object, which contains detailed information about the response*.*
Sub-properties id stringThe unique ID of the response.statusstringThe final status of the response.objectstringThe object type. The value is always "response".created_atintegerThe Unix timestamp (in seconds) when the response was created. output arrayA list of output content.
Sub-properties output message objectA message object that contains the model's output content.
Sub-properties id stringThe unique ID of the output item.type stringThe type of the output item.
stringThe role of the message.contentarrayA list of output content parts.
Sub-properties type stringThe type of the content part. For example, "output_text" indicates a text part.textstringThe text content.annotationsarrayA list of annotations.stringThe current status of the response.
Content construction events response.output_item.added: Indicates that an output item has been added.
Sub-properties output_index integerThe index of the item in the output array.itemobjectThe newly added output item object.
Sub-properties output message objectA message object that contains the model's output content.
Sub-properties id stringThe unique ID of the output item.type stringThe type of the output item.
stringThe role of the message.contentarrayA list of content parts.statusstringThe current status of the response.
Sub-properties output_index integerThe index of the completed item in the output array.itemobjectThe complete output item object.
Sub-properties id stringThe unique ID of the output item.type stringThe type of the output item.
stringThe role of the message.contentarrayA list of output content parts.
Sub-properties type stringThe type of the content part. For example, "output_text" indicates a text part.textstringThe text content.annotationsarrayA list of annotations.stringThe current status of the response.
Sub-properties output_index integerThe index in the response.output array.content_indexintegerThe index in the item.content array.item_idstringThe ID of the associated output item.partobjectThe newly added content part object.
Sub-properties type stringThe type of the content part. For example, "output_text" indicates a text part.text stringThe text content.annotationsarrayA list of annotations.
Sub-properties output_index integerThe index in the response.output array.content_indexintegerThe index in the item.content array.item_idstringThe ID of the associated output item.partobjectThe newly added content part object.
Sub-properties type stringThe type of the content part. For example, "output_text" indicates a text part.text stringThe text content.annotationsarrayA list of annotations.
Text stream events response.output_text.delta: A text increment of the output content.
Sub-properties delta stringAn incremental chunk of the output text.output_indexintegerThe index in the response.output array.content_indexintegerThe index in the item.content array.item_idstringThe ID of the associated output item.
Sub-properties text stringThe complete output text content.output_indexintegerThe index in the response.output array.content_indexintegerThe index in the item.content array.item_idstringThe ID of the associated output item.
Sub-properties delta stringAn incremental chunk of the reasoning text.output_indexintegerThe index in the response.output array.content_indexintegerThe index in the item.content array.item_idstringThe ID of the associated output item.
Sub-properties text stringThe complete reasoning process.output_indexintegerThe index in the response.output array.content_indexintegerThe index in the item.content array.item_idstringThe ID of the associated output item. |
FAQ
-
How do I pass the context for a multi-turn conversation?
You must maintain the complete conversation history on the client side and pass all historical messages in the
inputarray with each API request. Context management based onpre_response_idorconversation_idwill be supported in a future release. -
Why are some fields in the response examples not described in this topic?
If you use the official OpenAI SDK, the SDK may return extra fields that are usually
null. These fields are part of the OpenAI protocol's data model but are not supported by this service. You can safely ignore these fields and focus on the ones described in this document.