Create thread
Create a thread.
Request body
messagesarray
A list of messages to start the thread with.
itemsobject
rolestringRequired
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.
userstring
assistantstring
contentstring or array
Text contentstringRequired
The text contents of the message.Array of content partsarrayRequired
An array of content parts with a defined type, each can be of type
textor images can be passed withimage_urlorimage_file. Image types are only supported on Vision-compatible models.Image fileobject
References an image File in the content of a message.
typestringRequired
Always
image_file.image_filestring
image_fileobjectRequired
file_idstringRequired
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.detailstringDefaults: auto
Specifies the detail level of the image if specified by the user.
lowuses fewer tokens, you can opt in to high resolution usinghigh.autostring
lowstring
highstring
Image URLobject
References an image URL in the content of a message.typestringRequired
The type of the content part.image_urlstring
image_urlobjectRequired
urlstringRequired
The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp.detailstringDefaults: auto
Specifies the detail level of the image.
lowuses fewer tokens, you can opt in to high resolution usinghigh. Default value isautoautostring
lowstring
highstring
Textobject
The text content that is part of a message.typestringRequired
Always
text.textstring
textstringRequired
Text content to be sent to the model
attachmentsarray or null
A list of files attached to the message, and the tools they should be added to.itemsobject
file_idstring
The ID of the file to attach to the message.toolsarray
The tools to add this file to.Code interpreter toolobject
typestringRequired
The type of tool being defined:
code_interpretercode_interpreterstring
FileSearch toolobject
typestringRequired
The type of tool being defined:
file_searchfile_searchstring
metadataobject 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_resourcesobject 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_interpretertool requires a list of file IDs, while thefile_searchtool requires a list of vector store IDs.code_interpreterobject
file_idsarrayDefaults:
A list of file IDs made available to the
code_interpretertool. There can be a maximum of 20 files associated with the tool.itemsstring
file_searchobject
file_searchobject
file_searchobject
metadataobject 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 }