Skip to main content
Assistant API (Deprecated)

Threads (Deprecated)

This topic describes the Thread class in the assistant API, including how to create, retrieve, modify, and delete threads.

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.
Overview: For more information about the features and basic usage of the assistant API, see Assistant API overview.
Retention period: All Thread instances are stored on the Alibaba Cloud Model Studio server and do not expire. You can use the thread ID to retrieve context information.

Function name

Type

create

Creates a Thread class.

retrieve

Retrieves a Thread class.

update

Modifies a Thread class.

delete

Deletes a Thread class.

Create a thread

  • HTTP
  • SDK
Sample code
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "messages": [
        {
            "role": "user",
            "content": "hello"
        }
    ]
}'
Request parameters

Input parameter name

Input parameter descriptions

Type

Required

messages

The messages passed to the thread.

Message class

No

metadata

Thread name

object

No

Response
{
    "id": "thread_e99a9fe7-0433-426f-98ad-a5139c36579c",
    "object": "thread",
    "created_at": 1711448377850,
    "metadata": {},
    "request_id": "dd9489ec-dbdb-95d4-9ff8-cfe29b61db27"
}
Response parametersThe response returns a thread object with the following additional fields:
  • id: The thread ID.
  • request_id: The request ID.

Retrieve a thread

  • HTTP
  • SDK
Sample code
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_c7ebb0ca-2e4f-43e5-b223-6e1f8c6fccc7' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request parameters

Parameter Name

Parameter description

Type

Required

thread_id

The ID of the thread to retrieve.

str

Yes

Result
{
    "id": "thread_c7ebb0ca-2e4f-43e5-b223-6e1f8c6fccc7",
    "object": "thread",
    "created_at": 1711507920700,
    "metadata": {},
    "request_id": "4d4e73ad-15fb-96ac-9262-0643a0fdb5ca"
}
Response parametersThe response contains the retrieved thread object, which includes the following additional fields:
  • ID: Thread ID
  • request_id: The ID of the request.

Modify a thread

  • HTTP
  • SDK
Sample code
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_c7ebb0ca-2e4f-43e5-b223-6e1f8c6fccc7' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "metadata": {
        "modified": "true",
        "user": "abc123"
    }
}'
Request parameters

Input Parameter Name

Input Parameter Descriptions

Type

Required

thread_id

The ID of the thread to modify.

str

Yes

metadata

Thread name

dict

No

Result
{
    "id": "thread_c7ebb0ca-2e4f-43e5-b223-6e1f8c6fccc7",
    "object": "thread",
    "created_at": 1711507920700,
    "metadata": {
        "modified": "true",
        "user": "abc123"
    },
    "request_id": "a9ad63fa-b884-94be-9ec6-5000882de3c4"
}
Response parametersThe output contains the retrieved thread class and additional fields that are not specified in the user-provided parameters:
  • id: thread_id
  • request_id: The request ID.

Delete a thread

  • HTTP
  • SDK
Sample code
curl --location --request DELETE 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_c7ebb0ca-2e4f-43e5-b223-6e1f8c6fccc7' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request parameters

Input Parameter Name

Description

Type

Required

id

The ID of the thread to delete

str

Yes

Response
{
    "id": "thread_c7ebb0ca-2e4f-43e5-b223-6e1f8c6fccc7",
    "object": "thread.deleted",
    "deleted": true,
    "request_id": "b4edb7b8-5855-9787-b5c3-0374ee2b3b2c"
}
Response parametersThe status of the thread after deletion.

Error codes

If a model call fails and an error message is returned, see Error codes for troubleshooting.