How to Fix OpenAI and Claude API Errors: 401, 403, 429, 529 and insufficient_quota
APIsQuick answer: Retry only temporary errors: 429 rate limits, 500, 503 and Claude’s 529, with exponential backoff that honors the Retry-After header. Do not retry 401/403 (key, organization or region problems), 400 (bad request) or billing 429s such as insufficient_quota; those need a fix in your code or account.
Which API errors should I retry?
| Code | OpenAI meaning | Anthropic meaning | Retry? |
|---|---|---|---|
| 400 | invalid request | invalid_request_error, also returned when a spend limit is reached |
No |
| 401 | invalid auth / incorrect key / not in org / IP not allowed | authentication_error |
No |
| 402 | n/a | billing_error |
No |
| 403 | country, region or territory not supported | permission_error |
No |
| 404 | resource not found (NotFoundError in the SDKs) |
not_found_error |
No |
| 413 | n/a | request_too_large (Messages 32 MB, Batches 256 MB) |
No, shrink it |
| 429 | rate limit, slow_down, or a billing/spend limit |
rate_limit_error |
Rate limit: yes. Billing: no |
| 500 | server error | api_error |
Yes |
| 503 | server_is_overloaded |
n/a | Yes |
| 504 | n/a | timeout_error |
Yes, or use streaming |
| 529 | n/a | overloaded_error |
Yes |
OpenAI’s error-code table doesn’t list 404. Its Python library maps a 404 to NotFoundError, which the error guide describes as “Requested resource does not exist”, so check the model name, file or resource ID in your request (OpenAI error codes, openai-python). Anthropic’s not_found_error likewise means the endpoint path or a resource ID is wrong (Anthropic errors).
How do I fix an OpenAI 401 error?
Check, in this order: the key is copied without spaces and not revoked; the OpenAI-Organization or project header (if you send one) matches the key; and, if the project has an IP allow list, your server’s IP is on it. OpenAI’s error-code guide lists each of these as a separate 401 message, so read the message field, not just the status.
What does insufficient_quota mean, and why doesn’t retrying help?
OpenAI now returns several billing-related 429s: credit_balance_exhausted, organization_spend_limit_exceeded, project_spend_limit_exceeded and organization_usage_limit_exceeded, and the error.type can still say insufficient_quota. All of them mean money or a limit, not traffic. Add credit, raise the project’s spend limit, or wait for the monthly usage limit to reset. Your tier’s monthly cap is in our OpenAI pricing guide.
How do I handle a real rate limit (429)?
- Read the
Retry-Afterheader when present and wait at least that long. - Back off exponentially with jitter: 1s, 2s, 4s, 8s, plus a random fraction.
- If you see OpenAI’s
slow_downerror: above 1M TPM, OpenAI asks you to ramp traffic up by no more than 50% per 15 minutes. - Long term, cache prompt prefixes, batch offline work and request a higher tier.
What is Claude’s 529 error, and how is it different from 429?
As one developer put it on X, 529 “means Anthropic’s API is temporarily overloaded, so you wait a bit and retry. A 429 looks similar and isn’t. It’s about you: your rate limit” (@waldekm). That matches Anthropic’s errors page. One extra trap: when you hit your tier’s monthly spend cap, the 429 has no retry-after, because waiting minutes will not help.
Is there a retry snippet I can copy?
import random, time
RETRYABLE = {429, 500, 503, 504, 529}
BILLING = {"insufficient_quota", "credit_balance_exhausted",
"organization_spend_limit_exceeded", "project_spend_limit_exceeded"}
def call_with_retry(send, max_tries=6):
for attempt in range(max_tries):
r = send()
if r.status_code < 400:
return r
err = (r.json().get("error") or {}) if r.content else {}
if r.status_code not in RETRYABLE or err.get("code") in BILLING or err.get("type") in BILLING:
r.raise_for_status() # fix the request or the account
wait = float(r.headers.get("retry-after", 0)) or min(60, 2 ** attempt)
time.sleep(wait + random.random())
r.raise_for_status()
Tools that skip this step simply crash on the first 429 or 503; one developer built a wrapper for exactly that reason (@topjohnwu). The official Anthropic SDKs already retry twice by default.
What else should I check?
- 403 on OpenAI: the request comes from an unsupported country or region. Use a server in a supported location; do not route around it with a shared account.
- Claude 413: split large files or use the Files API.
- Long Claude requests timing out (504): switch to streaming.
Still stuck setting up keys? See how to get a Claude API key, or browse the AI API hub.
FAQ
What does insufficient_quota mean?
Your OpenAI organization or project is out of paid credit or has hit a spend or usage limit. It comes back as a 429, but retrying will not help; add credit or raise the limit in the billing settings.
What is the difference between 429 and 529 on the Claude API?
429 rate_limit_error means your own account hit a rate or spend limit. 529 overloaded_error means Anthropic's API is temporarily overloaded for everyone; wait and retry.
Why do I get 401 with a valid OpenAI key?
OpenAI lists several 401 causes: an incorrect or revoked key, a key that is not a member of the organization you specified, or a request from an IP address that is not on the project's allow list.
Should I retry 400 errors?
No. 400 means the request itself is wrong (bad parameter, too many tokens, or on Claude a reached spend limit). Fix the request instead.
Does the Anthropic SDK retry automatically?
Yes. Anthropic's official SDKs retry failed requests twice by default with backoff, which covers most 429, 500 and 529 errors.
Sources
- OpenAI API: Error codes (accessed 2026-10-18)
- OpenAI API: Rate limits (accessed 2026-10-18)
- Anthropic: API errors (accessed 2026-10-18)
- GitHub: openai/openai-python README (status code to error type) (accessed 2026-10-18)