OpenAI sunset the Assistants API on August 26, 2026. Calls to /v1/assistants, /v1/threads and /v1/threads/runs no longer work, and the thread history stored on OpenAI's side can no longer be read through the API. If you still have code that creates runs and polls them, it has been failing since that date.
OpenAI's own replacement is the Responses API with the Conversations API. That is one option. If you are rewriting the integration anyway, it is a good moment to choose a backend that is not tied to one model provider, and that can run more than one agent when a single assistant stops being enough.
This guide moves an Assistants integration to the Swarms API. It maps every Assistants concept to its Swarms equivalent, shows the same assistant before and after in Python, replaces server-side threads with a store you own, swaps function calling for MCP, and ends with the shortest path for code that already uses the OpenAI SDK.
The concept map
The Assistants API had five objects. Here is where each one goes.
| Assistants API | Swarms API | What changes |
|---|
Assistant (instructions, model, tools) | agent_config on POST /v1/agent/completions | The configuration travels with each request, so it lives in your code and version control |
| Thread | A list of {role, content} messages you store | Sent as history; you own the data |
| Message | {"role": "user" | "assistant", "content": "..."} | Same shape as chat messages |
Run, plus polling runs.retrieve | One POST, which returns the answer | No polling loop; stream with streaming_on if you want tokens as they arrive |
Function tools and requires_action | An MCP server the agent calls during the run | No round trip through your code to submit tool outputs |
file_search with vector stores | Retrieval in your code, or an MCP server that searches your documents | You pick the index |
| Built-in web browsing | tools_enabled: ["auto_search", "web_scraper"] | Search is $0.04 per request that enables it |
code_interpreter | No direct equivalent | Run code in your own sandbox and pass the results in |
Two things change in how you think about it. A run is a single synchronous request, so the code shrinks. And the model is just a string: gpt-5.4, claude-sonnet-5, gemini-3.5-flash or any other model the platform lists, each billed at its own token price, which you can check with GET /v1/models/pricing.
Before: a typical Assistants integration
This is the pattern most Assistants code followed: create the assistant once, create a thread per user, add a message, start a run, poll until it finishes, then list the thread's messages.
# before.py: the Assistants API version (no longer works after August 26, 2026)
import time
from openai import OpenAI
client = OpenAI()
assistant = client.beta.assistants.create(
name="Support Agent",
instructions="You answer billing questions for Acme. Be brief and cite the policy you used.",
model="gpt-4o",
)
thread = client.beta.threads.create()
def ask(thread_id: str, text: str) -> str:
client.beta.threads.messages.create(thread_id=thread_id, role="user", content=text)
run = client.beta.threads.runs.create(thread_id=thread_id, assistant_id=assistant.id)
while run.status in ("queued", "in_progress"):
time.sleep(1)
run = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
messages = client.beta.threads.messages.list(thread_id=thread_id, order="desc", limit=1)
return messages.data[0].content[0].text.value
print(ask(thread.id, "Can I get a refund after 30 days?"))
Four API calls and a polling loop for one answer, with the conversation stored where you cannot reach it anymore.
After: the same assistant on the Swarms API
Get an API key from cloud.swarms.world/api-keys and set it as SWARMS_API_KEY. The assistant's settings become an agent_config dictionary, and a run becomes one request.
# after.py: the same assistant on the Swarms API
import os
import requests
API_URL = "https://api.swarms.world/v1/agent/completions"
HEADERS = {"x-api-key": os.environ["SWARMS_API_KEY"], "Content-Type": "application/json"}
SUPPORT_AGENT = {
"agent_name": "Support Agent",
"description": "Answers billing questions for Acme",
"system_prompt": "You answer billing questions for Acme. Be brief and cite the policy you used.",
"model_name": "gpt-5.4",
"max_loops": 1,
"max_tokens": 2000,
"temperature": 0.3,
}
def final_text(result: dict) -> str:
"""The agent's answer is the last turn in `outputs` that is not the user's."""
turns = [t for t in result["outputs"] if str(t.get("role", "")).lower() not in ("user", "system")]
return str(turns[-1]["content"])
def ask(history: list[dict], text: str) -> str:
payload = {"agent_config": SUPPORT_AGENT, "task": text, "history": history}
resp = requests.post(API_URL, headers=HEADERS, json=payload, timeout=120)
resp.raise_for_status()
result = resp.json()
print(f"cost: ${result['usage']['total_cost']:.4f}")
return final_text(result)
print(ask([], "Can I get a refund after 30 days?"))
One request, no polling, and every response carries a usage block with tokens and the exact total_cost of that call. The job_id it returns can be fetched again later with GET /v1/job/{job_id}.
If you want to switch providers, change model_name. If you want a fallback when a provider has an outage, add "fallback_models": ["claude-sonnet-5", "gemini-3.5-flash"] and the request is retried on the next model in the list.
Threads: keep the conversation yourself
On the Assistants API, OpenAI held the thread and you held its ID. That is exactly why the shutdown hurt: OpenAI's migration guide says the call that read thread messages no longer works and tells you to use messages your application already stored. Owning the history from now on avoids a repeat.
The Swarms API takes earlier turns in history as a list of {role, content} messages. When every role is user, assistant or system, the model receives them as real chat turns before the new task. A small SQLite table is enough to store them:
# threads.py: a thread store you own
import sqlite3
db = sqlite3.connect("threads.db")
db.execute(
"CREATE TABLE IF NOT EXISTS messages ("
" thread_id TEXT, seq INTEGER PRIMARY KEY AUTOINCREMENT, role TEXT, content TEXT)"
)
def load(thread_id: str, limit: int = 40) -> list[dict]:
rows = db.execute(
"SELECT role, content FROM messages WHERE thread_id = ? ORDER BY seq DESC LIMIT ?",
(thread_id, limit),
).fetchall()
return [{"role": r, "content": c} for r, c in reversed(rows)]
def append(thread_id: str, role: str, content: str) -> None:
db.execute("INSERT INTO messages (thread_id, role, content) VALUES (?, ?, ?)", (thread_id, role, content))
db.commit()
def chat(thread_id: str, text: str) -> str:
answer = ask(load(thread_id), text) # ask() from after.py
append(thread_id, "user", text)
append(thread_id, "assistant", answer)
return answer
The limit keeps long threads inside the model's context window. Assistants truncated threads for you; here the policy is yours, and it is one line to change.
If you exported thread messages before the shutdown, load them into this table with the same role and content fields and your users keep their conversations.
Function calling becomes MCP
On the Assistants API, a function tool meant a round trip: the run stopped with requires_action, your code executed the function, submitted the output with submit_tool_outputs, and you polled again.
On the Swarms API, the agent calls your tools directly over the Model Context Protocol. You put your functions behind a small MCP server and pass its URL in the agent config. The agent lists the tools, calls the ones it needs during the run, and returns a final answer.
Here is the refund lookup from the example as an MCP server, using the official Python SDK:
# orders_mcp.py: your former function tools, now an MCP server
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("acme-orders")
@mcp.tool()
def get_order(order_id: str) -> dict:
"""Look up an order by ID and return its date, total and refund eligibility."""
order = ORDERS_DB.get(order_id) # your existing function body goes here
return {"order_id": order_id, "placed": order["placed"], "total": order["total"], "refundable": order["refundable"]}
if __name__ == "__main__":
mcp.run(transport="streamable-http")
Deploy it anywhere with a public HTTPS URL, then point the agent at it. If the server needs a token, send it with mcp_config:
SUPPORT_AGENT["mcp_config"] = {
"url": "https://orders.acme.com/mcp",
"authorization_token": os.environ["ORDERS_MCP_TOKEN"],
}
For several servers, use mcp_urls with a list. There is a full walkthrough of this pattern, including auth, in How to Turn an AI Agent into an MCP Server in Python, and Wrap Any API as an MCP Server covers putting an existing REST API behind MCP without rewriting it.
File search and web search
file_search combined a hosted vector store with retrieval at run time. There are two ways to replace it:
- Retrieve in your code and pass the relevant passages in the task. If you already have embeddings in Postgres, Pinecone or a local index, this is the smallest change.
- Expose search as an MCP tool, so the agent decides when to search and what to search for. This is closer to how
file_search behaved and works well with the MCP setup above.
Agentic RAG via API walks through the second pattern with an agent that checks its own answers against the passages.
For the open web, set tools_enabled on the request:
payload = {
"agent_config": SUPPORT_AGENT,
"task": "What changed in the EU's consumer refund rules this year?",
"tools_enabled": ["auto_search"],
}
auto_search runs web searches through Exa and web_scraper reads pages. Search costs $0.04 once per request that enables it, however many searches the agent runs; the scraper is free.
The shortest path: keep the OpenAI SDK
If your codebase already uses the OpenAI SDK for chat and you only used Assistants for a few features, you can point the SDK at the Swarms API and keep your call sites. The Swarms API serves an OpenAI-compatible /v1/chat/completions and accepts the key as a Bearer token, which is what the SDK sends:
from openai import OpenAI
client = OpenAI(base_url="https://api.swarms.world/v1", api_key=os.environ["SWARMS_API_KEY"])
reply = client.chat.completions.create(
model="claude-sonnet-5",
messages=[
{"role": "system", "content": "You answer billing questions for Acme."},
{"role": "user", "content": "Can I get a refund after 30 days?"},
],
)
print(reply.choices[0].message.content)
The same base URL serves /v1/responses in the Responses format for simple text generation, and /v1/messages in Anthropic's format. These compatible endpoints are stateless, so the thread store above still applies.
When one assistant becomes several agents
Many Assistants deployments grew into one long system prompt that tried to research, decide and write at once. On the Swarms API, splitting that into specialists is a change of endpoint, from /v1/agent/completions to /v1/swarm/completions:
swarm = {
"name": "Refund Desk",
"swarm_type": "SequentialWorkflow",
"task": "Customer 4411 asks for a refund on order A-1009 placed 41 days ago.",
"agents": [
{"agent_name": "Policy Checker", "model_name": "gpt-5.4-mini", "max_loops": 1,
"system_prompt": "Find the refund rules that apply and quote them."},
{"agent_name": "Decision Maker", "model_name": "claude-sonnet-5", "max_loops": 1,
"system_prompt": "Given the policy and the order, decide approve or deny and explain why."},
{"agent_name": "Reply Writer", "model_name": "gpt-5.4-mini", "max_loops": 1,
"system_prompt": "Write a short, friendly reply to the customer stating the decision."},
],
}
resp = requests.post("https://api.swarms.world/v1/swarm/completions", headers=HEADERS, json=swarm, timeout=300)
Each agent picks its own model, so cheap models handle lookup and formatting and a stronger one makes the decision. SequentialWorkflow is one of more than a dozen architectures; Swarm Architectures Explained covers the rest.
Migration checklist
- Export any thread messages you still have and load them into your own store.
- Turn each assistant into an
agent_config dictionary in your code.
- Replace create-run-poll-list with one
POST /v1/agent/completions, sending stored turns as history.
- Move function tools behind an MCP server and set
mcp_config or mcp_urls.
- Replace
file_search with retrieval in your code or a search tool on MCP.
- Add
fallback_models so a provider outage does not take your feature down.
- Read
usage.total_cost on every response, or open your logs in Swarms Cloud, to watch spend per request.
Get started
Create an API key at cloud.swarms.world, then run after.py above with your own instructions. The Swarms API docs cover every endpoint, and the pricing page shows what each plan includes. When you need the batch, reasoning or graph endpoints, you can upgrade your plan on Swarms Cloud.