Manually managing message lists for conversations that span multiple devices or have long interruptions can lead to context loss. Alibaba Cloud Model Studio provides an OpenAI compatible Conversations API that you can use with the Responses API to automatically inject historical context. This eliminates the need for manual message synchronization and ensures conversational continuity across different scenarios and devices.
Create conversation
Creates a new conversation. You can optionally include initial message items.
Chinese mainland: POST https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations
International: POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations
|
items A list of up to 20 initial message items. |
Python
Node.js
cURL
|
|
metadata The conversation metadata. Use this parameter to store additional conversation information in a structured format. Specify up to 16 key-value pairs. The key can be up to 64 characters long, and the value can be up to 512 characters long. |
Response parameters
|
created_at The Unix timestamp in milliseconds that indicates when the conversation was created. |
|
|
id The unique ID of the conversation. |
|
|
metadata The conversation metadata. This parameter stores additional information as key-value pairs. It can contain up to 16 pairs. The key can be up to 64 characters long, and the value can be up to 512 characters long. |
|
|
object The object type. The value is fixed as |
Retrieve conversation
Retrieves information for a specified conversation.
Chinese mainland: GET https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}
International: GET https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}
|
conversation_id The conversation ID. |
Python
Node.js
cURL
|
Response parameters
|
created_at The Unix timestamp in milliseconds that indicates when the conversation was created. |
|
|
id The unique ID of the conversation. |
|
|
metadata The conversation metadata. This parameter stores additional information as key-value pairs. It can contain up to 16 pairs. The key can be up to 64 characters long, and the value can be up to 512 characters long. |
|
|
object The object type. The value is fixed as |
Update conversation
Updates the metadata for a conversation.
Chinese mainland: POST https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}
International: POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}
|
conversation_id The ID of the conversation. |
Python
Node.js
cURL
|
|
metadata The conversation metadata. This parameter completely overwrites the existing metadata. Specify up to 16 key-value pairs. The key can be up to 64 characters long, and the value can be up to 512 characters long. |
Response parameters
|
created_at The Unix timestamp in milliseconds that indicates when the conversation was created. |
|
|
id The unique ID of the conversation. |
|
|
metadata The conversation metadata. This parameter stores additional information as key-value pairs. It can contain up to 16 pairs. The key can be up to 64 characters long, and the value can be up to 512 characters long. |
|
|
object The object type. The value is fixed as |
Delete conversation
Deletes a specified conversation. Message items within the conversation are not deleted.
Chinese mainland: DELETE https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}
International: DELETE https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}
|
conversation_id The conversation ID. |
Python
Node.js
cURL
|
Response parameters
|
deleted Indicates whether the deletion was successful. |
|
|
id The ID of the deleted conversation. |
|
|
object The object type. The value is fixed as |
Create items
Adds message items to a specified conversation.
Chinese mainland: POST https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items
International: POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items
|
conversation_id The ID of the conversation. |
Python
Node.js
cURL
|
|
items A list of message items. You can add up to 20 items at a time. |
Response parameters
|
data A list of the created message items. |
|
|
first_id The ID of the first message item in the list. |
|
|
has_more Indicates whether more data is available. |
|
|
last_id The ID of the last message item in the list. |
List items
Lists all message items in a conversation.
Chinese mainland: GET https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items
International: GET https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items
|
conversation_id The ID of the conversation. |
Python
Node.js
cURL
|
|
after The pagination cursor. Returns only message items created after the specified message ID. |
|
|
order The sort order. Valid values are |
|
|
limit The number of items to return. The value must be an integer from 1 to 100. The default value is 20. |
Response parameters
|
data A list of the message items. |
|
|
first_id The ID of the first message item in the list. |
|
|
has_more Indicates whether more data is available. |
|
|
last_id The ID of the last message item in the list. |
|
|
object The object type. The value is fixed as |
Retrieve item
Retrieves the details for a specified message item.
Chinese mainland: GET https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
International: GET https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
|
conversation_id The ID of the conversation. |
Python
Node.js
cURL
|
|
item_id The ID of the message item. |
Response parameters
|
content A list of message content that contains one or more content objects. |
|
|
id The unique ID of the message item. |
|
|
role The role of the message. Valid values are |
|
|
status The processing status of the message. Valid values are |
|
|
type The type of the message item. The value is fixed as |
Delete item
Deletes a specified message item.
Chinese mainland: DELETE https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
International: DELETE https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
|
conversation_id The ID of the conversation. |
Python
Node.js
cURL
|
|
item_id The ID of the message item. |
Response parameters
|
deleted Indicates whether the item was successfully deleted. |
|
|
id The ID of the deleted message item. |
|
|
object The object type. The value is fixed as |
Use conversations in the Responses API
Use the conversation parameter of the Responses API to maintain context in multi-turn conversations.
Do not pass bothprevious_response_idandconversationat the same time. Otherwise, the following error occurs:[400] INVALID_REQUEST: Mutually exclusive parameters: Ensure you are only providing one of: previous_response_id or conversation.
Python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",
)
conversation = client.conversations.create(
items=[
{
"type": "message",
"role": "system",
"content": "Alice, a gentle and resilient woman, was born in Singapore. She is 20 years old, and her hobbies are music and chess.",
}
]
)
response1 = client.responses.create(
conversation=conversation.id, model="qwen3.5-plus", input="How old is Alice?"
)
print(f"First response: {response1.output_text}")
response2 = client.responses.create(
conversation=conversation.id, model="qwen3.5-plus", input="What are her hobbies?"
)
print(f"Second response: {response2.output_text}")
Node.js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",
});
const conversation = await client.conversations.create({
items: [
{
type: "message",
role: "system",
content: "Alice, a gentle and resilient woman, was born in Singapore. She is 20 years old, and her hobbies are music and chess."
}
]
});
const response1 = await client.responses.create({
conversation: conversation.id,
model: "qwen3.5-plus",
input: "How old is Alice?"
});
console.log("First response:", response1.output_text);
const response2 = await client.responses.create({
conversation: conversation.id,
model: "qwen3.5-plus",
input: "What are her hobbies?"
});
console.log("Second response:", response2.output_text);
Limitations
-
When you create a conversation or add message items, the
itemsarray can contain up to 20 entries. -
The
metadataobject can contain up to 16 key-value pairs. The key can be up to 64 characters long, and the value can be up to 512 characters long.