Skip to content

Create a thread.

POST
/threads

Authorizations

Request Body

object
messages

A list of messages to start the thread with.

Array<object>
object
role
required

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.
string
Allowed values: user assistant
content
required
One of:

The text contents of the message.

string
attachments

A list of files attached to the message, and the tools they should be added to.

Array<object>
nullable
object
file_id

The ID of the file to attach to the message.

string
tools

The tools to add this file to.

Array
One of:
object
type
required

The type of tool being defined: code_interpreter

string
Allowed values: code_interpreter
metadata

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. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

object
tool_resources

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.

object
code_interpreter
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.

Array<string>
default: <= 20 items
file_search
One of:
object
vector_store_ids
required

The vector store attached to this thread. There can be a maximum of 1 vector store attached to the thread.

Array<string>
<= 1 items
vector_stores

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.

Array<object>
<= 1 items
object
file_ids

A list of file IDs to add to the vector store. There can be a maximum of 10000 files in a vector store.

Array<string>
<= 10000 items
chunking_strategy
One of:

The default strategy. This strategy currently uses a max_chunk_size_tokens of 800 and chunk_overlap_tokens of 400.

object
type
required

Always auto.

string
Allowed values: auto
metadata

Set of 16 key-value pairs that can be attached to a vector store. This can be useful for storing additional information about the vector store in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

object
metadata

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. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

object

Responses

200

OK

Represents a thread that contains messages.

object
id
required

The identifier, which can be referenced in API endpoints.

string
object
required

The object type, which is always thread.

string
Allowed values: thread
created_at
required

The Unix timestamp (in seconds) for when the thread was created.

integer
tool_resources
required

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.

object
code_interpreter
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.

Array<string>
default: <= 20 items
file_search
object
vector_store_ids

The vector store attached to this thread. There can be a maximum of 1 vector store attached to the thread.

Array<string>
<= 1 items
metadata
required

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. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

object