Skip to main content

runs

Creates, updates, deletes, gets or lists a runs resource.

Overview

Nameruns
TypeResource
Idopenai.assistants.runs

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
idstringThe identifier, which can be referenced in API endpoints.
assistant_idstringThe ID of the assistant used for execution of this run.
thread_idstringThe ID of the thread that was executed on as a part of this run.
cancelled_atinteger (unixtime)The Unix timestamp (in seconds) for when the run was cancelled.
completed_atinteger (unixtime)The Unix timestamp (in seconds) for when the run was completed.
created_atinteger (unixtime)The Unix timestamp (in seconds) for when the run was created.
expires_atinteger (unixtime)The Unix timestamp (in seconds) for when the run will expire.
failed_atinteger (unixtime)The Unix timestamp (in seconds) for when the run failed.
incomplete_detailsobjectDetails on why the run is incomplete. Will be null if the run is not incomplete.
instructionsstringThe instructions that the assistant used for this run.
last_errorobjectThe last error associated with this run. Will be null if there are no errors.
max_completion_tokensintegerThe maximum number of completion tokens specified to have been used over the course of the run.
max_prompt_tokensintegerThe maximum number of prompt tokens specified to have been used over the course of the run.
metadataobjectSet 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. (x-oaiTypeLabel: map)
modelstringThe model that the assistant used for this run.
objectstringThe object type, which is always thread.run. (thread.run)
parallel_tool_callsbooleanWhether to enable parallel function calling during tool use.
required_actionobjectDetails on the action required to continue the run. Will be null if no action is required.
response_formatstringSpecifies 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. (auto) (title: Text)
started_atinteger (unixtime)The Unix timestamp (in seconds) for when the run was started.
statusstringThe status of the run, which can be either queued, in_progress, requires_action, cancelling, cancelled, failed, completed, incomplete, or expired. (queued, in_progress, requires_action, cancelling, cancelled, failed, completed, incomplete, expired)
temperaturenumberThe sampling temperature used for this run. If not set, defaults to 1.
tool_choicestringControls which (if any) tool is called by the model. none means the model will not call any tools and instead generates a message. auto is the default value and 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. Specifying a particular tool like {"type": "file_search"} or {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool. (none, auto, required)
toolsarrayThe list of tools that the assistant used for this run.
top_pnumberThe nucleus sampling value used for this run. If not set, defaults to 1.
truncation_strategyobjectControls for how a thread will be truncated prior to the run. Use this to control the initial context window of the run. (title: Thread Truncation Controls)
usageobjectUsage 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.).

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectthread_id, run_idopenai-organization, openai-project
listselectthread_idlimit, order, after, before, openai-organization, openai-project
createinsertthread_id, assistant_idinclude[], openai-organization, openai-project
updateupdatethread_id, run_idopenai-organization, openai-project
cancelexecthread_id, run_idopenai-organization, openai-project
submit_tool_outputsexecthread_id, run_id, tool_outputsopenai-organization, openai-project

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
run_idstringThe ID of the run that requires the tool output submission.
thread_idstringThe ID of the thread to which this run belongs.
afterstringA 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.
beforestringA 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.
include[]arrayA 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.
limitintegerA limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. Automatically applied from a SQL LIMIT clause - SELECT ... LIMIT 10 sends limit=10 on the wire. Setting it explicitly in a WHERE clause is not required.
openai-organizationstringOptionally scope the request to a specific organization (overrides the default associated with the API key). Addressable in SQL as openai_organization.
openai-projectstringOptionally scope the request to a specific project (overrides the default associated with the API key). Addressable in SQL as openai_project.
orderstringSort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

SELECT examples

OK

SELECT
id,
assistant_id,
thread_id,
cancelled_at,
completed_at,
created_at,
expires_at,
failed_at,
incomplete_details,
instructions,
last_error,
max_completion_tokens,
max_prompt_tokens,
metadata,
model,
object,
parallel_tool_calls,
required_action,
response_format,
started_at,
status,
temperature,
tool_choice,
tools,
top_p,
truncation_strategy,
usage
FROM openai.assistants.runs
WHERE thread_id = '{{ thread_id }}' -- required
AND run_id = '{{ run_id }}' -- required
AND "openai-organization" = '{{ openai-organization }}'
AND "openai-project" = '{{ openai-project }}'
;

INSERT examples

No description available.

INSERT INTO openai.assistants.runs (
assistant_id,
model,
reasoning_effort,
instructions,
additional_instructions,
additional_messages,
tools,
metadata,
temperature,
top_p,
stream,
max_prompt_tokens,
max_completion_tokens,
truncation_strategy,
tool_choice,
parallel_tool_calls,
response_format,
thread_id,
include[],
"openai-organization",
"openai-project"
)
SELECT
'{{ assistant_id }}' /* required */,
'{{ model }}',
'{{ reasoning_effort }}',
'{{ instructions }}',
'{{ additional_instructions }}',
'{{ additional_messages }}',
'{{ tools }}',
'{{ metadata }}',
{{ temperature }},
{{ top_p }},
{{ stream }},
{{ max_prompt_tokens }},
{{ max_completion_tokens }},
'{{ truncation_strategy }}',
'{{ tool_choice }}',
{{ parallel_tool_calls }},
'{{ response_format }}',
'{{ thread_id }}',
'{{ include[] }}',
'{{ openai-organization }}',
'{{ openai-project }}'
RETURNING
id,
assistant_id,
thread_id,
cancelled_at,
completed_at,
created_at,
expires_at,
failed_at,
incomplete_details,
instructions,
last_error,
max_completion_tokens,
max_prompt_tokens,
metadata,
model,
object,
parallel_tool_calls,
required_action,
response_format,
started_at,
status,
temperature,
tool_choice,
tools,
top_p,
truncation_strategy,
usage
;

UPDATE examples

No description available.

UPDATE openai.assistants.runs
SET
metadata = '{{ metadata }}'
WHERE
thread_id = '{{ thread_id }}' --required
AND run_id = '{{ run_id }}' --required
AND "openai-organization" = '{{ openai-organization}}'
AND "openai-project" = '{{ openai-project}}'
RETURNING
id,
assistant_id,
thread_id,
cancelled_at,
completed_at,
created_at,
expires_at,
failed_at,
incomplete_details,
instructions,
last_error,
max_completion_tokens,
max_prompt_tokens,
metadata,
model,
object,
parallel_tool_calls,
required_action,
response_format,
started_at,
status,
temperature,
tool_choice,
tools,
top_p,
truncation_strategy,
usage;

Lifecycle Methods

OK

EXEC openai.assistants.runs.cancel
@thread_id='{{ thread_id }}' --required,
@run_id='{{ run_id }}' --required,
@openai-organization='{{ openai-organization }}',
@openai-project='{{ openai-project }}'
;