# List the agents in your workspace. Python 3.9+ with requests.
import os
import sys

import requests

base = os.environ.get("RELATIONSAI_API_BASE", "https://voice-api.relationsai.com/v1")

r = requests.get(
    f"{base}/agents",
    params={"limit": 100},
    headers={"Authorization": f"Bearer {os.environ['RELATIONSAI_API_KEY']}"},
    timeout=30,
)
body = r.json()
if not r.ok:
    err = body["error"]
    sys.exit(f"{err['code']}: {err['message']} (request {err['request_id']})")
for agent in body["data"]:
    print(f"{agent['id']}  {agent['name']}  status={agent['status']} published={agent['published']} sample={agent['sample']}")
