Create thread
Create a thread.
Request body
messages
array
A list of messages to start the thread with.
items
object
role
string
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.
user
string
assistant
string
content
string or array
Text content
string
Required
The text contents of the message.Array of content parts
array
Required
An array of content parts with a defined type, each can be of type
text
or images can be passed withimage_url
orimage_file
. Image types are only supported on Vision-compatible models.Image file
object
References an image File in the content of a message.
type
string
Required
Always
image_file
.image_file
string
image_file
object
Required
file_id
string
Required
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.detail
string
Defaults: auto
Specifies the detail level of the image if specified by the user.
low
uses fewer tokens, you can opt in to high resolution usinghigh
.auto
string
low
string
high
string
Image URL
object
References an image URL in the content of a message.type
string
Required
The type of the content part.image_url
string
image_url
object
Required
url
string
Required
The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp.detail
string
Defaults: auto
Specifies the detail level of the image.
low
uses fewer tokens, you can opt in to high resolution usinghigh
. Default value isauto
auto
string
low
string
high
string
Text
object
The text content that is part of a message.type
string
Required
Always
text
.text
string
text
string
Required
Text content to be sent to the model
attachments
array or null
A list of files attached to the message, and the tools they should be added to.items
object
file_id
string
The ID of the file to attach to the message.tools
array
The tools to add this file to.Code interpreter tool
object
type
string
Required
The type of tool being defined:
code_interpreter
code_interpreter
string
FileSearch tool
object
type
string
Required
The type of tool being defined:
file_search
file_search
string
metadata
object or null
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 or null
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 thefile_search
tool requires a list of vector store IDs.code_interpreter
object
file_ids
array
Defaults:
A list of file IDs made available to the
code_interpreter
tool. There can be a maximum of 20 files associated with the tool.items
string
file_search
object
file_search
object
file_search
object
metadata
object or null
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.
Response
A thread object.
1 curl https://api.openai.com/v1/threads \2 -H "Content-Type: application/json" \3 -H "Authorization: Bearer $OPENAI_API_KEY" \4 -H "OpenAI-Beta: assistants=v2" \5 -d ''
1 {2 "id": "thread_abc123",3 "object": "thread",4 "created_at": 1699012949,5 "metadata": {},6 "tool_resources": {}7 }