Thread API
Threads serve as conversation containers that store Messages exchanged between a user and an Assistant, maintaining context and continuity across interactions.
This page provides API schemas for the following methods:
https://api.apilaplas.com/threads
https://api.apilaplas.com/threads/{threadId}
https://api.apilaplas.com/threads/{threadId}
https://api.apilaplas.com/threads/{threadId}
After each API 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 Thread
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "Create 3 data visualizations based on the trends in this file.",
"attachments": [
{
"file_id": file.id,
"tools": [{"type": "code_interpreter"}]
}
]
}
]
)
Retrieve information about a specific Thread by its ID
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
my_thread = client.beta.threads.retrieve("thread_abc123")
print(my_thread)
Modify a specific Thread by its ID
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
my_updated_thread = client.beta.threads.update(
"thread_abc123",
metadata={
"modified": "true",
"user": "abc123"
}
)
print(my_updated_thread)
Delete a specific Thread by its ID
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
response = client.beta.threads.delete("thread_abc123")
print(response)
Last updated