Body
Required
-
The ID of the assistant to use to execute this run.
-
Options to create a new thread. If no thread is provided when running a request, an empty thread will be created.
Additional properties are NOT allowed.
model
string | null 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.
-
Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis.
-
Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis.
Not more than
20
elements. -
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_interpreter
tool requires a list of file IDs, while thefile_search
tool requires a list of vector store IDs. -
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.
-
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.
Minimum value is
0
, maximum value is2
. Default value is1
. -
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.
Minimum value is
0
, maximum value is1
. Default value is1
. -
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. -
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_details
for more info.Minimum value is
256
. -
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_details
for more info.Minimum value is
256
. -
Controls for how a thread will be truncated prior to the run. Use this to control the intial context window of the run.
tool_choice
string | object -
Whether to enable parallel function calling during tool use.
Default value is
true
. response_format
string | null | 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
{ "type": "json_schema", "json_schema": {...} }
enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.Setting to
{ "type": "json_object" }
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_tokens
or the conversation exceeded the max context length.
curl \
--request POST 'https://api.openai.com/v1/threads/runs' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"assistant_id":"string","thread":{"messages":[{"role":"user","content":"string","attachments":[{"file_id":"string","tools":[{"type":"code_interpreter"}]}],"metadata":{"additionalProperty1":"string","additionalProperty2":"string"}}],"tool_resources":{"code_interpreter":{"file_ids":[]},"file_search":{"vector_store_ids":["string"],"vector_stores":[{"file_ids":["string"],"chunking_strategy":{"type":"auto"},"metadata":{"additionalProperty1":"string","additionalProperty2":"string"}}]}},"metadata":{"additionalProperty1":"string","additionalProperty2":"string"}},"model":"gpt-4o","instructions":"string","tools":[{"type":"code_interpreter"}],"tool_resources":{"code_interpreter":{"file_ids":[]},"file_search":{"vector_store_ids":["string"]}},"metadata":{"additionalProperty1":"string","additionalProperty2":"string"},"temperature":1,"top_p":1,"stream":true,"max_prompt_tokens":42,"max_completion_tokens":42,"truncation_strategy":{"type":"auto","last_messages":42},"tool_choice":"none","parallel_tool_calls":true,"response_format":"auto"}'
{
"assistant_id": "string",
"thread": {
"messages": [
{
"role": "user",
"content": "string",
"attachments": [
{
"file_id": "string",
"tools": [
{
"type": "code_interpreter"
}
]
}
],
"metadata": {
"additionalProperty1": "string",
"additionalProperty2": "string"
}
}
],
"tool_resources": {
"code_interpreter": {
"file_ids": []
},
"file_search": {
"vector_store_ids": [
"string"
],
"vector_stores": [
{
"file_ids": [
"string"
],
"chunking_strategy": {
"type": "auto"
},
"metadata": {
"additionalProperty1": "string",
"additionalProperty2": "string"
}
}
]
}
},
"metadata": {
"additionalProperty1": "string",
"additionalProperty2": "string"
}
},
"model": "gpt-4o",
"instructions": "string",
"tools": [
{
"type": "code_interpreter"
}
],
"tool_resources": {
"code_interpreter": {
"file_ids": []
},
"file_search": {
"vector_store_ids": [
"string"
]
}
},
"metadata": {
"additionalProperty1": "string",
"additionalProperty2": "string"
},
"temperature": 1,
"top_p": 1,
"stream": true,
"max_prompt_tokens": 42,
"max_completion_tokens": 42,
"truncation_strategy": {
"type": "auto",
"last_messages": 42
},
"tool_choice": "none",
"parallel_tool_calls": true,
"response_format": "auto"
}
{
"id": "string",
"object": "thread.run",
"created_at": 42,
"thread_id": "string",
"assistant_id": "string",
"status": "queued",
"required_action": {
"type": "submit_tool_outputs",
"submit_tool_outputs": {
"tool_calls": [
{
"id": "string",
"type": "function",
"function": {
"name": "string",
"arguments": "string"
}
}
]
}
},
"last_error": {
"code": "server_error",
"message": "string"
},
"expires_at": 42,
"started_at": 42,
"cancelled_at": 42,
"failed_at": 42,
"completed_at": 42,
"incomplete_details": {
"reason": "max_completion_tokens"
},
"model": "string",
"instructions": "string",
"tools": [
{
"type": "code_interpreter"
}
],
"metadata": {
"additionalProperty1": "string",
"additionalProperty2": "string"
},
"usage": {
"completion_tokens": 42,
"prompt_tokens": 42,
"total_tokens": 42
},
"temperature": 42.0,
"top_p": 42.0,
"max_prompt_tokens": 42,
"max_completion_tokens": 42,
"truncation_strategy": {
"type": "auto",
"last_messages": 42
},
"tool_choice": "none",
"parallel_tool_calls": true,
"response_format": "auto"
}