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)
raiseRate limits (conceptual)
Monitor usage in the provider dashboard. Cache embeddings where possible.
User-facing errors
Never expose raw API errors. Show: "Assistant busy — try again."
Related
- Glossary: latency, cost per token
- Lesson: Serving LLMs