orientx

Rate limits & errors

Rate-limit headers, backoff for 429, and the error table

Limits apply per key and are enforced on both request count and token throughput. Every response carries the current state:

HeaderMeaning
x-ratelimit-limit-requestsRequests allowed in the current window.
x-ratelimit-remaining-requestsRequests left in the window.
x-ratelimit-reset-requestsSeconds until the request counter resets.
x-ratelimit-limit-tokensTokens allowed in the current window.
x-ratelimit-remaining-tokensTokens left in the window.
x-ratelimit-reset-tokensSeconds until the token counter resets.

Exceeding a limit returns 429. Retry after the interval given in the Retry-After header, and add exponential backoff with jitter so that retries from concurrent workers do not line up:

import random
import time

import openai

def with_retries(fn, attempts=5):
    for attempt in range(attempts):
        try:
            return fn()
        except openai.RateLimitError as err:
            if attempt == attempts - 1:
                raise
            retry_after = getattr(err, "response", None)
            delay = float(retry_after.headers.get("Retry-After", 0)) if retry_after else 0
            time.sleep(max(delay, 2**attempt) + random.random())

The official OpenAI SDKs already retry 429 and 5xx a couple of times. Set max_retries when constructing the client if you want different behavior, and reserve custom logic for cases the SDK does not cover.

Errors

Failures use conventional HTTP status codes with a consistent body:

{
  "error": {
    "message": "Human-readable description of what went wrong.",
    "type": "invalid_request_error",
    "code": "context_length_exceeded"
  }
}
StatusMeaningWhat to do
400Malformed request or an unsupported parameterFix the request. Retrying will not help. See models & parameters.
401Missing or invalid keyCheck the Authorization header. See keys & authentication.
403Key has no access to this modelRequest access or pick another model.
404Unknown endpoint or retired modelRe-check the path and GET /v1/models.
429Rate limit or quota exhaustedBack off and retry, or raise your limit. Quota is on usage & billing.
5xxUpstream or gateway failureRetry with backoff.

Log error.code rather than matching on error.message — the code is stable, the message is not.

On this page