Swarms Logo
ProductEngineering

Swarms API Update: Faster Requests, Steadier Under Load, and 61 Bug and Security Fixes

Over the past month we merged 113 changes to the Swarms API. Agent calls make half the database round trips, pricing and model lookups answer in milliseconds, busy servers stay responsive, and 50 bug fixes and 11 security fixes shipped. Here is what changed, what we measured, and how to start using the API.

Swarms Team8 min read
Swarms API Update: Faster Requests, Steadier Under Load, and 61 Bug and Security Fixes

The Swarms API runs agents, multi-agent swarms, workflows and reasoning agents behind one endpoint at https://api.swarms.world. Between October 25 and November 25 we merged 113 changes to it. Most of them make your requests faster or make the API more dependable when something goes wrong.

The short version:

  1. Faster requests. An agent completion now makes 9 to 11 database round trips instead of 18, and pricing and model lookups answer in about 5 ms instead of 0.8 s.
  2. Steadier under load. When many requests arrive at once, the median response is about twice as fast, and one heavy request no longer stalls the others on the same server.
  3. Fairer billing. You no longer pay the agent fee for an agent whose model calls all failed, reasoning agents are billed on the tokens the provider actually reported, and the image fee dropped from $0.25 to $0.02.
  4. 61 fixes. 50 bug fixes and 11 security fixes, including a 25 MB cap on request bodies and API keys kept out of server logs.

Your requests and code do not need to change. Everything below is live on api.swarms.world today.

The Numbers

What we measuredBeforeAfter
Database round trips per agent completion189 to 11
Agent completion, total request time (repeat call)3.6 s2.3 s
Swarm completion, total request time3.4 s2.3 s
GET /v1/models/pricing, /v1/usage/costs, /v1/swarms/availableabout 0.8 sabout 5 ms
GET /v1/account/credits1.0 s0.5 s
24 credit checks at once, median2.8 to 3.7 s1.5 to 1.6 s
/health p95 with 8 agent calls running on the server22 ms2 to 3 ms
/health worst case during heavy log reads4,129 ms162 ms
GET /v1/account/logs, free plan0.38 to 0.65 s0.21 to 0.23 s
GET /v1/account/metrics/summary0.96 s0.53 s
New database connections across three load rounds32 / 9 / 24 / 0 / 0
Downloads of the OpenRouter catalogue for 10 cold requests101

Each number comes from the pull request that made the change, measured on a local server running the old and new code side by side. They are a comparison of the two versions, not measurements from production traffic. Times that include a model call vary with the provider by a few hundred milliseconds either way, and the gains you see depend on how far your region is from our database.

Faster Requests

Before your agent's model was ever called, the API used to look up your API key, your plan, your premium status and your credit balance, and several of those lookups ran more than once as the request passed through each layer. One agent completion made 18 database round trips, 11 of them one after another.

Now each lookup runs once and is cached for 30 seconds. An agent completion makes 9 to 11 round trips, and a repeat call takes 2.3 s end to end instead of 3.6 s. Read-only endpoints that do not cost credits, such as pricing, usage costs and the list of swarm types, skip the rate limiter and answer in about 5 ms.

The cache has one visible effect: a revoked key or a plan change can take up to 30 seconds to apply.

Smaller changes in the same direction:

  • Request logs are written after the response is sent. Your response no longer waits for the log insert.
  • The first request on each server is no longer the slow one. Agent setup is warmed up at startup, before the server takes traffic.
  • Account logs and the metrics summary run their queries in parallel, so they load about 45% faster.
  • The OpenRouter model list is downloaded once per refresh and shared by /v1/models, /v1/models/available and billing, instead of once for every request that arrived while it was refreshing.
  • Agent validation is 2 to 24 times faster. It was already measured in microseconds, so you will not feel this one, but it keeps work off the request path.

Steadier Under Load

Each API server handles many requests at once on a single event loop. Until this month, sixteen database calls ran directly on that loop, along with the input log write on every agent and chat completion. While one of them waited on the database, every other request on that server waited too: health checks, credit lookups and the tokens of streams already in progress.

Those calls now run on worker threads. With eight agent calls in flight, /health answers in 2 to 3 ms at p95 instead of 22 ms. During four heavy log downloads at once, its worst case fell from 4.1 s to 0.16 s.

We also replaced the per-thread database clients with one shared connection pool. Under a burst of 24 concurrent credit checks, the median response went from about 3 s to 1.5 s, and the server opened 4 new database connections instead of 32.

For streaming this means steadier tokens. A stream no longer pauses because another request on the same server is writing a log row.

Lower Memory Use

  • Request bodies are capped at 25 MB. A larger body gets a 413 with error.type set to request_too_large, before the server reads it into memory. Previously a worker would buffer whatever it was sent.
  • Fewer open connections. The shared database pool keeps one set of connections per server, which cut new connections by about 8 times in our load test.
  • Heavy reads stay off the request loop. A logs download can move around 10 MB, and it now runs on a worker thread instead of holding up the server's other requests.

Fairer Billing

Several of the 50 bug fixes change what a run costs, and most of them make it cheaper:

  • No agent fee for agents that failed. In swarms, batched grid workflows and graph workflows, an agent whose every model call failed no longer pays the per-agent fee, and its error text is no longer counted as output tokens. A swarm in which no agent got an answer costs nothing.
  • Reasoning agents are billed on reported usage. Self-consistency, ReflexionAgent, AgentJudge and the auto agent builder are now charged for the tokens the provider reported, instead of an estimate from the prompt and final answer.
  • Handoff agents are billed at their own model's price instead of the parent agent's.
  • A blank task is rejected with a 400 before anything runs, so it is never billed.
  • Images cost $0.02 each instead of $0.25.
  • A stream that fails partway is billed for what it sent, the same way a stream you cancel yourself is.

11 Security Fixes

  • Request bodies over 25 MB are refused with a 413.
  • Image URLs and MCP server URLs must use https://, and raw base64 images are wrapped so they can never be opened as a file path.
  • MCP credentials written as env:NAME or ${NAME} are rejected, so a request cannot read the server's environment.
  • The autonomous file tools (read_file, create_file, update_file, list_directory, delete_file) are no longer available to agents.
  • director_settings accepts only its six documented keys.
  • A swarm's rearrange_flow is capped at 2,000 names and its tasks list at 50, which bounds how many model calls one request can make.
  • CORS no longer marks any origin as trusted with credentials.
  • Server logs no longer carry prompts in tracebacks, and record only the last 4 characters of an API key.
  • The hosted MCP server at /mcp hides crash details, encodes path values and rejects unknown tools.

Fewer Errors

  • Clearer status codes. Requests that used to fail with a 500, such as a max_tokens below 1, a null agent_name or a malformed message part, now get a 400 or 422 that names the field.
  • Provider errors keep their status. When a model provider rejects a call, you get its status code and message instead of a generic 500.
  • Errors in the right shape. /v1/messages returns errors in Anthropic's format and /v1/responses in OpenAI's, so those SDKs parse them correctly.
  • Cache failures no longer fail your request. If our shared cache returns a bad reply or is unreachable, the API answers from the database as if the cache were off.

Get Started With the Swarms API

1. Get an API key

Create a key on the API Keys page and export it:

Shell
export SWARMS_API_KEY="your-key-here"

The API accepts the key as an x-api-key header, or as Authorization: Bearer <key> for OpenAI-compatible clients.

2. Run one agent with curl

Shell
curl -s https://api.swarms.world/v1/agent/completions \
  -H "x-api-key: $SWARMS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_config": {
      "agent_name": "Summarizer",
      "system_prompt": "You summarize text in two sentences.",
      "model_name": "gpt-5.4-mini",
      "max_tokens": 200
    },
    "task": "Summarize why event loops stall when a database call blocks."
  }'

The response holds the agent's answer in outputs and the tokens and cost of the run in usage.

3. Run one agent from Python

Python
# agent_quickstart.py
# Requires: pip install requests
import os

import requests

API = "https://api.swarms.world"
HEADERS = {"x-api-key": os.environ["SWARMS_API_KEY"]}

response = requests.post(
    f"{API}/v1/agent/completions",
    headers=HEADERS,
    json={
        "agent_config": {
            "agent_name": "Researcher",
            "system_prompt": "You answer questions with short, sourced facts.",
            "model_name": "gpt-5.4-mini",
            "max_tokens": 400,
        },
        "task": "What are three common causes of slow API responses?",
    },
    timeout=120,
)
response.raise_for_status()
result = response.json()

print(result["outputs"])
print(result["usage"])

4. Run a multi-agent swarm

A SequentialWorkflow passes each agent's output to the next one. Change swarm_type to try another architecture; GET /v1/swarms/available lists them all.

Python
# swarm_quickstart.py
import os

import requests

API = "https://api.swarms.world"
HEADERS = {"x-api-key": os.environ["SWARMS_API_KEY"]}

agents = [
    {
        "agent_name": "Researcher",
        "system_prompt": "List the key facts about the topic.",
        "model_name": "gpt-5.4-mini",
        "max_tokens": 400,
    },
    {
        "agent_name": "Writer",
        "system_prompt": "Turn the facts you are given into one clear paragraph.",
        "model_name": "gpt-5.4-mini",
        "max_tokens": 400,
    },
]

response = requests.post(
    f"{API}/v1/swarm/completions",
    headers=HEADERS,
    json={
        "name": "Research and write",
        "swarm_type": "SequentialWorkflow",
        "task": "Explain connection pooling for a backend newsletter.",
        "agents": agents,
        "max_loops": 1,
    },
    timeout=300,
)
response.raise_for_status()
result = response.json()

print(result["output"])
print(f"{result['number_of_agents']} agents, {result['execution_time']:.1f} s")
print(result["usage"])

5. Stream with the OpenAI SDK

/v1/chat/completions speaks the OpenAI format, so the OpenAI SDK works by changing base_url. Streaming is where the event-loop work above shows most.

Python
# stream_quickstart.py
# Requires: pip install openai
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SWARMS_API_KEY"],
    base_url="https://api.swarms.world/v1",
)

stream = client.chat.completions.create(
    model="gpt-5.4-mini",
    messages=[{"role": "user", "content": "Write a haiku about fast APIs."}],
    max_tokens=100,
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

6. Call it from TypeScript

TypeScript
// agent_quickstart.ts (Node 18+ has fetch built in)
const response = await fetch("https://api.swarms.world/v1/agent/completions", {
  method: "POST",
  headers: {
    "x-api-key": process.env.SWARMS_API_KEY!,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    agent_config: {
      agent_name: "Helper",
      model_name: "gpt-5.4-mini",
      max_tokens: 200,
    },
    task: "Give me one tip for writing fast APIs.",
  }),
});

const result = await response.json();
console.log(result.outputs, result.usage);

7. Check prices and your balance

These are among the endpoints that now answer in milliseconds:

Shell
# Price per million tokens for a model
curl -s "https://api.swarms.world/v1/models/pricing?model_name=gpt-5.4-mini" \
  -H "x-api-key: $SWARMS_API_KEY"

# Your remaining credits
curl -s https://api.swarms.world/v1/account/credits \
  -H "x-api-key: $SWARMS_API_KEY"

Also New This Month

  • A hosted MCP server at https://api.swarms.world/mcp exposes every endpoint as a tool for Claude Code, Cursor and other MCP clients. See the MCP getting-started guide.
  • Native streaming for agent, chat, Responses and Messages completions.
  • Paging with limit and offset on /v1/models, /v1/models/available and /v1/account/logs.
  • /llms.txt and /AGENTS.md at the API root, so coding agents can find the base URL, auth and main endpoints on their own.

Conclusion

This month's work went into the time a request spends outside the model: fewer database round trips, lookups cached and shared between servers, logging moved off the request path, and no blocking calls on the event loop. Requests are faster, a busy server stays responsive, failed agents cost nothing, and 11 security fixes close off ways a single request could misuse the server.

We will keep publishing these numbers as we go, measured the same way.

Read the docs: docs.swarms.ai

Get an API key: swarms.world/platform/api-keys