Assistants (Beta)
Managing Threads
POST
/
v1
/
threads
from openai import OpenAI
client = OpenAI()
# Create a thread
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "Explain quantum computing in simple terms."
}
]
)
print(thread.id)
import OpenAI from "openai";
const openai = new OpenAI();
// Create a thread
const thread = await openai.beta.threads.create({
messages: [
{
role: "user",
content: "Explain quantum computing in simple terms."
}
]
});
console.log(thread.id);
curl https://api.openai.com/v1/threads \\
-H "Authorization: Bearer $OPENAI_API_KEY" \\
-H "Content-Type: application/json" \\
-H "OpenAI-Beta: assistants=v2" \\
-d '{
"messages": [
{
"role": "user",
"content": "Explain quantum computing in simple terms."
}
]
}'
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699012949,
"metadata": {},
"tool_resources": {}
}
The Assistants API is deprecated in favor of the Responses API.
Create Thread
Request Body
array
A list of messages to start the thread with.
Show Message object
Show Message object
object
A set of resources that are made available to the assistant’s tools in this thread. The resources are specific to the type of tool. For example, the
code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.object
Set of 16 key-value pairs that can be attached to an object.Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
Response
Returns aThread object.
string
The thread identifier.
string
The object type, always
thread.integer
The Unix timestamp (in seconds) for when the thread was created.
object
Set of 16 key-value pairs attached to the object.
Retrieve Thread
GET https://api.openai.com/v1/threads/{thread_id}
Retrieves a thread.
Update Thread
POST https://api.openai.com/v1/threads/{thread_id}
Modifies a thread.
Delete Thread
DELETE https://api.openai.com/v1/threads/{thread_id}
Delete a thread.
from openai import OpenAI
client = OpenAI()
# Create a thread
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "Explain quantum computing in simple terms."
}
]
)
print(thread.id)
import OpenAI from "openai";
const openai = new OpenAI();
// Create a thread
const thread = await openai.beta.threads.create({
messages: [
{
role: "user",
content: "Explain quantum computing in simple terms."
}
]
});
console.log(thread.id);
curl https://api.openai.com/v1/threads \\
-H "Authorization: Bearer $OPENAI_API_KEY" \\
-H "Content-Type: application/json" \\
-H "OpenAI-Beta: assistants=v2" \\
-d '{
"messages": [
{
"role": "user",
"content": "Explain quantum computing in simple terms."
}
]
}'
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699012949,
"metadata": {},
"tool_resources": {}
}
from openai import OpenAI
client = OpenAI()
# Create a thread
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "Explain quantum computing in simple terms."
}
]
)
print(thread.id)
import OpenAI from "openai";
const openai = new OpenAI();
// Create a thread
const thread = await openai.beta.threads.create({
messages: [
{
role: "user",
content: "Explain quantum computing in simple terms."
}
]
});
console.log(thread.id);
curl https://api.openai.com/v1/threads \\
-H "Authorization: Bearer $OPENAI_API_KEY" \\
-H "Content-Type: application/json" \\
-H "OpenAI-Beta: assistants=v2" \\
-d '{
"messages": [
{
"role": "user",
"content": "Explain quantum computing in simple terms."
}
]
}'
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699012949,
"metadata": {},
"tool_resources": {}
}