Fetch a list of your previously created agent configurations.
- Endpoint:
GET /v1/agents/list
- Auth:
x-api-key header
- Returns your agents and a
count of total agents
import json
import os
from typing import Any, Dict
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",
}
def list_agents() -> Dict[str, Any]:
"""Retrieve all unique agent configurations"""
try:
response = requests.get(f"{BASE_URL}/v1/agents/list", headers=HEADERS)
assert response.status_code == 200, f"Expected 200, got {response.status_code}: {response.text}"
response_data = response.json()
print(json.dumps(response_data, indent=4))
count = response_data["count"]
print(f"Number of agents: {count}")
return response_data
except Exception as e:
print(str(e))
return {}
if __name__ == "__main__":
list_agents()
Responses include a count of agents and an array of agent definitions you previously created.