Runs are processes that execute the assistant’s logic within a thread, allowing it to process messages, generate responses, and call external tools if needed. Runs go through different statuses, such as queued, in_progress, and completed, and trigger events based on their progress, including tool calls and message updates.
This page provides API schemas for the following methods:
After each schema, you'll find a short example demonstrating how to correctly call the described method in code using the OpenAI SDK.
Note that the method names in the API schema and the SDK often differ.
Accordingly, when calling these methods via the REST API, you should use the names from the API schema, while for calls through the OpenAI SDK, use the names from the examples.
API Schemas
Create a run
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
run = client.beta.threads.runs.create(
thread_id="thread_abc123",
assistant_id="asst_abc123"
)
print(run)
Create a Thread and run it in one request
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
run = client.beta.threads.create_and_run(
assistant_id="asst_abc123",
thread={
"messages": [
{"role": "user", "content": "Explain deep learning to a 5 year old."}
]
}
)
print(run)
Retrieve a list of Runs belonging to a specific Thread