NAME

OpenAPI::Client::OpenAI::Path::threads-thread_id-runs - Documentation for the /threads/{thread_id}/runs path.

OPERATIONS

GET /threads/{thread_id}/runs

listRuns

$client->list_runs({
    body => { ... },
});

Returns a list of runs belonging to a thread.

Path/query parameters

  • thread_id (in path, required, string) - The ID of the thread the run belongs to.

  • limit (in query, optional, integer) - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

    Default: 20

  • order (in query, optional, string) - Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

    Allowed values: asc, desc

    Default: desc

  • after (in query, optional, string) - A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before (in query, optional, string) - A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

Responses

200 - OK

Content-Type: application/json

Example:

{
   "data" : [
      "{\n  \"id\": \"run_abc123\",\n  \"object\": \"thread.run\",\n  \"created_at\": 1698107661,\n  \"assistant_id\": \"asst_abc123\",\n  \"thread_id\": \"thread_abc123\",\n  \"status\": \"completed\",\n  \"started_at\": 1699073476,\n  \"expires_at\": null,\n  \"cancelled_at\": null,\n  \"failed_at\": null,\n  \"completed_at\": 1699073498,\n  \"last_error\": null,\n  \"model\": \"gpt-4o\",\n  \"instructions\": null,\n  \"tools\": [{\"type\": \"file_search\"}, {\"type\": \"code_interpreter\"}],\n  \"metadata\": {},\n  \"incomplete_details\": null,\n  \"usage\": {\n    \"prompt_tokens\": 123,\n    \"completion_tokens\": 456,\n    \"total_tokens\": 579\n  },\n  \"temperature\": 1.0,\n  \"top_p\": 1.0,\n  \"max_prompt_tokens\": 1000,\n  \"max_completion_tokens\": 1000,\n  \"truncation_strategy\": {\n    \"type\": \"auto\",\n    \"last_messages\": null\n  },\n  \"response_format\": \"auto\",\n  \"tool_choice\": \"auto\",\n  \"parallel_tool_calls\": true\n}\n"
   ],
   "first_id" : "run_abc123",
   "has_more" : false,
   "last_id" : "run_abc456",
   "object" : "list"
}

POST /threads/{thread_id}/runs

createRun

$client->create_run({
    body => { ... },
});

Create a run.

Path/query parameters

  • thread_id (in path, required, string) - The ID of the thread to run.

  • include[] (in query, optional, 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

Content-Type: application/json

Example:

{
   "assistant_id" : "asst_abc123",
   "cancelled_at" : null,
   "completed_at" : 1699063291,
   "created_at" : 1699063290,
   "expires_at" : null,
   "failed_at" : null,
   "id" : "run_abc123",
   "incomplete_details" : null,
   "instructions" : null,
   "last_error" : null,
   "max_completion_tokens" : 1000,
   "max_prompt_tokens" : 1000,
   "metadata" : {},
   "model" : "gpt-4o",
   "object" : "thread.run",
   "parallel_tool_calls" : true,
   "response_format" : "auto",
   "started_at" : 1699063290,
   "status" : "queued",
   "temperature" : 1,
   "thread_id" : "thread_abc123",
   "tool_choice" : "auto",
   "tools" : [
      {
         "type" : "code_interpreter"
      }
   ],
   "top_p" : 1,
   "truncation_strategy" : {
      "last_messages" : null,
      "type" : "auto"
   },
   "usage" : null
}

Responses

200 - OK

Content-Type: application/json

Example:

{
   "assistant_id" : "asst_abc123",
   "cancelled_at" : null,
   "completed_at" : 1699063291,
   "created_at" : 1699063290,
   "expires_at" : null,
   "failed_at" : null,
   "id" : "run_abc123",
   "incomplete_details" : null,
   "instructions" : null,
   "last_error" : null,
   "max_completion_tokens" : 1000,
   "max_prompt_tokens" : 1000,
   "metadata" : {},
   "model" : "gpt-4o",
   "object" : "thread.run",
   "parallel_tool_calls" : true,
   "response_format" : "auto",
   "started_at" : 1699063290,
   "status" : "queued",
   "temperature" : 1,
   "thread_id" : "thread_abc123",
   "tool_choice" : "auto",
   "tools" : [
      {
         "type" : "code_interpreter"
      }
   ],
   "top_p" : 1,
   "truncation_strategy" : {
      "last_messages" : null,
      "type" : "auto"
   },
   "usage" : null
}

SCHEMAS

AssistantsApiResponseFormatOption

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

CreateMessageRequest

Properties:

  • attachments (anyOf)

  • content (oneOf, required)

  • metadata (Metadata)

    See "Metadata" below for shape.

  • 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.

    Allowed values: user, assistant

CreateRunRequest

Properties:

  • additional_instructions (string) - 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 of CreateMessageRequest) - Adds additional messages to the thread before creating the run.

  • assistant_id (string, required) - The ID of the assistant to use to execute this run.

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

  • max_completion_tokens (integer) - 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.

  • max_prompt_tokens (integer) - 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.

  • metadata (Metadata)

    See "Metadata" below for shape.

  • model (anyOf) - 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.

  • parallel_tool_calls (ParallelToolCalls)

    See "ParallelToolCalls" below for shape.

  • reasoning_effort (ReasoningEffort)

    See "ReasoningEffort" below for shape.

  • response_format (AssistantsApiResponseFormatOption)

    See "AssistantsApiResponseFormatOption" below for shape.

  • stream (boolean) - 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.

  • temperature (number) - 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.

    Default: 1

  • tool_choice (allOf)

  • tools (array of object) - Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis.

  • top_p (number) - 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.

    Default: 1

  • truncation_strategy (allOf)

ListRunsResponse

Properties:

  • data (array of RunObject, required)

  • first_id (string, required)

  • has_more (boolean, required)

  • last_id (string, required)

  • object (string, required)

Metadata

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.

ParallelToolCalls

Whether to enable parallel function calling during tool use.

ReasoningEffort

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

- gpt-5.1 defaults to none , which does not perform reasoning. The supported reasoning values for gpt-5.1 are none , low , medium , and high . Tool calls are supported for all reasoning values in gpt-5.1. - All models before gpt-5.1 default to medium reasoning effort, and do not support none . - The gpt-5-pro model defaults to (and only supports) high reasoning effort. - xhigh is supported for all models after gpt-5.1-codex-max .

RunCompletionUsage

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.).

RunObject

Properties:

  • assistant_id (string, required) - The ID of the assistant used for execution of this run.

  • cancelled_at (integer, required) - The Unix timestamp (in seconds) for when the run was cancelled.

  • completed_at (integer, required) - The Unix timestamp (in seconds) for when the run was completed.

  • created_at (integer, required) - The Unix timestamp (in seconds) for when the run was created.

  • expires_at (integer, required) - The Unix timestamp (in seconds) for when the run will expire.

  • failed_at (integer, required) - The Unix timestamp (in seconds) for when the run failed.

  • id (string, required) - The identifier, which can be referenced in API endpoints.

  • incomplete_details (object, required) - Details on why the run is incomplete. Will be null if the run is not incomplete.

  • instructions (string, required) - The instructions that the assistant used for this run.

  • last_error (object, required) - The last error associated with this run. Will be null if there are no errors.

  • max_completion_tokens (integer, required) - The maximum number of completion tokens specified to have been used over the course of the run.

  • max_prompt_tokens (integer, required) - The maximum number of prompt tokens specified to have been used over the course of the run.

  • metadata (Metadata, required)

    See "Metadata" below for shape.

  • model (string, required) - The model that the assistant used for this run.

  • object (string, required) - The object type, which is always thread.run .

    Allowed values: thread.run

  • parallel_tool_calls (ParallelToolCalls, required)

    See "ParallelToolCalls" below for shape.

  • required_action (object, required) - Details on the action required to continue the run. Will be null if no action is required.

  • response_format (AssistantsApiResponseFormatOption, required)

    See "AssistantsApiResponseFormatOption" below for shape.

  • started_at (integer, required) - The Unix timestamp (in seconds) for when the run was started.

  • status (string, required) - The status of the run, which can be either queued , in_progress , requires_action , cancelling , cancelled , failed , completed , incomplete , or expired .

    Allowed values: queued, in_progress, requires_action, cancelling, cancelled, failed, completed, incomplete, expired

  • temperature (number) - The sampling temperature used for this run. If not set, defaults to 1.

  • thread_id (string, required) - The ID of the thread that was executed on as a part of this run.

  • tool_choice (allOf, required)

  • tools (array of object, required) - The list of tools that the assistant used for this run.

    Default: []

  • top_p (number) - The nucleus sampling value used for this run. If not set, defaults to 1.

  • truncation_strategy (allOf, required)

  • usage (RunCompletionUsage, required)

    See "RunCompletionUsage" below for shape.

RunToolCallObject

Properties:

  • function (object, required) - The function definition.

  • 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 endpoint.

  • type (string, required) - The type of tool call the output is required for. For now, this is always function .

    Allowed values: function

SEE ALSO

OpenAPI::Client::OpenAI::Path

COPYRIGHT AND LICENSE

Copyright (C) 2023-2026 by Nelson Ferraz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.0 or, at your option, any later version of Perl 5 you may have available.