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
Copy
SWARMS_API_KEY=your-api-key-here
Step 3 — Run the code
- Python
- JavaScript
- cURL
Copy
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))
Copy
require('dotenv').config();
const API_KEY = process.env.SWARMS_API_KEY;
const BASE_URL = "https://api.swarms.world";
async function main() {
// Get 10 agents (default)
const res = await fetch(`${BASE_URL}/v1/marketplace/agents`, {
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({})
});
console.log(res.status);
const data = await res.json();
console.log(JSON.stringify(data, null, 2));
// Get 30 agents
const res2 = await fetch(`${BASE_URL}/v1/marketplace/agents`, {
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({ number_of_items: 30 })
});
console.log(res2.status);
const data2 = await res2.json();
console.log(JSON.stringify(data2, null, 2));
}
main().catch(console.error);
Copy
# Basic request (default 10 items)
curl -X POST "https://api.swarms.world/v1/marketplace/agents" \
-H "x-api-key: $SWARMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'
# Get 25 agents
curl -X POST "https://api.swarms.world/v1/marketplace/agents" \
-H "x-api-key: $SWARMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"number_of_items": 25}'