How to Use the OpenAI Assistants API

Threads, tools, and file search — the managed agent API

Ad placeholder (leaderboard)

What the Assistants API is

The Assistants API is OpenAI’s higher-level, stateful interface for building agents. Instead of resending the entire conversation on every call and wiring up retrieval yourself, you create an assistant (a model plus instructions plus tools), keep the conversation in a thread, and execute it with a run. OpenAI manages the conversation state, context truncation, and hosted tools like code interpreter and file search. It trades some control for a lot less plumbing.

How the pieces fit together

There are four objects. An assistant is the reusable configuration: which model, what system instructions, and which tools it may use. A thread is a single conversation — an ordered list of messages that persists across calls. A message is one entry in a thread, from the user or the assistant. A run executes an assistant against a thread: it reads the latest messages, optionally calls tools, and appends the assistant’s reply. You either poll the run until its status is completed or stream events for a live UI.

The two headline tools are managed for you. File search turns attached files into a vector store and retrieves relevant passages automatically — managed RAG with no embedding code on your side. Code interpreter gives the assistant a sandboxed Python environment to run calculations, analyse data, or process uploads. The generator below produces the complete create-assistant, create- thread, add-message, and run flow in Python from your choices.

Tips and pitfalls

Reuse one assistant across many threads — the assistant is configuration, the thread is the conversation, so you do not recreate the assistant per user. Keep a thread per user or per conversation rather than mixing contexts. Prefer streaming for any interactive UI so users see progress. Remember that hosted tools cost extra (file storage, code execution) on top of token usage, so clean up vector stores you no longer need. And if you need full control over context, caching, or non-OpenAI providers, the lower-level Chat Completions API may suit you better than this managed abstraction.

Ad placeholder (rectangle)