Rate limits
Three limits apply to every relay request, each to your organisation and to the API key:
| Limit | How it counts |
|---|---|
| Requests per minute (RPM) | A sliding window over the last 60 seconds. One unit per request. |
| Tokens per minute (TPM) | A token bucket that refills continuously: capacity is the TPM value and it refills at TPM/60 per second. |
| Concurrency | Requests in flight at once. A streaming request holds its slot until the stream ends. |
A request must fit under every limit of both the organisation and the key. The organisation’s limits depend on its account level and may be raised per organisation; a key can set limits of its own (key rate limits), and the stricter of the two applies. A limit that is not set is unlimited and its headers are omitted.
What counts toward TPM
Section titled “What counts toward TPM”When a request arrives the gateway does not yet know how many tokens it will produce. It charges the bucket with an estimate, input tokens plus the output ceiling (max_tokens, or the model’s default maximum when you set none), and corrects the bucket to the real token count when the request ends. A request that sets a very large max_tokens therefore uses a lot of the bucket for as long as it runs. Set max_tokens to what you need.
Response headers
Section titled “Response headers”Every response that got as far as the limiter carries these headers, success or 429. They describe the tightest limit among the organisation and the key.
| Header | Meaning |
|---|---|
x-ratelimit-limit-requests |
The RPM limit. |
x-ratelimit-remaining-requests |
Requests left in the current window. |
x-ratelimit-reset-requests |
Time until the request budget has recovered, as a duration: 250ms, 1s, 6m0s. |
x-ratelimit-limit-tokens |
The TPM limit. |
x-ratelimit-remaining-tokens |
Tokens left in the bucket (can be low or zero right after a request with a large max_tokens). |
x-ratelimit-reset-tokens |
Time until the token budget has recovered, same format. |
Retry-After |
On a 429 only: whole seconds to wait, at least 1. |
Header names are case-insensitive; over HTTP/1.1 they arrive as X-Ratelimit-Limit-Requests and so on. Requests refused earlier (bad key, bad body, unknown model) have not reached the limiter and carry no rate-limit headers.
curl -s -D - -o /dev/null https://api.test.whocare.xyz/v1/chat/completions \ -H "Authorization: Bearer $GATEWAY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "gpt-4o-mini", "max_tokens": 16, "messages": [{"role": "user", "content": "hi"}]}'# expect: X-Ratelimit-Limit-RequestsThe names and the duration format follow OpenAI’s, so clients that read those headers work as is. Anthropic-style anthropic-ratelimit-* and Gemini quota headers are not sent.
The 429 response
Section titled “The 429 response”A 429 has one of two causes, told apart by code:
rate_limit_exceeded: your organisation or key is over a limit. The message names which one, for examplerate limit exceeded (api_key tokens). WaitRetry-Afterseconds.upstream_rate_limited: every provider that could serve this model is itself rate limited or at the budget the operator set for it. Nothing is wrong with your account.Retry-Afteris present when a provider gave one.
Neither case is charged. See Errors and retries for backoff guidance.
If the limiter’s store is unreachable the gateway lets requests through rather than refusing them: limits protect capacity, and the balance check, which fails closed, protects your money.
This example uses httpx (pip install httpx).
import osimport timeimport httpx
url = "https://api.test.whocare.xyz/v1/chat/completions"headers = {"Authorization": f"Bearer {os.environ['GATEWAY_API_KEY']}"}body = {"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "hi"}]}
# Honour Retry-After on 429, back off on 5xx, give up on everything else.for attempt in range(5): r = httpx.post(url, headers=headers, json=body, timeout=60) if r.status_code == 429: time.sleep(int(r.headers.get("Retry-After", 2 ** attempt))) elif r.status_code >= 500: time.sleep(2 ** attempt) else: breakprint(r.status_code, r.headers.get("x-ratelimit-remaining-requests"))