NAME
OpenAPI::Client::OpenAI::Path::threads-runs - Documentation for the /threads/runs path.
OPERATIONS
POST /threads/runs
createThreadAndRun
$client->create_thread_and_run({
body => { ... },
});
Create a thread and run it in one request.
Request body
Content-Type: application/json
Example:
{
"assistant_id" : "asst_abc123",
"cancelled_at" : null,
"completed_at" : null,
"created_at" : 1699076792,
"expires_at" : 1699077392,
"failed_at" : null,
"id" : "run_abc123",
"incomplete_details" : null,
"instructions" : "You are a helpful assistant.",
"last_error" : null,
"max_completion_tokens" : null,
"max_prompt_tokens" : null,
"metadata" : {},
"model" : "gpt-4o",
"object" : "thread.run",
"parallel_tool_calls" : true,
"required_action" : null,
"response_format" : "auto",
"started_at" : null,
"status" : "queued",
"temperature" : 1,
"thread_id" : "thread_abc123",
"tool_choice" : "auto",
"tool_resources" : {},
"tools" : [],
"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" : null,
"created_at" : 1699076792,
"expires_at" : 1699077392,
"failed_at" : null,
"id" : "run_abc123",
"incomplete_details" : null,
"instructions" : "You are a helpful assistant.",
"last_error" : null,
"max_completion_tokens" : null,
"max_prompt_tokens" : null,
"metadata" : {},
"model" : "gpt-4o",
"object" : "thread.run",
"parallel_tool_calls" : true,
"required_action" : null,
"response_format" : "auto",
"started_at" : null,
"status" : "queued",
"temperature" : 1,
"thread_id" : "thread_abc123",
"tool_choice" : "auto",
"tool_resources" : {},
"tools" : [],
"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
CreateThreadAndRunRequest
Properties:
assistant_id(string, required) - The ID of the assistant to use to execute this run.instructions(string) - Override the default system message 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 statusincomplete. Seeincomplete_detailsfor 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 statusincomplete. Seeincomplete_detailsfor 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.
response_format(AssistantsApiResponseFormatOption)See "AssistantsApiResponseFormatOption" below for shape.
stream(boolean) - Iftrue, 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.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
thread(CreateThreadRequest)See "CreateThreadRequest" below for shape.
tool_choice(allOf)tool_resources(object) - A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, thecode_interpretertool requires a list of file IDs, while thefile_searchtool requires a list of vector store IDs.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)
CreateThreadRequest
Properties:
messages(array of CreateMessageRequest) - A list of messages to start the thread with.metadata(Metadata)See "Metadata" below for shape.
tool_resources(anyOf)
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.
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 benullif 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 benullif 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 alwaysthread.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 benullif 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 eitherqueued,in_progress,requires_action,cancelling,cancelled,failed,completed,incomplete, orexpired.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 alwaysfunction.Allowed values: function
SEE ALSO
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.