Skip to main content
The Swarms API enables you to create and orchestrate AI agents for both single-agent tasks and multi-agent workflows. The platform supports various AI models and provides flexible orchestration patterns for complex problem-solving scenarios.

Key Features

  • Single Agent Operations: Deploy individual AI agents for specific tasks
  • Multi-Agent Swarms: Coordinate multiple agents working together
  • Sequential Workflows: Agents work in ordered sequence, building on previous outputs
  • Concurrent Workflows: Agents work in parallel for faster processing
  • Tools Integration: Extend agent capabilities with custom functions
  • Multiple Model Support: Choose from OpenAI, Anthropic, and Groq models

Getting Started

Prerequisites

Before you begin, ensure you have:
  • Python 3.7+ or Node.js for JavaScript/TypeScript
  • An API key from Swarms Platform
  • Required libraries installed

Installation

Python:
JavaScript/TypeScript:

Authentication

The API uses API key authentication through the x-api-key header. For OpenAI SDK compatibility, the Authorization: Bearer <your-api-key> header is also accepted. Store your API key securely as an environment variable. Base URL:
  • Production: https://api.swarms.world
Security Note: Never hardcode API keys in your code. Always use environment variables or secure configuration management.

Single Agent Usage

Single agents are ideal for focused tasks that don’t require collaboration between multiple AI systems.

Basic Health Check

Before making API calls, verify your connection: Python:
JavaScript/TypeScript:

Creating a Basic Agent

A single agent requires an agent configuration and a task to execute: Python:
JavaScript/TypeScript:

Agent Configuration Parameters

  • agent_name: Descriptive name for your agent
  • description: Brief description of the agent’s purpose
  • system_prompt: Detailed instructions defining the agent’s role and capabilities
  • model_name: AI model to use (see supported models section)
  • role: Agent role, typically “worker”
  • max_loops: Maximum number of processing loops
  • max_tokens: Maximum response length
  • temperature: Response creativity (0.0 = deterministic, 1.0 = creative)
  • auto_generate_prompt: Whether to auto-enhance the system prompt
  • tools_list_dictionary: Optional tools for extended functionality

Maintaining Conversation History

For multi-turn conversations, include previous messages in the history parameter: Python:

Multi-Agent Swarms

Multi-agent swarms enable complex problem-solving by coordinating multiple AI agents. Swarms support two primary workflow types:

Workflow Types

Sequential Workflow: Agents execute in order, with each agent building upon the previous agent’s output. This is ideal for tasks requiring step-by-step processing. Concurrent Workflow: Agents work simultaneously on the same task, providing parallel processing for faster results and diverse perspectives.

Sequential Workflow Example

Sequential workflows are perfect for analysis pipelines where each step depends on the previous one: Python:

Concurrent Workflow Example

Concurrent workflows are ideal when you need multiple perspectives or parallel processing: Python:

Batch Processing

Premium Tier Required: The /v1/swarm/batch/completions endpoint is restricted to Pro, Ultra, and Premium plan subscribers. Upgrade your account to access batch swarm processing.
Process multiple swarms in a single request for improved efficiency: Python:

Advanced Features

Tools Integration

Enhance agent capabilities by providing specialized tools. Tools are defined using OpenAPI-style function specifications: Python:

Tool Definition Guidelines

When creating tools for your agents:
  1. Clear Names: Use descriptive function names that clearly indicate the tool’s purpose
  2. Detailed Descriptions: Provide comprehensive descriptions of what the tool does
  3. Parameter Specifications: Define all parameters with appropriate types and descriptions
  4. Required Fields: Specify which parameters are mandatory
  5. Usage Context: Include guidance in the system prompt about when to use specific tools

Supported Models

Choose the appropriate model based on your use case requirements:
Some models are restricted to premium-tier accounts. gpt-4.1 and all groq/* models are rejected for free-tier API keys. Call GET /v1/models with your key to see the models available to your tier.

OpenAI Models

  • gpt-4: High-quality reasoning and complex task handling
  • gpt-4.1: Optimized version with improved performance (premium tier only)
  • gpt-4.1-mini: Lightweight version for faster responses

Anthropic Models

  • claude-sonnet-4-20250514: Balanced performance and reasoning
  • claude-3-7-sonnet-latest: Latest Claude model with enhanced capabilities

Groq Models (premium tier only)

  • groq/llama3-70b-8192: High-performance open-source model
  • groq/deepseek-r1-distill-llama-70b: Specialized reasoning model

Model Selection Guidelines

  • Complex Analysis: Use GPT-4 or Claude Sonnet 4 for tasks requiring deep reasoning
  • Fast Responses: Choose gpt-4.1-mini for quick, straightforward tasks
  • Creative Tasks: Higher temperature settings work better with creative models
  • Factual Tasks: Lower temperature settings provide more consistent, factual responses

API Reference

Endpoints

Best Practices

Security

  • Never commit API keys to version control
  • Use environment variables for all sensitive configuration
  • Implement proper access controls in production environments
  • Regularly rotate API keys

Error Handling

Implement robust error handling for production applications: Python:

Rate Limiting

  • Implement exponential backoff for failed requests
  • Monitor your API usage to stay within limits
  • Use batch processing when possible to reduce individual request volume

Performance Optimization

  • Cache responses when appropriate
  • Use concurrent workflows for independent tasks
  • Choose the right model for your specific use case
  • Optimize token usage by being specific in your prompts

Testing Strategy

  • Start with simple, single-agent tasks
  • Test with different models to find the best fit
  • Gradually increase complexity as you understand the system
  • Implement comprehensive logging for debugging

Troubleshooting

Common Issues

Authentication Errors:
  • Verify your API key is correct and active
  • Check that the x-api-key header (or Authorization: Bearer <key>) is properly set
  • Ensure your API key has the necessary permissions
Timeout Issues:
  • Increase request timeout values
  • Consider breaking complex tasks into smaller chunks
  • Use batch processing for multiple operations
Model Availability:
  • Check if your requested model is currently available
  • Have fallback models configured
  • Monitor model status through the health endpoint
Payload Validation:
  • Ensure all required fields are present
  • Validate data types match the expected format
  • Check that tool definitions follow the correct schema

Getting Help

Community Resources

Professional Support

Stay Updated

Conclusion

The Swarms API provides a powerful platform for building sophisticated AI agent systems. Whether you’re working with single agents for focused tasks or orchestrating complex multi-agent workflows, the platform offers the flexibility and tools needed to create effective AI solutions. Start with simple implementations and gradually explore more advanced features like tools integration and multi-agent coordination. The community and documentation resources are available to help you succeed in building powerful agent-based applications.