Reference · API

OpenAI errors & rate limits

Production apps need retries, backoff, and clear user errors.

Production apps need retries, backoff, and clear user errors.

Common HTTP codes

| Code | Meaning | Action |

|------|---------|--------|

| 401 | Invalid API key | Fix env var, rotate key |

| 429 | Rate limit / quota | Exponential backoff, queue |

| 500 | Server error | Retry with jitter |

| 400 | Bad request | Fix JSON, model name, params |

Retry pattern (pseudo)

import time
for attempt in range(3):
    try:
        return client.chat.completions.create(...)
    except RateLimitError:
        time.sleep(2 ** attempt)
raise

Rate limits (conceptual)

  • **RPM** — requests per minute
  • **TPM** — tokens per minute
  • Limits vary by account tier and model
  • Monitor usage in the provider dashboard. Cache embeddings where possible.

    User-facing errors

    Never expose raw API errors. Show: "Assistant busy — try again."

    Related