How do I call the Model API with Python's requests library?
import os, requests
r = requests.post(
"https://api.gateway.clatterlabs.xyz/v1/chat/completions",
headers={
"Authorization": f"Bearer {os.environ['CLATTER_API_KEY']}",
"X-Clatter-Account": os.environ["CLATTER_ACCOUNT_ID"],
},
json={"model": "supercosmos-flash", "messages": [{"role": "user", "content": "Hello!"}]},
timeout=120,
)
data = r.json()
if r.status_code != 200:
raise RuntimeError(f"{r.status_code} {data['error']['code']}: {data['error']['message']}")
print(data["choices"][0]["message"]["content"], r.headers.get("x-request-id"))
json= sets Content-Type: application/json for you. For streaming, the OpenAI SDK is simpler.
Good to know#
- Each key has its own limit: 10, 30 (default), 60 or 120 requests per minute. Rate limits
- Every call shows in Console › Logs and Usage as Model API, with its price. See what you spent
- New accounts get $5 of free credit; top up from $1 to $800 per purchase in Console › Billing › Credits. Billing
Still need help?#
- General support: support@clatterlabs.com or team@clatterlabs.xyz
- Infrastructure questions, or permanent deletion of your data (your whole account or one service): infrastructure@clatterlabs.xyz
We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Related articles
Still need help?
Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyzFor deleting your whole account or the data of one service.