Skip to main content
Assistant API (Deprecated)

Messages (Deprecated)

This topic describes how to use the Message class in the assistant API to create, list, retrieve, and modify messages.

The Assistant API is being deprecated. Migrate to the Responses API as an alternative. The Responses API includes multiple built-in tools and supports multi-turn context management.

Function name

Type

create

Create a message class

retrieve

Retrieve a message class

modify

Modify a message class

list

List message classes

Create a message

  • HTTP
  • SDK
Code example
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_e99a9fe7-0433-426f-98ad-a5139c36579c/messages' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "role": "user",
    "content": "Who are you",
    "metadata": {}
}'
Request parameters

Parameter name

Input Parameters

Parameter type

Required

thread id

The thread ID to which the message is passed.

string

Yes

content

The content of the message.

string

Yes

role

The role of the entity that provides the message. Only `user` is supported.

string

No

metadata

Other related information.

object

No

Response
{
    "id": "message_f1933671-19e1-4162-ad25-7326165123e1",
    "object": "thread.message",
    "created_at": 1711508433283,
    "thread_id": "thread_e99a9fe7-0433-426f-98ad-a5139c36579c",
    "incomplete_details": {},
    "completed_at": null,
    "incomplete_at": null,
    "assistant_id": "",
    "run_id": "",
    "file_ids": [],
    "role": "user",
    "content": [
        {
            "type": "text",
            "text": {
                "value": "Who are you",
                "annotations": []
            }
        }
    ],
    "metadata": {},
    "name": "",
    "plugin_call": {},
    "tool_calls": [],
    "status": "",
    "request_id": "b3ad40b9-f052-9665-a064-dab11c34625f"
}
Response parametersThe message class is returned. In addition to the request parameters, the response contains the following fields:
  • id: the message ID.
  • request_id: the request ID.

List messages

  • HTTP
  • SDK
Code example
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_e99a9fe7-0433-426f-98ad-a5139c36579c/messages?limit=2&order=desc' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request parameters

Parameter name

Description

Parameter type

Required

thread id

The thread ID to which the message is passed.

string

Yes

limit

Number of messages

integer

No

order

The sorting order by creation time: `asc` or `desc`.

string

No (Default: `desc`)

Response
{
    "object": "list",
    "data": [
        {
            "id": "message_f1933671-19e1-4162-ad25-7326165123e1",
            "object": "thread.message",
            "created_at": 1711508433283,
            "thread_id": "thread_e99a9fe7-0433-426f-98ad-a5139c36579c",
            "assistant_id": "",
            "run_id": "",
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": {
                        "value": "Who are you",
                        "annotations": []
                    }
                }
            ],
            "metadata": {},
            "name": "",
            "plugin_call": {},
            "tool_calls": [],
            "status": ""
        }
    ],
    "first_id": "message_f1933671-19e1-4162-ad25-7326165123e1",
    "last_id": "message_f1933671-19e1-4162-ad25-7326165123e1",
    "has_more": false,
    "request_id": "78f7d607-4a9a-90c6-8040-d3f81c84d60a"
}
Response parametersA list of message classes is returned. The response also includes the original request parameters and the following additional fields:
  • A list of multiple messages.

Retrieve a message

  • HTTP
  • SDK
Code example
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_e99a9fe7-0433-426f-98ad-a5139c36579c/messages/message_ea26d29d-4509-490e-98e9-9f6238bd821b' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request parameters

Parameter name

Description

Parameter type

Required

thread id

The thread ID of the message to retrieve.

string

Yes

message_id

The ID of the message to retrieve.

string

Yes

Response
{
    "id": "message_ea26d29d-4509-490e-98e9-9f6238bd821b",
    "object": "thread.message",
    "created_at": 1711508622598,
    "thread_id": "thread_e99a9fe7-0433-426f-98ad-a5139c36579c",
    "assistant_id": "",
    "run_id": "",
    "role": "user",
    "content": [
        {
            "type": "text",
            "text": {
                "value": "Hello",
                "annotations": []
            }
        }
    ],
    "metadata": {},
    "name": "",
    "plugin_call": {},
    "tool_calls": [],
    "status": "",
    "request_id": "4d5ce962-91c3-9edb-87f7-00bbf985135e"
}
Response parametersThe retrieved message class is returned. In addition to the request parameters, the response contains the following fields:
  • id: Message ID
  • request_id: the request ID.

Modify a message

  • HTTP
  • SDK
Code example
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_e99a9fe7-0433-426f-98ad-a5139c36579c/messages/message_ea26d29d-4509-490e-98e9-9f6238bd821b' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "metadata": {
        "modified": "true",
        "user": "abc123"
    }
}'
Request parameters

Parameter name

Input Parameters

Parameter type

Required

thread_id

The ID of the thread to modify.

string

Yes

message_id

The ID of the message to modify.

string

Yes

metadata

The metadata.

dict

Response
{
    "id": "message_ea26d29d-4509-490e-98e9-9f6238bd821b",
    "object": "thread.message",
    "created_at": 1711508622598,
    "thread_id": "thread_e99a9fe7-0433-426f-98ad-a5139c36579c",
    "incomplete_details": {},
    "completed_at": null,
    "incomplete_at": null,
    "assistant_id": "",
    "run_id": "",
    "file_ids": [],
    "role": "user",
    "content": [
        {
            "type": "text",
            "text": {
                "value": "Hello",
                "annotations": []
            }
        }
    ],
    "metadata": {
        "modified": "true",
        "user": "abc123"
    },
    "name": "",
    "plugin_call": {},
    "tool_calls": [],
    "status": "",
    "request_id": "7877b011-cb94-9df1-9add-dc42b7d611f6"
}
Output ParametersThe modified message class is returned. In addition to the request parameters, the response contains the following fields:
  • id: Message ID
  • request_id: the request ID.

Error codes

If an assistant API call fails and returns an error message, see Error messages to resolve the issue.