---
title: "Create a thread and run it in one request."
method: POST
path: "/threads/runs"
tags: ["Assistants"]
---

# Create a thread and run it in one request.

`POST /threads/runs`

## Request body

- CreateThreadAndRunRequest
  - `assistant_id` string, required — The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run.
  - `thread` CreateThreadRequest — Options to create a new thread. If no thread is provided when running a request, an empty thread will be created.
    - `messages` CreateMessageRequest[] — A list of [messages](/docs/api-reference/messages) to start the thread with.
      - `role` 'user' | 'assistant', 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.
      - `content` union, required
        - string — The text contents of the message.
        - union[] — An array of content parts with a defined type, each can be of type `text` or images can be passed with `image_url` or `image_file`. Image types are only supported on [Vision-compatible models](/docs/models).
          - union
            - MessageContentImageFileObject — References an image [File](/docs/api-reference/files) in the content of a message.
              - …
            - MessageContentImageUrlObject — References an image URL in the content of a message.
              - …
            - MessageRequestContentTextObject — The text content that is part of a message.
              - …
      - `attachments` object[], nullable — A list of files attached to the message, and the tools they should be added to.
        - `file_id` string — The ID of the file to attach to the message.
        - `tools` union[] — The tools to add this file to.
          - union
            - AssistantToolsCode
              - …
            - AssistantToolsFileSearchTypeOnly
              - …
      - `metadata` Metadata, nullable — 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, nullable — 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.
      - `code_interpreter` object
        - `file_ids` string[] — A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool.
      - `file_search` union
        - object
          - `vector_store_ids` string[], required — The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread.
          - `vector_stores` object[] — A helper to create a [vector store](/docs/api-reference/vector-stores/object) with file_ids and attach it to this thread. There can be a maximum of 1 vector store attached to the thread.
            - `file_ids` string[] — A list of [file](/docs/api-reference/files) IDs to add to the vector store. For vector stores created before Nov 2025, there can be a maximum of 10,000 files in a vector store. For vector stores created starting in Nov 2025, the limit is 100,000,000 files.
            - `chunking_strategy` union — The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy.
              - …
            - `metadata` Metadata, nullable — 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.
        - object
          - `vector_store_ids` string[] — The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread.
          - `vector_stores` object[], required — A helper to create a [vector store](/docs/api-reference/vector-stores/object) with file_ids and attach it to this thread. There can be a maximum of 1 vector store attached to the thread.
            - `file_ids` string[] — A list of [file](/docs/api-reference/files) IDs to add to the vector store. For vector stores created before Nov 2025, there can be a maximum of 10,000 files in a vector store. For vector stores created starting in Nov 2025, the limit is 100,000,000 files.
            - `chunking_strategy` union — The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy.
              - …
            - `metadata` Metadata, nullable — 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.
    - `metadata` Metadata, nullable — 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.
  - `model` union — The ID of the [Model](/docs/api-reference/models) 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.
    - string
    - 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-5-2025-08-07' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano-2025-08-07' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-11-20' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-05-13' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613'
  - `instructions` string, nullable — Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis.
  - `tools` union[], nullable — Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis.
    - union
      - AssistantToolsCode
        - `type` 'code_interpreter', required — The type of tool being defined: `code_interpreter`
      - AssistantToolsFileSearch
        - `type` 'file_search', required — The type of tool being defined: `file_search`
        - `file_search` object — Overrides for the file search tool.
          - `max_num_results` integer — The maximum number of results the file search tool should output. The default is 20 for `gpt-4*` models and 5 for `gpt-3.5-turbo`. This number should be between 1 and 50 inclusive. Note that the file search tool may output fewer than `max_num_results` results. See the [file search tool documentation](/docs/assistants/tools/file-search#customizing-file-search-settings) for more information.
          - `ranking_options` FileSearchRankingOptions — The ranking options for the file search. If not specified, the file search tool will use the `auto` ranker and a score_threshold of 0. See the [file search tool documentation](/docs/assistants/tools/file-search#customizing-file-search-settings) for more information.
            - `ranker` 'auto' | 'default_2024_08_21' — The ranker to use for the file search. If not specified will use the `auto` ranker.
            - `score_threshold` number, required — The score threshold for the file search. All values must be a floating point number between 0 and 1.
      - AssistantToolsFunction
        - `type` 'function', required — The type of tool being defined: `function`
        - `function` FunctionObject, required
          - `description` string — A description of what the function does, used by the model to choose when and how to call the function.
          - `name` string, required — 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.
          - `parameters` FunctionParameters — The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format. Omitting `parameters` defines a function with an empty parameter list.
          - `strict` boolean, nullable — 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 `parameters` field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn more about Structured Outputs in the [function calling guide](/docs/guides/function-calling).
  - `tool_resources` object, nullable — 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 the `file_search` tool requires a list of vector store IDs.
    - `code_interpreter` object
      - `file_ids` string[] — A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool.
    - `file_search` object
      - `vector_store_ids` string[] — The ID of the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant.
  - `metadata` Metadata, nullable — 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.
  - `temperature` number, nullable — 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_p` number, nullable — 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.
  - `stream` boolean, nullable — 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 a `data: [DONE]` message.
  - `max_prompt_tokens` integer, nullable — 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`. See `incomplete_details` for more info.
  - `max_completion_tokens` integer, nullable — 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`. See `incomplete_details` for more info.
  - `truncation_strategy` object, nullable — Controls for how a thread will be truncated prior to the run. Use this to control the initial context window of the run.
    - `type` 'auto' | 'last_messages', required — The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the n most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens`.
    - `last_messages` integer, nullable — The number of most recent messages from the thread when constructing the context for the run.
  - `tool_choice` union
    - 'none' | 'auto' | 'required', nullable — `none` means the model will not call any tools and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools before responding to the user.
    - object, nullable — Specifies a tool the model should use. Use to force the model to call a specific tool.
      - `type` 'function' | 'code_interpreter' | 'file_search', required — The type of the tool. If type is `function`, the function name must be set
      - `function` object
        - `name` string, required — The name of the function to call.
  - `parallel_tool_calls` boolean — Whether to enable [parallel function calling](/docs/guides/function-calling#configuring-parallel-function-calling) during tool use.
  - `response_format` union — Specifies the format that the model must output. Compatible with [GPT-4o](/docs/models#gpt-4o), [GPT-4 Turbo](/docs/models#gpt-4-turbo-and-gpt-4), 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](/docs/guides/structured-outputs). 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 exceeded `max_tokens` or the conversation exceeded the max context length.
    - 'auto' — `auto` is the default value
    - ResponseFormatText — Default response format. Used to generate text responses.
      - `type` 'text', required — The type of response format being defined. Always `text`.
    - ResponseFormatJsonObject — JSON object response format. An older method of generating JSON responses. Using `json_schema` is 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.
      - `type` 'json_object', required — The type of response format being defined. Always `json_object`.
    - ResponseFormatJsonSchema — JSON Schema response format. Used to generate structured JSON responses. Learn more about [Structured Outputs](/docs/guides/structured-outputs).
      - `type` 'json_schema', required — The type of response format being defined. Always `json_schema`.
      - `json_schema` object, required — Structured Outputs configuration options, including a JSON Schema.
        - `description` string — A description of what the response format is for, used by the model to determine how to respond in the format.
        - `name` string, required — 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.
        - `schema` ResponseFormatJsonSchemaSchema — The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas [here](https://json-schema.org/).
        - `strict` boolean, nullable — 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 `schema` field. Only a subset of JSON Schema is supported when `strict` is `true`. To learn more, read the [Structured Outputs guide](/docs/guides/structured-outputs).

## Response `200`

OK

- RunObject — Represents an execution run on a [thread](/docs/api-reference/threads).
  - `id` string, required — The identifier, which can be referenced in API endpoints.
  - `object` 'thread.run', required — The object type, which is always `thread.run`.
  - `created_at` integer, required — The Unix timestamp (in seconds) for when the run was created.
  - `thread_id` string, required — The ID of the [thread](/docs/api-reference/threads) that was executed on as a part of this run.
  - `assistant_id` string, required — The ID of the [assistant](/docs/api-reference/assistants) used for execution of this run.
  - `status` 'queued' | 'in_progress' | 'requires_action' | 'cancelling' | 'cancelled' | 'failed' | 'completed' | 'incomplete' | 'expired', required — The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, `incomplete`, or `expired`.
  - `required_action` object, nullable, required — Details on the action required to continue the run. Will be `null` if no action is required.
    - `type` 'submit_tool_outputs', required — For now, this is always `submit_tool_outputs`.
    - `submit_tool_outputs` object, required — Details on the tool outputs needed for this run to continue.
      - `tool_calls` RunToolCallObject[], required — A list of the relevant tool calls.
        - `id` string, required — The ID of the tool call. This ID must be referenced when you submit the tool outputs in using the [Submit tool outputs to run](/docs/api-reference/runs/submitToolOutputs) endpoint.
        - `type` 'function', required — The type of tool call the output is required for. For now, this is always `function`.
        - `function` object, required — The function definition.
          - `name` string, required — The name of the function.
          - `arguments` string, required — The arguments that the model expects you to pass to the function.
  - `last_error` object, nullable, required — The last error associated with this run. Will be `null` if there are no errors.
    - `code` 'server_error' | 'rate_limit_exceeded' | 'invalid_prompt', required — One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt`.
    - `message` string, required — A human-readable description of the error.
  - `expires_at` integer, nullable, required — The Unix timestamp (in seconds) for when the run will expire.
  - `started_at` integer, nullable, required — The Unix timestamp (in seconds) for when the run was started.
  - `cancelled_at` integer, nullable, required — The Unix timestamp (in seconds) for when the run was cancelled.
  - `failed_at` integer, nullable, required — The Unix timestamp (in seconds) for when the run failed.
  - `completed_at` integer, nullable, required — The Unix timestamp (in seconds) for when the run was completed.
  - `incomplete_details` object, nullable, required — Details on why the run is incomplete. Will be `null` if the run is not incomplete.
    - `reason` 'max_completion_tokens' | 'max_prompt_tokens' — The reason why the run is incomplete. This will point to which specific token limit was reached over the course of the run.
  - `model` string, required — The model that the [assistant](/docs/api-reference/assistants) used for this run.
  - `instructions` string, required — The instructions that the [assistant](/docs/api-reference/assistants) used for this run.
  - `tools` union[], required — The list of tools that the [assistant](/docs/api-reference/assistants) used for this run.
    - union
      - AssistantToolsCode
        - `type` 'code_interpreter', required — The type of tool being defined: `code_interpreter`
      - AssistantToolsFileSearch
        - `type` 'file_search', required — The type of tool being defined: `file_search`
        - `file_search` object — Overrides for the file search tool.
          - `max_num_results` integer — The maximum number of results the file search tool should output. The default is 20 for `gpt-4*` models and 5 for `gpt-3.5-turbo`. This number should be between 1 and 50 inclusive. Note that the file search tool may output fewer than `max_num_results` results. See the [file search tool documentation](/docs/assistants/tools/file-search#customizing-file-search-settings) for more information.
          - `ranking_options` FileSearchRankingOptions — The ranking options for the file search. If not specified, the file search tool will use the `auto` ranker and a score_threshold of 0. See the [file search tool documentation](/docs/assistants/tools/file-search#customizing-file-search-settings) for more information.
            - `ranker` 'auto' | 'default_2024_08_21' — The ranker to use for the file search. If not specified will use the `auto` ranker.
            - `score_threshold` number, required — The score threshold for the file search. All values must be a floating point number between 0 and 1.
      - AssistantToolsFunction
        - `type` 'function', required — The type of tool being defined: `function`
        - `function` FunctionObject, required
          - `description` string — A description of what the function does, used by the model to choose when and how to call the function.
          - `name` string, required — 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.
          - `parameters` FunctionParameters — The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format. Omitting `parameters` defines a function with an empty parameter list.
          - `strict` boolean, nullable — 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 `parameters` field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn more about Structured Outputs in the [function calling guide](/docs/guides/function-calling).
  - `metadata` Metadata, nullable, 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, 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.
  - `usage` RunCompletionUsage, nullable, required — Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.).
    - `completion_tokens` integer, required — Number of completion tokens used over the course of the run.
    - `prompt_tokens` integer, required — Number of prompt tokens used over the course of the run.
    - `total_tokens` integer, required — Total number of tokens used (prompt + completion).
  - `temperature` number, nullable — The sampling temperature used for this run. If not set, defaults to 1.
  - `top_p` number, nullable — The nucleus sampling value used for this run. If not set, defaults to 1.
  - `max_prompt_tokens` integer, nullable, required — The maximum number of prompt tokens specified to have been used over the course of the run.
  - `max_completion_tokens` integer, nullable, required — The maximum number of completion tokens specified to have been used over the course of the run.
  - `truncation_strategy` object, nullable, required — Controls for how a thread will be truncated prior to the run. Use this to control the initial context window of the run.
    - `type` 'auto' | 'last_messages', required — The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the n most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens`.
    - `last_messages` integer, nullable — The number of most recent messages from the thread when constructing the context for the run.
  - `tool_choice` union, required
    - 'none' | 'auto' | 'required', nullable — `none` means the model will not call any tools and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools before responding to the user.
    - object, nullable — Specifies a tool the model should use. Use to force the model to call a specific tool.
      - `type` 'function' | 'code_interpreter' | 'file_search', required — The type of the tool. If type is `function`, the function name must be set
      - `function` object
        - `name` string, required — The name of the function to call.
  - `parallel_tool_calls` boolean, required — Whether to enable [parallel function calling](/docs/guides/function-calling#configuring-parallel-function-calling) during tool use.
  - `response_format` union, required — Specifies the format that the model must output. Compatible with [GPT-4o](/docs/models#gpt-4o), [GPT-4 Turbo](/docs/models#gpt-4-turbo-and-gpt-4), 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](/docs/guides/structured-outputs). 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 exceeded `max_tokens` or the conversation exceeded the max context length.
    - 'auto' — `auto` is the default value
    - ResponseFormatText — Default response format. Used to generate text responses.
      - `type` 'text', required — The type of response format being defined. Always `text`.
    - ResponseFormatJsonObject — JSON object response format. An older method of generating JSON responses. Using `json_schema` is 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.
      - `type` 'json_object', required — The type of response format being defined. Always `json_object`.
    - ResponseFormatJsonSchema — JSON Schema response format. Used to generate structured JSON responses. Learn more about [Structured Outputs](/docs/guides/structured-outputs).
      - `type` 'json_schema', required — The type of response format being defined. Always `json_schema`.
      - `json_schema` object, required — Structured Outputs configuration options, including a JSON Schema.
        - `description` string — A description of what the response format is for, used by the model to determine how to respond in the format.
        - `name` string, required — 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.
        - `schema` ResponseFormatJsonSchemaSchema — The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas [here](https://json-schema.org/).
        - `strict` boolean, nullable — 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 `schema` field. Only a subset of JSON Schema is supported when `strict` is `true`. To learn more, read the [Structured Outputs guide](/docs/guides/structured-outputs).

---

[API](https://skmtc.net/openai/apis/openai-api-3.md) · [All operations](https://skmtc.net/openai/apis/openai-api-3/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/openai/openai-api-3/versions/74cbcf73838f/schema)
