Fix error 429 "Rate limit reached" on OpenAI, Claude and Gemini APIs
RateLimitError: Error code: 429 - Rate limit reached for requests (rate_limit_exceeded)
- Rate limit reached for gpt-4o in organization org-xxx on tokens per min (TPM): Limit 30000, Used 28500, Requested 4000. Please try again in 5s.
- You exceeded your current quota, please check your plan and billing details. (insufficient_quota)
- anthropic.RateLimitError: Error code: 429 - {'type': 'error', 'error': {'type': 'rate_limit_error', ...}}
- Error code: 529 - {'type': 'error', 'error': {'type': 'overloaded_error', 'message': 'Overloaded'}}
- 429 RESOURCE_EXHAUSTED
The provider rejects the request because you are over a rate limit: requests per minute (RPM) or tokens per minute (TPM). Wait for the delay given by the retry-after header, retry with exponential backoff and cap the number of concurrent requests. If the message mentions quota or billing, retrying will not help: you need to add credit.
What this error means
Every LLM API account has per-model limits measured over a rolling window: requests, input tokens and output tokens per minute, sometimes a monthly spend cap. As soon as a request would exceed one of them, the API returns HTTP 429 instead of processing it. The OpenAI SDK raises RateLimitError (code rate_limit_exceeded, or insufficient_quota when credit is exhausted), the Anthropic SDK raises RateLimitError with type rate_limit_error, and Gemini returns RESOURCE_EXHAUSTED. At Anthropic, the 529 overloaded_error code is different: the API itself is overloaded, not your quota.
Common causes
- Burst of parallel requests: an
asyncio.gatherorPromise.allloop fires hundreds of calls at once and goes over RPM or TPM. - Requests that are too large: long prompts and a high
max_tokensburn through the tokens-per-minute limit quickly, even with few requests. - Credit exhausted or spend cap reached:
insufficient_quotaat OpenAI, spend limit at Anthropic, free tier at Gemini. Retries keep failing until you add credit or change tier. - Low usage tier: new accounts get low limits, which rise automatically with cumulative spend.
- Provider-side overload: 529
overloaded_errorat Anthropic or 503 elsewhere, regardless of your usage.
Step-by-step fix
-
Identify the exact error type
Read the JSON body of the response.
rate_limit_exceededorrate_limit_error: temporary rate limit, retry later.insufficient_quota: no credit left, fix billing.overloaded_error(529): service overload, retry with a longer delay. -
Read the limit headers
The 429 response includes
retry-after(seconds to wait). OpenAI addsx-ratelimit-remaining-requests,x-ratelimit-remaining-tokensandx-ratelimit-reset-tokens. Anthropic addsanthropic-ratelimit-requests-remaining,anthropic-ratelimit-input-tokens-remainingandanthropic-ratelimit-output-tokens-remaining. They tell you which limit you hit. -
Raise the SDK’s automatic retries
The official OpenAI and Anthropic SDKs already retry 429 and 5xx errors with exponential backoff, 2 times by default. Simply raise
max_retries(maxRetriesin JavaScript).from anthropic import Anthropic from openai import OpenAI anthropic_client = Anthropic(max_retries=5) openai_client = OpenAI(max_retries=5) -
Write your own backoff if needed
For fine control over delays, honour
retry-afterwhen present, otherwise double the wait on each attempt and add some randomness (jitter) so your workers do not all restart at once.import random import time import anthropic client = anthropic.Anthropic(max_retries=0) # retries handled below def create_with_backoff(max_attempts=6, **kwargs): for attempt in range(max_attempts): try: return client.messages.create(**kwargs) except anthropic.APIStatusError as e: if e.status_code not in (429, 529) or attempt == max_attempts - 1: raise retry_after = e.response.headers.get("retry-after") delay = float(retry_after) if retry_after else min(60, 2 ** attempt) + random.random() time.sleep(delay) -
Cap the number of concurrent requests
A semaphore caps in-flight calls. Start low (4 to 8) and increase while no 429 shows up.
import asyncio from anthropic import AsyncAnthropic client = AsyncAnthropic(max_retries=5) sem = asyncio.Semaphore(4) async def ask(prompt: str) -> str: async with sem: msg = await client.messages.create( model="claude-opus-5-5", max_tokens=1024, messages=[{"role": "user", "content": prompt}], ) return "".join(b.text for b in msg.content if b.type == "text") async def main(prompts): return await asyncio.gather(*(ask(p) for p in prompts)) -
Use fewer tokens per minute
Lower
max_tokensto what you actually need, shorten prompts and cache the fixed parts (prompt caching). For non-urgent work, use the Batch API (OpenAI Batch, Anthropic Message Batches): it has its own limits and costs roughly half as much. -
Check quota, billing and tier
Open the limits page of your console (OpenAI Platform, Anthropic Console, Google AI Studio) to see per-model limits, remaining credit and your tier. On
insufficient_quotaor a reached cap, add credit or raise the spend limit.
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Route every LLM call through a queue or a shared semaphore instead of firing them freely.
- Log the remaining
ratelimitheaders so you slow down before hitting the limit. - Set up a billing alert so you do not discover an exhausted quota in production.
Frequently asked questions
Why do I get a 429 with only a few requests?
Limits also apply to tokens per minute: a few requests with long documents or a high max_tokens are enough. The 429 message says “requests” or “tokens” depending on which limit you hit.
What is the difference between 429 and 529 at Anthropic?
429 rate_limit_error means your organization is over its limits. 529 overloaded_error means the API is temporarily overloaded for everyone: retry later with backoff.
"You exceeded your current quota": should I wait?
No. This variant (insufficient_quota) means credit or the spend cap is exhausted. Add credit or raise the limit in the billing console.
Useful tools for this error
HTTP status codes
All the common HTTP codes (401, 403, 404, 419, 429, 500, 502…): meaning, causes and what to do.
JSON validator
Validate, format and minify JSON, with the exact line and column of the error.
Error finder
Paste an error message or a log: the tool recognises the error and opens the right fix.
More AI & LLMs errors
- Fix "maximum context length" and "prompt is too long" (context_length_exceeded)
- Fix "CUDA out of memory" in PyTorch
- Fix error 401 "Incorrect API key provided" / "invalid x-api-key"
- Fix "Torch not compiled with CUDA enabled" and torch.cuda.is_available() returning False
- Fix "could not connect to ollama" and connection refused on port 11434
- Fix "JSONDecodeError: Expecting value" when parsing an LLM response
- Fix "You are trying to access a gated repo" (401) on Hugging Face