This topic describes the API operations that can be used by developers to manage messages of DashScope.
Function | Description |
create | Creates a message |
retrieve | Queries the information about a message |
modify | Modifies a message |
list | Queries a list of messages |
Create a message
Sample request
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 <your-dashscope-api-key>' \
--data '{
"role": "user",
"content": "Who are you?"
"metadata": {}
}'
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread that is used to process the message. | str | Yes |
content | The message content. | str | Yes |
role | The role that creates the message. Set the value to user. | str | No |
metadata | The metadata. | str | No |
Response parameters
{
"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": []
}
}
],
"file_ids": [],
"metadata": {},
"from": "",
"name": "",
"plugin_call": {},
"tool_calls": [],
"status": {},
"request_id": "b3ad40b9-f052-9665-a064-dab11c34625f"
}
The returned message
class contains the parameters that you specify and the following additional parameters:
id: the message ID.
request_id: the request ID.
Query a list of messages
Sample request
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 <your-dashscope-api-key>'
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread that is used to process the message. | str | Yes |
limit | The maximum number of messages that can be returned. | int | No |
order | The ascending or descending order in which the messages are sorted based on the creation time. Default value: desc. | str | No |
Response parameters
{
"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": []
}
}
],
"file_ids": [],
"metadata": {},
"from": "",
"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"
}
The returned message list
class contains the parameters you specify and the following additional parameter:
A list of messages.
Query a list of files associated with a message
Sample request
This operation returns a list of files that are associated with a message.
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_e99a9fe7-0433-426f-98ad-a5139c36579c/messages/message_ea26d29d-4509-490e-98e9-9f6238bd821b/files?limit=2&order=desc' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-dashscope-api-key>'
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread that is used to process the message. | str | Yes |
message id | The ID of the message with which the files are associated. | str | Yes |
limit | The maximum number of files that can be returned. | int | No |
order | The ascending or descending order in which the messages are sorted based on the creation time Default value: desc. | str | No |
Response parameters
{
"object": "list",
"data": [
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1711508622608,
"message_id": "message_ea26d29d-4509-490e-98e9-9f6238bd821b"
}
],
"first_id": "file-abc123",
"last_id": "file-abc123",
"has_more": false,
"request_id": "5e9f2b36-9aa7-9242-b86b-36b8f3a95bd9"
}
The returned message file list
class contains the parameters that you specify and the following additional parameters:
A list of files.
request_id: the request ID.
Query the information about a message
Sample request
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 <your-dashscope-api-key>'
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread that is used to process the message. | str | Yes |
message_id | The ID of the message to be queried. | str | Yes |
Response parameters
{
"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": []
}
}
],
"file_ids": [
"file-abc123"
],
"metadata": {},
"from": "",
"name": "",
"plugin_call": {},
"tool_calls": [],
"status": {},
"request_id": "4d5ce962-91c3-9edb-87f7-00bbf985135e"
}
The returned message class
contains the parameters that you specify and the following additional parameters:
id: the message ID.
request_id: the request ID.
Query the information about a file associated with a message
Sample request
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_e99a9fe7-0433-426f-98ad-a5139c36579c/messages/message_ea26d29d-4509-490e-98e9-9f6238bd821b/files/file-abc123' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-dashscope-api-key>'
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread that is used to process the message. | str | Yes |
message_id | The ID of the message with which the file is associated. | str | Yes |
file_id | The ID of the file to be queried. | str | Yes |
Response parameters
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1711508622608,
"message_id": "message_ea26d29d-4509-490e-98e9-9f6238bd821b",
"request_id": "04ac8567-aef9-9f11-b83f-131e735e6ff8"
}
The returned message file class
contains the parameters that you specify and the following additional parameters:
id: the file ID.
request_id: the request ID.
Update a message
Sample request
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 <your-dashscope-api-key>' \
--data '{
"metadata": {
"modified": "true",
"user": "abc123"
}
}'
Request parameters
Parameter | Description | Type | Required |
thread_id | The ID of the thread that is used to process the message. | str | Yes |
message_id | The ID of the message to be updated. | str | Yes |
metadata | The metadata. | dict |
Response parameters
{
"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": []
}
}
],
"file_ids": [
"file-abc123"
],
"metadata": {
"modified": "true",
"user": "abc123"
},
"from": "",
"name": "",
"plugin_call": {},
"tool_calls": [],
"status": {},
"request_id": "7877b011-cb94-9df1-9add-dc42b7d611f6"
}
The returned message
class contains the parameters that you specify and the following additional parameters:
id: the message ID.
request_id: the request ID.