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.
North China 2 (Beijing): POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations
Singapore: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations
itemsarray (Optional)A list of up to 20 initial message items.
Properties type string(Required)The message type. Only message is supported.rolestring(Required)The role of the message. Instructions from the system and developer roles have a higher priority than instructions from the user role. The assistant role indicates messages that were generated by the model in previous interactions. Valid values are user, assistant, system, and developer.contentstring or array(Required)The message content. This parameter supports plain text strings or structured content lists, such as ResponseInputText object arrays. The list format can include various content types, such as text.object (Optional)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. | Python |
Response parameters
created_atintegerThe Unix timestamp in milliseconds that indicates when the conversation was created.idstringThe unique ID of the conversation.metadataobjectThe 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.objectstringThe object type. The value is fixed as conversation. |
Retrieve conversation
Retrieves information for a specified conversation.
North China 2 (Beijing): GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}
Singapore: GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}
conversation_idstring(Required, Path)The conversation ID. | Python |
Response parameters
created_atintegerThe Unix timestamp in milliseconds that indicates when the conversation was created.idstringThe unique ID of the conversation.metadataobjectThe 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.objectstringThe object type. The value is fixed as conversation. |
Update conversation
Updates the metadata for a conversation.
North China 2 (Beijing): POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}
Singapore: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}
conversation_idstring(Required, Path)The ID of the conversation.metadataobject(Required)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. | Python |
Response parameters
created_atintegerThe Unix timestamp in milliseconds that indicates when the conversation was created.idstringThe unique ID of the conversation.metadataobjectThe 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.objectstringThe object type. The value is fixed as conversation. |
Delete conversation
Deletes a specified conversation. Message items within the conversation are not deleted.
North China 2 (Beijing): DELETE https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}
Singapore: DELETE https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}
conversation_idstring(Required, Path)The conversation ID. | Python |
Response parameters
deletedbooleanIndicates whether the deletion was successful.idstringThe ID of the deleted conversation.objectstringThe object type. The value is fixed as conversation.deleted. |
Create items
Adds message items to a specified conversation.
North China 2 (Beijing): POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items
Singapore: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items
conversation_idstring(Required, Path)The ID of the conversation.itemsarray(Required)A list of message items. You can add up to 20 items at a time.
Properties type string(Required)The message type. Only message is supported.rolestring(Required)The role of the message. Instructions from the system and developer roles have a higher priority than instructions from the user role. The assistant role indicates messages that were generated by the model in previous interactions. Valid values are user, assistant, system, and developer.contentstring or array(Required)The message content. This parameter supports plain text strings or structured content lists, such as ResponseInputText object arrays. The list format can include various content types, such as text. | Python |
Response parameters
dataarray[object]A list of the created message items.
Properties id stringThe unique ID of the message item.contentstring or arrayThe message content. This can be a plain text string or a structured content list, such as a ResponseInputText object array.rolestringThe role of the message. Valid values are user, assistant, system, and developer.statusstringThe processing status of the message. Valid values are in_progress, completed, and incomplete.typestringThe type of the message item. The value is fixed as message.stringThe ID of the first message item in the list.has_morebooleanIndicates whether more data is available.last_idstringThe ID of the last message item in the list. |
List items
Lists all message items in a conversation.
North China 2 (Beijing): GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items
Singapore: GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items
conversation_idstring(Required, Path)The ID of the conversation.afterstring (Optional)The pagination cursor. Returns only message items created after the specified message ID.orderstring (Optional)The sort order. Valid values are asc for ascending and desc for descending. The default value is desc.limitinteger (Optional)The number of items to return. The value must be an integer from 1 to 100. The default value is 20. | Python |
Response parameters
dataarray[object]A list of the message items.
Properties id stringThe unique ID of the message item.contentstring or arrayThe message content. This can be a plain text string or a structured content list, such as a ResponseInputText object array.rolestringThe role of the message. Valid values are user, assistant, system, and developer.statusstringThe processing status of the message. Valid values are in_progress, completed, and incomplete.typestringThe type of the message item. The value is fixed as message.stringThe ID of the first message item in the list.has_morebooleanIndicates whether more data is available.last_idstringThe ID of the last message item in the list.objectstringThe object type. The value is fixed as list. |
Retrieve item
Retrieves the details for a specified message item.
North China 2 (Beijing): GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
Singapore: GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
conversation_idstring(Required, Path)The ID of the conversation.item_idstring(Required, Path)The ID of the message item. | Python |
Response parameters
contentarray[object]A list of message content that contains one or more content objects.
Properties type stringThe content type, such as input_text for user input text or output_text for model output text.textstringThe text content.stringThe unique ID of the message item.rolestringThe role of the message. Valid values are user, assistant, system, and developer.statusstringThe processing status of the message. Valid values are in_progress, completed, and incomplete.typestringThe type of the message item. The value is fixed as message. |
Delete item
Deletes a specified message item.
North China 2 (Beijing): DELETE https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
Singapore: DELETE https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/conversations/{conversation_id}/items/{item_id}
conversation_idstring(Required, Path)The ID of the conversation.item_idstring(Required, Path)The ID of the message item. | Python |
Response parameters
deletedbooleanIndicates whether the item was successfully deleted.idstringThe ID of the deleted message item.objectstringThe object type. The value is fixed as conversation.item.deleted. |
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
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. - Conversation data is retained for a maximum of 7 days and limited to the latest 100 entries. Any data exceeding the time or quantity limit will be automatically cleared.