Skip to main content
The Swarms API provides powerful multi-agent orchestration capabilities, enabling you to build complex systems where multiple AI agents collaborate to solve problems. Each multi-agent architecture type is designed for specific use cases and can be combined to create powerful multi-agent systems.

Swarm Completions Endpoint

The /v1/swarm/completions endpoint is the primary API for executing multi-agent swarm workflows. This endpoint supports both standard and streaming responses, allowing you to orchestrate complex multi-agent systems. Endpoint: POST /v1/swarm/completions Base URL: https://api.swarms.world

Authentication

All requests require an API key in the header:

Input Parameters

The request body uses the SwarmSpec schema. All parameters are organized in the tables below:

Swarm Configuration Parameters

Agent Configuration Parameters (AgentSpec)

Each agent in the agents array can be configured with the following parameters:

MCP Connection Configuration Parameters

Multiple MCP Connections

Output Parameters

The endpoint returns a SwarmCompletion object with the following parameters:

Swarm Architectures

Each multi-agent architecture type is designed for specific use cases and can be combined to create powerful multi-agent systems. There are 14 supported swarm_type values, exactly matching what GET /v1/swarms/available returns live. See Available Architectures for the full description, category, best-for use cases, and tuning parameters of each.
BatchedGridWorkflow and GraphWorkflow are not swarm_type values — each has its own dedicated, premium-only endpoint (/v1/batched-grid-workflow/completions and /v1/graph-workflow/completions). "auto" and "SpreadSheetSwarm" are rejected with a 400 error if sent as swarm_type. See Available Architectures for details.

Best Practices

This section outlines production-grade best practices for using the Swarms API effectively. These guidelines will help you choose the right swarm architecture, optimize costs, and implement robust error handling in your multi-agent systems.

Choosing the Right Swarm Architecture

Selecting the optimal swarm architecture is crucial for achieving your desired outcomes. Start by analyzing your task complexity: complex tasks benefit from HierarchicalSwarm or MultiAgentRouter. For dynamic tasks that require adaptive processing, consider AgentRearrange. When evaluating workflow patterns, use SequentialWorkflow for linear processes where each step depends on the previous one, ConcurrentWorkflow for parallel operations that can run independently, and GroupChat for collaborative tasks requiring interactive problem-solving. For multi-domain expertise requirements, MixtureOfAgents combines diverse specialist agents effectively, while MajorityVoting provides consensus-based decision-making for quality assurance needs. Different applications have specific swarm recommendations. Team automation systems excel with HierarchicalSwarm, providing automated team coordination with clear responsibility chains and scalable structures. Research pipelines benefit from SequentialWorkflow, ensuring structured processes with quality control at each stage. Trading systems leverage ConcurrentWorkflow for multi-market coverage and real-time analysis with risk distribution. Content factories utilize MixtureOfAgents for automated content creation with consistent quality and high throughput. Industry-specific patterns also guide architecture selection. In finance, risk analysis uses HierarchicalSwarm, market research employs MixtureOfAgents, and trading strategies leverage ConcurrentWorkflow. Healthcare applications use SequentialWorkflow for patient analysis, MajorityVoting for research review, GroupChat for treatment planning, and MultiAgentRouter for medical records management. Legal workflows apply SequentialWorkflow for document review, MixtureOfAgents for case analysis, HierarchicalSwarm for compliance checks, and ConcurrentWorkflow for contract analysis.

Cost Optimization

Swarm completions bill a flat per-agent fee (swarm_completions_agent_cost, 0.01bydefault)plustokencosts(swarmcompletionsinputcostper1m/swarmcompletionsoutputcostper1m,0.01 by default) plus token costs (`swarm_completions_input_cost_per_1m` / `swarm_completions_output_cost_per_1m`, 6.50 / $18.50 per 1M tokens by default — see Pricing for current values). Only the token component is discounted off-peak; the per-agent fee is charged in full regardless of time. The clearest, verifiable cost lever is timing: requests are automatically billed at a 50% discount on the token cost when the server’s clock, in the America/Los_Angeles timezone, falls between 8 PM and 6 AM (20:00–05:59 PT) — there is no separate “off-peak tier” to opt into; the discount applies automatically based on when the request runs. Beyond that, the usual principles apply: use only as many agents as the task needs (each one adds a flat per-agent fee), keep max_tokens and prompts focused on what the task requires, and pick a max_loops no larger than necessary — extra loops re-run the same agents and add tokens without a documented cost multiplier to justify them.

Production Best Practices

Implementing robust production practices ensures reliable and efficient multi-agent systems. Use the swarm type suited to your task shape (see Available Architectures), implement error handling with retry logic for transient failures, and log responses (job_id, execution_time, usage) to track cost and performance over time. Check your credit balance and rate-limit headers (X-RateLimit-*, see Rate Limit Headers) rather than assuming a request will succeed. Avoid common anti-patterns that can compromise your system’s reliability and security. Never hardcode API keys in your application code — load them from the environment. Respect rate limits to prevent 429 responses, and stay above the minimum credit balance (billable routes require a total balance greater than $1.00, or requests are rejected with 402 before any work runs). Avoid using more agents than a task requires — every agent in the agents array adds a flat per-agent fee whether or not its output changes the final result.

Error Handling

The API returns standard HTTP status codes. 401 means a missing or invalid x-api-key — rotate and store keys securely. 402 means your credit balance is below the required minimum. 403 means the request used a model or endpoint gated to premium accounts. 422 is a validation error — the response body’s detail array names the offending field and constraint (see the Errors reference); validate max_loops (≤ 50), agents length (≤ 2000), and temperature (0–2) client-side before sending. 429 means you exceeded a rate-limit window — back off using the Retry-After header. 500 is a server-side failure — retry with backoff.

Example Usage

Basic Swarm Completion

Additional Resources