Create thread
Create a thread.
Create thread
curl https://api.openai.com/v1/threads \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
-d ''
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699012949,
"metadata": {},
"tool_resources": {}
}
Body ParametersJSON
messages: optional array of object { content, role, attachments, metadata } A list of messages to start the thread with.
A list of messages to start the thread with.
content: string or array of ImageFileContentBlock { image_file, type } or ImageURLContentBlock { image_url, type } or TextContentBlockParam { text, type } The text contents of the message.
The text contents of the message.
ArrayOfContentParts = array of ImageFileContentBlock { image_file, type } or ImageURLContentBlock { image_url, type } or TextContentBlockParam { text, type } An array of content parts with a defined type, each can be of type text or images can be passed with image_url or image_file. Image types are only supported on Vision-compatible models.
minItems1
An array of content parts with a defined type, each can be of type text or images can be passed with image_url or image_file. Image types are only supported on Vision-compatible models.
ImageFileContentBlock object { image_file, type } References an image File in the content of a message.
References an image File in the content of a message.
The File ID of the image in the message content. Set purpose="vision" when uploading the File if you need to later display the file content.
role: "user" or "assistant"The role of the entity that is creating the message. Allowed values include:
user: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages.
assistant: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation.
The role of the entity that is creating the message. Allowed values include:
user: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages.assistant: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation.
attachments: optional array of object { file_id, tools } or nullA list of files attached to the message, and the tools they should be added to.
A list of files attached to the message, and the tools they should be added to.
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
tool_resources: optional object { code_interpreter, file_search } or nullA set of resources that are made available to the assistant’s tools in this thread. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.
A set of resources that are made available to the assistant’s tools in this thread. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.
code_interpreter: optional object { file_ids }
A list of file IDs made available to the code_interpreter tool. There can be a maximum of 20 files associated with the tool.
file_search: optional object { vector_store_ids, vector_stores }
The vector store attached to this thread. There can be a maximum of 1 vector store attached to the thread.
vector_stores: optional array of object { chunking_strategy, file_ids, metadata } A helper to create a vector store with file_ids and attach it to this thread. There can be a maximum of 1 vector store attached to the thread.
maxItems1
A helper to create a vector store with file_ids and attach it to this thread. There can be a maximum of 1 vector store attached to the thread.
chunking_strategy: optional Auto { type } or Static { static, type } The chunking strategy used to chunk the file(s). If not set, will use the auto strategy.
The chunking strategy used to chunk the file(s). If not set, will use the auto strategy.
Auto object { type } The default strategy. This strategy currently uses a max_chunk_size_tokens of 800 and chunk_overlap_tokens of 400.
The default strategy. This strategy currently uses a max_chunk_size_tokens of 800 and chunk_overlap_tokens of 400.
A list of file IDs to add to the vector store. For vector stores created before Nov 2025, there can be a maximum of 10,000 files in a vector store. For vector stores created starting in Nov 2025, the limit is 100,000,000 files.
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
Returns
Thread object { id, created_at, metadata, 2 more } Represents a thread that contains messages.
Represents a thread that contains messages.
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
tool_resources: object { code_interpreter, file_search } or nullA set of resources that are made available to the assistant’s tools in this thread. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.
A set of resources that are made available to the assistant’s tools in this thread. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.
code_interpreter: optional object { file_ids }
A list of file IDs made available to the code_interpreter tool. There can be a maximum of 20 files associated with the tool.
file_search: optional object { vector_store_ids }
The vector store attached to this thread. There can be a maximum of 1 vector store attached to the thread.
Returns Examples
{
"id": "id",
"created_at": 0,
"metadata": {
"foo": "string"
},
"object": "thread",
"tool_resources": {
"code_interpreter": {
"file_ids": [
"string"
]
},
"file_search": {
"vector_store_ids": [
"string"
]
}
}
}