Skip to content
FR
  1. LuzineDebug
  2. AI & LLMs
  3. RateLimitError: Error code: 429 - Rate limit rea…
AI & LLMs Intermediate ≈ 20 min to fix

Fix error 429 "Rate limit reached" on OpenAI, Claude and Gemini APIs

Error message
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
In short

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.

Be the first to confirm this fix

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

  1. Burst of parallel requests: an asyncio.gather or Promise.all loop fires hundreds of calls at once and goes over RPM or TPM.
  2. Requests that are too large: long prompts and a high max_tokens burn through the tokens-per-minute limit quickly, even with few requests.
  3. Credit exhausted or spend cap reached: insufficient_quota at OpenAI, spend limit at Anthropic, free tier at Gemini. Retries keep failing until you add credit or change tier.
  4. Low usage tier: new accounts get low limits, which rise automatically with cumulative spend.
  5. Provider-side overload: 529 overloaded_error at Anthropic or 503 elsewhere, regardless of your usage.

Step-by-step fix

  1. Identify the exact error type

    Read the JSON body of the response. rate_limit_exceeded or rate_limit_error: temporary rate limit, retry later. insufficient_quota: no credit left, fix billing. overloaded_error (529): service overload, retry with a longer delay.

  2. Read the limit headers

    The 429 response includes retry-after (seconds to wait). OpenAI adds x-ratelimit-remaining-requests, x-ratelimit-remaining-tokens and x-ratelimit-reset-tokens. Anthropic adds anthropic-ratelimit-requests-remaining, anthropic-ratelimit-input-tokens-remaining and anthropic-ratelimit-output-tokens-remaining. They tell you which limit you hit.

  3. 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 (maxRetries in JavaScript).

    python
    from anthropic import Anthropic
    from openai import OpenAI
    
    anthropic_client = Anthropic(max_retries=5)
    openai_client = OpenAI(max_retries=5)
  4. Write your own backoff if needed

    For fine control over delays, honour retry-after when present, otherwise double the wait on each attempt and add some randomness (jitter) so your workers do not all restart at once.

    python
    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)
  5. Cap the number of concurrent requests

    A semaphore caps in-flight calls. Start low (4 to 8) and increase while no 429 shows up.

    python
    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))
  6. Use fewer tokens per minute

    Lower max_tokens to 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.

  7. 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_quota or 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 ratelimit headers 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

More AI & LLMs errors

All AI & LLMs errors →