Features
- Type Safety: Full type definitions for all request params and response fields
- Dual Clients: Both synchronous and asynchronous clients powered by httpx
- Comprehensive Coverage: Access to all Swarms API endpoints
- Modern Python: Built for Python 3.8+ with async/await support
- Environment Integration: Seamless .env file support for API keys
Installation
Environment Setup
Create a.env file in your project root:
Quick Start
Your First Swarm
Client Configuration
Environment Variable
SetSWARMS_API_KEY in your environment (or a .env file), then load it in your code:
Direct API Key
Custom Configuration
If
base_url is omitted, the installed swarms-client falls back to its own
built-in default host rather than https://api.swarms.world. Always pass
base_url="https://api.swarms.world" explicitly to avoid depending on
whatever host ships baked into a given SDK version.Core Operations
Single Agent Completion
Swarm Management
client.swarms.get_logs() calls GET /v1/swarm/logs, a deprecated alias.
The canonical endpoint, GET /v1/account/logs, is not yet exposed on this
SDK resource; call it directly with requests — see
Endpoints Not Yet in the SDK below.Model Information
Health and Status
Advanced Usage
Asynchronous Operations
Batch Operations
Run several swarms concurrently in a single request withclient.swarms.batch.run:
client.agent.batch.run, takes a list of
{"agent_config": ..., "task": ...} objects and posts to
/v1/agent/batch/completions (batch limit: 50 agent completions per request):
client.swarms.run or client.agent.run instead:
Helper Methods
The client provides convenient helper methods for common operations:Examples
Content Generation Swarm
Data Analysis Pipeline
Endpoints Not Yet in the SDK
The installedswarms-client (0.8.0) wraps a subset of the Swarms API:
client.agent.run, client.agent.batch.run, client.swarms.run,
client.swarms.batch.run, client.swarms.get_logs,
client.swarms.check_available, client.models.list_available,
client.health.check, and client.client.rate.get_limits.
Newer endpoints — reasoning agents, graph workflows, batched grid workflows,
the auto agent builder, and the account/usage endpoints — are not yet
wrapped by a dedicated resource. Call them directly with requests using
the same x-api-key header:
Troubleshooting
Common Issues
- API Key Errors: Ensure your API key is valid and properly set in environment variables
- Rate Limiting: Check rate limits with
client.client.rate.get_limits() - Network Issues: Verify your internet connection and firewall settings
- Model Availability: Use
client.models.list_available()to check available models
Getting Help
- GitHub: swarms-client repository
- Support: Check our technical support page