AI Gateway

Limits, budgets & errors

Rate limits, spend caps, and the error envelope.

Every error uses the OpenAI-style envelope, so SDK error handling just works:

Error shape
{
  "error": {
    "message": "Rate limit exceeded for key (60 req/min). Retry in 12s.",
    "type": "rate_limit_error",
    "code": "rate_limit_exceeded",
    "param": null
  }
}

What can limit a request

StatusCodeMeaning
429rate_limit_exceededRequests/min, tokens/min, or concurrency cap hit. Honor the retry-after header.
402budget_exceededA hard spend cap (key, project or account) is used up for the period.
413request_too_largeBody over the inference size limit (10MB).
422guardrail_blockedYour account's data guardrails blocked the request (e.g. credit card numbers headed to an external model).
502upstream_errorEvery candidate backend failed. Safe to retry.

Budgets

Spend caps can be set per key, per project, and account-wide — the tightest one wins. A cap is either blocking (requests get 402 at the limit) or alert-only (email warning, requests keep flowing). Check live budget status with GET /client/budget using a key with usage:read.

Retries

Idempotent handling on your side plus exponential backoff on 429 and 502 is all you need — failover inside the gateway already retried other backends before a 502 reaches you.