Create thread and run
Create a thread and run it in one request.
Request body
assistant_idstringRequired
The ID of the assistant to use to execute this run.
threadobject
Options to create a new thread. If no thread is provided when running a request, an empty thread will be created.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.
modelstring
The ID of the Model to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used.
modelstring
modelstring
gpt-4.1string
gpt-4.1-ministring
gpt-4.1-nanostring
gpt-4.1-2025-04-14string
gpt-4.1-mini-2025-04-14string
gpt-4.1-nano-2025-04-14string
gpt-4ostring
gpt-4o-2024-11-20string
gpt-4o-2024-08-06string
gpt-4o-2024-05-13string
gpt-4o-ministring
gpt-4o-mini-2024-07-18string
gpt-4.5-previewstring
gpt-4.5-preview-2025-02-27string
gpt-4-turbostring
gpt-4-turbo-2024-04-09string
gpt-4-0125-previewstring
gpt-4-turbo-previewstring
gpt-4-1106-previewstring
gpt-4-vision-previewstring
gpt-4string
gpt-4-0314string
gpt-4-0613string
gpt-4-32kstring
gpt-4-32k-0314string
gpt-4-32k-0613string
gpt-3.5-turbostring
gpt-3.5-turbo-16kstring
gpt-3.5-turbo-0613string
gpt-3.5-turbo-1106string
gpt-3.5-turbo-0125string
gpt-3.5-turbo-16k-0613string
instructionsstring or null
Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis.toolsarray or null
Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis.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
file_searchobject
Overrides for the file search tool.max_num_resultsinteger
The maximum number of results the file search tool should output. The default is 20 for
gpt-4*models and 5 forgpt-3.5-turbo. This number should be between 1 and 50 inclusive.Note that the file search tool may output fewer than
max_num_resultsresults. See the file search tool documentation for more information.ranking_optionsobject
The ranking options for the file search. If not specified, the file search tool will use the
autoranker and a score_threshold of 0.See the file search tool documentation for more information.
rankerstring
The ranker to use for the file search. If not specified will use the
autoranker.autostring
default_2024_08_21string
score_thresholdnumberRequired
The score threshold for the file search. All values must be a floating point number between 0 and 1.
Function toolobject
typestringRequired
The type of tool being defined:
functionfunctionstring
functionobjectRequired
descriptionstring
A description of what the function does, used by the model to choose when and how to call the function.namestringRequired
The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.parametersobject
The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
Omitting
parametersdefines a function with an empty parameter list.strictboolean or nullDefaults: false
Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the
parametersfield. Only a subset of JSON Schema is supported whenstrictistrue. Learn more about Structured Outputs in the .
tool_resourcesobject or null
A set of resources that are used by the assistant's tools. 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
vector_store_idsarray
The ID of the vector store attached to this assistant. There can be a maximum of 1 vector store attached to the assistant.
itemsstring
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.temperaturenumber or nullDefaults: 1
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.top_pnumber or nullDefaults: 1
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.streamboolean or null
If
true, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with adata: [DONE]message.max_prompt_tokensinteger or null
The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status
incomplete. Seeincomplete_detailsfor more info.max_completion_tokensinteger or null
The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status
incomplete. Seeincomplete_detailsfor more info.truncation_strategyobject
tool_choiceobject
parallel_tool_callsbooleanDefaults: true
Whether to enable parallel function calling during tool use.
response_formatstring or object
Specifies the format that the model must output. Compatible with GPT-4o, GPT-4 Turbo, and all GPT-3.5 Turbo models since
gpt-3.5-turbo-1106.Setting to
enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.Setting to
enables JSON mode, which ensures the message the model generates is valid JSON.Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if
finish_reason="length", which indicates the generation exceededmax_tokensor the conversation exceeded the max context length.response_formatstring
autois the default valueautostring
Textobject
Default response format. Used to generate text responses.typestringRequired
The type of response format being defined. Always
text.textstring
JSON objectobject
JSON object response format. An older method of generating JSON responses. Using
json_schemais recommended for models that support it. Note that the model will not generate JSON without a system or user message instructing it to do so.typestringRequired
The type of response format being defined. Always
json_object.json_objectstring
JSON schemaobject
JSON Schema response format. Used to generate structured JSON responses. Learn more about Structured Outputs.
typestringRequired
The type of response format being defined. Always
json_schema.json_schemastring
json_schemaobjectRequired
Structured Outputs configuration options, including a JSON Schema.descriptionstring
A description of what the response format is for, used by the model to determine how to respond in the format.namestringRequired
The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.schemaobject
The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas here.
strictboolean or nullDefaults: false
Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the
schemafield. Only a subset of JSON Schema is supported whenstrictistrue. To learn more, read the Structured Outputs guide.
Response
A run object.
1 curl https://api.openai.com/v1/threads/runs \2 -H "Authorization: Bearer $OPENAI_API_KEY" \3 -H "Content-Type: application/json" \4 -H "OpenAI-Beta: assistants=v2" \5 -d '{6 "assistant_id": "asst_abc123",7 "thread": {8 "messages": [9 {"role": "user", "content": "Explain deep learning to a 5 year old."}10 ]11 }12 }'
1 {2 "id": "run_abc123",3 "object": "thread.run",4 "created_at": 1699076792,5 "assistant_id": "asst_abc123",6 "thread_id": "thread_abc123",7 "status": "queued",8 "started_at": null,9 "expires_at": 1699077392,10 "cancelled_at": null,11 "failed_at": null,12 "completed_at": null,13 "required_action": null,14 "last_error": null,15 "model": "gpt-4o",16 "instructions": "You are a helpful assistant.",17 "tools": [],18 "tool_resources": {},19 "metadata": {},20 "temperature": 1.0,21 "top_p": 1.0,22 "max_completion_tokens": null,23 "max_prompt_tokens": null,24 "truncation_strategy": {25 "type": "auto",26 "last_messages": null27 },28 "incomplete_details": null,29 "usage": null,30 "response_format": "auto",31 "tool_choice": "auto",32 "parallel_tool_calls": true33 }