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
from dotenv import load_dotenv
import requests

load_dotenv()

API_KEY = os.getenv("SWARMS_API_KEY")

BASE_URL = "https://api.swarms.world"

headers = {
    "x-api-key": API_KEY,
    "Content-Type": "application/json"
}

# Get 10 agents (default)
resp = requests.post(
    f"{BASE_URL}/v1/marketplace/agents",
    headers=headers,
    json={}
)
print(resp.status_code)
print(json.dumps(resp.json(), indent=2))

# Get 25 agents
resp = requests.post(
    f"{BASE_URL}/v1/marketplace/agents",
    headers=headers,
    json={"number_of_items": 25}
)
print(resp.status_code)
print(json.dumps(resp.json(), indent=2))