OpenAI Assistants API and Threads
OpenAI's managed agents: zero infra, but vendor lock-in and a missing piece in observability.
OpenAI Assistants API and Threads is a free AI Agents lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is It?
OpenAI Assistants API is a managed agent product. You define an assistant (model + instructions + tools); users interact via "threads" (conversations). OpenAI handles state, RAG, code interpreter, and file storage.
Two Big Drawcards
- Built-in file_search — managed RAG, no vector DB to run
- Built-in code_interpreter — sandboxed Python execution
If you want those features without building them, Assistants is fast.
Creating an Assistant
from openai import OpenAI
client = OpenAI()
assistant = client.beta.assistants.create(
name='Support Bot',
instructions='You help customers with orders.',
model='gpt-4o-mini',
tools=[{'type': 'file_search'}, {'type': 'code_interpreter'}]
)Threads = Conversations
thread = client.beta.threads.create()
client.beta.threads.messages.create(
thread_id=thread.id,
role='user',
content='Where is my order?'
)
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id
)Polling for Completion
Runs are async. Poll until done:
import time
while run.status not in ('completed', 'failed', 'requires_action'):
time.sleep(1)
run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)Function Calling
Same pattern as chat.completions tools. When run.status == 'requires_action', dispatch tool calls and submit results:
if run.status == 'requires_action':
tool_outputs = []
for tc in run.required_action.submit_tool_outputs.tool_calls:
result = dispatch(tc)
tool_outputs.append({'tool_call_id': tc.id, 'output': json.dumps(result)})
client.beta.threads.runs.submit_tool_outputs(thread_id=thread.id, run_id=run.id, tool_outputs=tool_outputs)File Search (Vector Store)
vector_store = client.beta.vector_stores.create(name='docs')
client.beta.vector_stores.file_batches.upload_and_poll(
vector_store_id=vector_store.id,
files=[open('handbook.pdf', 'rb')]
)
assistant = client.beta.assistants.update(assistant.id, tool_resources={'file_search': {'vector_store_ids': [vector_store.id]}})Code Interpreter
Add code_interpreter and the assistant gets a sandboxed Python. Great for data tasks:
{'type': 'code_interpreter'}Streaming
with client.beta.threads.runs.stream(thread_id=thread.id, assistant_id=assistant.id) as stream:
for event in stream:
print(event)Trade-offs
- + Zero infra for vector stores and sandbox
- + Managed memory and thread state
- + Built-in citations from file_search
- - Vendor lock-in
- - Less control over retrieval strategy
- - Latency higher than direct chat.completions
- - Observability is more limited
Roadmap
OpenAI announced the Responses API as a successor to Assistants. Some teams hold off on Assistants until Responses settles.
Use For Prototypes
Spinning up a doc-QA bot in 50 lines? Assistants is hard to beat. For production with strict SLAs and custom retrieval? Build it yourself.
Cost
Assistants charges:
- Normal token costs
- file_search: per-day per-GB storage
- code_interpreter: per-session
Cheap for low volume; can add up for heavy use.
Assistants Best Fit
What use case fits Assistants API best?
Recap
Assistants = managed agent product. file_search + code_interpreter + threads. Great for prototypes; less ideal for high-scale production. Watch the Responses API.
Frequently asked questions
Is the “OpenAI Assistants API and Threads” lesson free?
Yes — the full text of “OpenAI Assistants API and Threads” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.
What will I learn in “OpenAI Assistants API and Threads”?
OpenAI's managed agents: zero infra, but vendor lock-in and a missing piece in observability. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Agents?
No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “OpenAI Assistants API and Threads” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Agents lesson?
Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- LangGraph vs CrewAI vs AutoGen
- Letta (formerly MemGPT) for Long-Lived Agents
- OpenAI Assistants API and Threads
- Choosing the Right Framework Per Use Case