Skip to main content
POST /v1/swarm/completions is the primary endpoint of the Swarms API. One request describes a whole multi-agent system — the roster, the architecture that coordinates it, and the task — and the response returns the swarm’s output along with timing and usage. This page is the complete field-by-field reference. For a conceptual introduction, start with Multi-Agent Overview; for guidance on picking a topology, see Available Architectures.

Endpoint

Authentication

Every request requires your API key in the x-api-key header. Get one from the API Keys page.
The batch variant, /v1/swarm/batch/completions, accepts an array of these same SwarmSpec objects (at most 50 per request) and is premium-gated. The single endpoint documented here is not.

Request Body: SwarmSpec

Every field is optional at the schema level, but a request with no task (or tasks/messages) and no agents has nothing to run. In practice you always send agents, swarm_type, and a task.

Core Parameters

agents accepts up to 2000 entries and max_loops is capped at 50. Exceeding either returns a 422 validation error before any work is billed.

Architecture-Specific Parameters

These only take effect for their corresponding swarm_type. Sending them with a different architecture is harmless but has no effect.

Swarm Types

swarm_type accepts one of the following 16 values:
BatchedGridWorkflow also has a dedicated premium endpoint, /v1/batched-grid-workflow/completions, and GraphWorkflow is not a swarm_type at all — it has its own endpoint at /v1/graph-workflow/completions.

AgentSpec

Each entry in agents is an AgentSpec. Every field is optional.

Identity and Model

Generation Controls

Looping and Tools

selected_tools accepts: create_plan, think, subtask_done, complete_task, respond_to_user, create_file, update_file, read_file, list_directory, delete_file, create_sub_agent, assign_task. run_bash is not permitted.

Reasoning

At xhigh and above, pair reasoning_effort with a large max_tokens so the model has room to both think and answer. A low max_tokens at high effort produces truncated or empty output.

Marketplace Publishing

Set when you want the agent listed on the Swarms Marketplace as a side effect of the run.

MCPConnection

Passed as mcp_config on an AgentSpec. Accepts additional properties beyond those listed.

MCP Authentication

stdio Transport

Only used when transport is "stdio".

MultipleMCPConnections

MCPOAuthConfig

Three flavors are supported: the interactive authorization_code browser flow (PKCE and dynamic client registration handled for you, so client_id is optional), the headless client_credentials flow, or supplying a pre-obtained access_token so no flow runs at all.
Any string field accepts "env:MY_VAR" or "${MY_VAR}" to read the value from the environment instead of hardcoding a secret.

Response: SwarmCompletion

All nine fields are always present in a successful response.
output is untyped in the schema because each architecture returns a different structure — SequentialWorkflow returns an ordered conversation, BatchedGridWorkflow returns a matrix keyed by agent, MajorityVoting returns votes plus a verdict. Branch on swarm_type rather than assuming a fixed shape.

Errors

HTTPValidationError

A 422 returns a detail array with one ValidationError per offending field:
Common causes: max_loops above 50, agents longer than 2000, max_tokens below 1, temperature outside 0–2, a swarm_type outside the enum, or AgentRearrange without rearrange_flow.

Examples

Basic Swarm Completion

Architecture-Specific Parameters

HierarchicalSwarm with a tuned director, and AgentRearrange with an explicit flow:
HeavySwarm builds its own agents internally — pass "agents": []. See HeavySwarm.

Streaming

Set stream: true to receive output as it is produced rather than waiting for the full run.
See Streaming and Swarm Streaming for the event shapes.

Multi-Agent Overview

Conceptual introduction to swarms

Available Architectures

Pick the right topology for your task

Batch Swarm Completions

Run up to 50 swarms in one request

Agent Completions

The single-agent endpoint

Graph Workflow

DAG orchestration on its own endpoint

Pricing

How swarm runs are billed