Create run

POSThttps:/api.openai.com/v1/threads/{thread_id}/runs

Create a run.

Path parameters

  • thread_id
    string
    Required
    The ID of the thread to run.

Query parameters

  • include[]
    array

    A list of additional fields to include in the response. Currently the only supported value is step_details.tool_calls[*].file_search.results[*].content to fetch the file search result content.

    See the file search tool documentation for more information.

Request body

  • assistant_id
    string
    Required

    The ID of the assistant to use to execute this run.

  • model
    string

    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.

    • model
      string
    • model
      string
      • gpt-4.1
        string
      • gpt-4.1-mini
        string
      • gpt-4.1-nano
        string
      • gpt-4.1-2025-04-14
        string
      • gpt-4.1-mini-2025-04-14
        string
      • gpt-4.1-nano-2025-04-14
        string
      • o3-mini
        string
      • o3-mini-2025-01-31
        string
      • o1
        string
      • o1-2024-12-17
        string
      • gpt-4o
        string
      • gpt-4o-2024-11-20
        string
      • gpt-4o-2024-08-06
        string
      • gpt-4o-2024-05-13
        string
      • gpt-4o-mini
        string
      • gpt-4o-mini-2024-07-18
        string
      • gpt-4.5-preview
        string
      • gpt-4.5-preview-2025-02-27
        string
      • gpt-4-turbo
        string
      • gpt-4-turbo-2024-04-09
        string
      • gpt-4-0125-preview
        string
      • gpt-4-turbo-preview
        string
      • gpt-4-1106-preview
        string
      • gpt-4-vision-preview
        string
      • gpt-4
        string
      • gpt-4-0314
        string
      • gpt-4-0613
        string
      • gpt-4-32k
        string
      • gpt-4-32k-0314
        string
      • gpt-4-32k-0613
        string
      • gpt-3.5-turbo
        string
      • gpt-3.5-turbo-16k
        string
      • gpt-3.5-turbo-0613
        string
      • gpt-3.5-turbo-1106
        string
      • gpt-3.5-turbo-0125
        string
      • gpt-3.5-turbo-16k-0613
        string
  • reasoning_effort
    string or null
    Defaults: medium

    o-series models only

    Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.

    • low
      string
    • medium
      string
    • high
      string
  • instructions
    string or null

    Overrides the instructions of the assistant. This is useful for modifying the behavior on a per-run basis.

  • additional_instructions
    string or null
    Appends additional instructions at the end of the instructions for the run. This is useful for modifying the behavior on a per-run basis without overriding other instructions.
  • additional_messages
    array or null
    Adds additional messages to the thread before creating the run.
    • 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 with image_url or image_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 using high.

                • 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 using high. Default value is auto

                • 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.
  • tools
    array 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 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
      • 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 for more information.

        • ranking_options
          object

          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 for more information.

          • ranker
            string

            The ranker to use for the file search. If not specified will use the auto ranker.

            • auto
              string
            • default_2024_08_21
              string
          • score_threshold
            number
            Required
            The score threshold for the file search. All values must be a floating point number between 0 and 1.
    • Function tool
      object
      • type
        string
        Required

        The type of tool being defined: function

        • function
          string
      • function
        object
        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
          object

          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 parameters defines a function with an empty parameter list.

        • strict
          boolean or null
          Defaults: 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 parameters field. Only a subset of JSON Schema is supported when strict is true. Learn more about Structured Outputs in the .

  • 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.
  • temperature
    number or null
    Defaults: 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_p
    number or null
    Defaults: 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.
  • stream
    boolean 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 a data: [DONE] message.

  • max_prompt_tokens
    integer 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. See incomplete_details for more info.

  • max_completion_tokens
    integer 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. See incomplete_details for more info.

  • truncation_strategy
    object
  • tool_choice
    object
  • parallel_tool_calls
    boolean
    Defaults: true

    Whether to enable parallel function calling during tool use.

  • response_format
    string 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 exceeded max_tokens or the conversation exceeded the max context length.

    • response_format
      string

      auto is the default value

      • auto
        string
    • Text
      object
      Default response format. Used to generate text responses.
      • type
        string
        Required

        The type of response format being defined. Always text.

        • text
          string
    • JSON object
      object

      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
        string
        Required

        The type of response format being defined. Always json_object.

        • json_object
          string
    • JSON schema
      object

      JSON Schema response format. Used to generate structured JSON responses. Learn more about Structured Outputs.

      • type
        string
        Required

        The type of response format being defined. Always json_schema.

        • json_schema
          string
      • 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
          object

          The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas here.

        • strict
          boolean or null
          Defaults: 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 schema field. Only a subset of JSON Schema is supported when strict is true. To learn more, read the Structured Outputs guide.

Response

A run object.

Example request
1
curl https://api.openai.com/v1/threads/thread_abc123/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
}'
Example response
1
{
2
"id": "run_abc123",
3
"object": "thread.run",
4
"created_at": 1699063290,
5
"assistant_id": "asst_abc123",
6
"thread_id": "thread_abc123",
7
"status": "queued",
8
"started_at": 1699063290,
9
"expires_at": null,
10
"cancelled_at": null,
11
"failed_at": null,
12
"completed_at": 1699063291,
13
"last_error": null,
14
"model": "gpt-4o",
15
"instructions": null,
16
"incomplete_details": null,
17
"tools": [
18
{
19
"type": "code_interpreter"
20
}
21
],
22
"metadata": {},
23
"usage": null,
24
"temperature": 1.0,
25
"top_p": 1.0,
26
"max_prompt_tokens": 1000,
27
"max_completion_tokens": 1000,
28
"truncation_strategy": {
29
"type": "auto",
30
"last_messages": null
31
},
32
"response_format": "auto",
33
"tool_choice": "auto",
34
"parallel_tool_calls": true
35
}
Built with