Swarms Api Cookbook banner
The-Swarm-Corporation The-Swarm-Corporation

Swarms Api Cookbook

Development community

Description

Practical cookbook examples for the Swarms API Client. This repository is a hands-on guide to building with Swarms, showcasing single-agent and multi-agent workflows, concurrent and sequential pipelines, content generation, data analysis, health and rate checks, and more.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

Swarms API Cookbook

🏠 Swarms Website   •   📙 Documentation   •   🔑 API Key Management

Practical cookbook examples for the Swarms API Client. This repository is a hands-on guide to building with Swarms, showcasing single-agent and multi-agent workflows, concurrent and sequential pipelines, content generation, data analysis, health and rate checks, and more. Each example is designed to be minimal yet illustrative, so you can quickly adapt patterns to your own use cases.

What you’ll find here:

  • Clear, runnable examples for common tasks
  • Patterns for hierarchical, concurrent, and sequential workflows
  • Utilities for health checks, model discovery, logs, and rate limits
  • Async usage with AsyncSwarmsClient for higher throughput workloads

Install

pip install swarms-client python-dotenv

Set your API Key

Use an environment variable:

export SWARMS_API_KEY="your_api_key_here"

Or create a `.env` file in your project root:

echo 'SWARMS_API_KEY=your_api_key_here' > .env

Quickstart

import os
from dotenv import load_dotenv
from swarms_client import SwarmsClient

load_dotenv()

client = SwarmsClient(api_key=os.getenv("SWARMS_API_KEY"))

response = client.swarms.run(
    name="Hello Swarm",
    description="Simple demo swarm",
    swarm_type="SequentialWorkflow",
    task="Write a concise haiku about collaborative AI.",
    agents=[
        {
            "agent_name": "Haiku Writer",
            "description": "Creates short poetic outputs",
            "system_prompt": "Write a haiku that is vivid and clear.",
            "model_name": "gpt-4.1",
            "role": "worker",
            "max_loops": 1,
            "max_tokens": 256,
            "tempera