How do I read rate limit headers in Python?
Headers aren't on the parsed object, so ask for the raw response.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.gateway.clatterlabs.xyz/v1",
api_key=os.environ["CLATTER_API_KEY"],
default_headers={"X-Clatter-Account": os.environ["CLATTER_ACCOUNT_ID"]},
)
raw = client.chat.completions.with_raw_response.create(
model="supercosmos-flash", messages=[{"role": "user", "content": "Hi"}]
)
print(raw.headers.get("x-ratelimit-limit"), raw.headers.get("x-ratelimit-remaining"))
print(raw.headers.get("x-request-id"))
resp = raw.parse()
print(resp.choices[0].message.content)
Also check x-clatter-notice: it's set to abuse_warning when a request earned a warning under the Abuse policy.
The client setup above (base URL, key and the X-Clatter-Account header) is the same in every Python example; see Set up the Python SDK. Full parameter list: Create a chat completion.
Good to know#
- Retry only
429and 5xx errors, with backoff; honourRetry-Afterwhen it's sent. Which errors to retry - Each key has its own limit: 10, 30 (default), 60 or 120 requests per minute. Rate limits
- If calls fail unexpectedly, check status.clatterlabs.com before debugging further.
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.