Skip to main content

Step 1 — Get your API key

Create an API key in your dashboard: https://swarms.world/platform/api-keys

Step 2 — Add it to .env

SWARMS_API_KEY=your-api-key-here

Step 3 — Run the code

import os
import json
import requests
from dotenv import load_dotenv

load_dotenv()

BASE_URL = "https://api.swarms.world"
headers = {
    "x-api-key": os.getenv("SWARMS_API_KEY"),
    "Content-Type": "application/json",
}

resp = requests.get(f"{BASE_URL}/v1/agents/list", headers=headers)
print(resp.status_code)
data = resp.json()
print(json.dumps(data, indent=2))
print(f"Number of agents: {data.get('count')}")