How to Fix LLM API Rate Limit Errors (429)
LLM API error 429 Too Many Requests for beginners, on real APIs: why a script that worked a minute ago starts failing, what a rate limit counts (requests per minute, tokens per minute, requests per day), where each provider writes the wait time (a Retry-After header, the error body, a reset-time header), one retry function with exponential backoff and jitter that works with any provider, why workers that retry in step keep colliding, the retries your SDK already does, and how batching or pacing avoids the limit. Plus the daily-limit 429 that no retry fixes.

It worked a minute ago
Your script asks an LLM API to summarise twelve support tickets, and all twelve come back. Run it again, and five fail: 429, Too Many Requests.

By the end, you'll know what that error is counting, where it tells you how long to wait, and how to write one retry that works with any provider.

That was a real run, on Google's Gemini API. Your first instinct: send the failed ones again. So one question to keep: when can retrying make things worse?
python send.py1 200 OK 2 429 Too Many Requests 3 200 OK 4 200 OK 5 200 OK 6 429 Too Many Requests 7 200 OK 8 429 Too Many Requests 9 429 Too Many Requests 10 429 Too Many Requests 11 200 OK 12 200 OK summarised 7 of 12 tickets
The quick fix
First, the quick fix. When a request comes back 429, wait, then send the same request again. Wait about one second, then two, then four: doubling each time gives a busy API more room after every miss. Waiting longer after each miss like this is called backing off. Here's the same script with that retry, run while the limit is still used up. It waits a little under two seconds, not exactly one, and you'll see why later. Then it waits longer each time, and all twelve tickets are done in twenty-four seconds.
python retry.py1 200 OK 429: waiting 1.7 s 429: waiting 2.7 s 429: waiting 4.8 s 429: waiting 8.0 s 2 200 OK 3 200 OK 4 200 OK 5 200 OK 6 200 OK 7 200 OK 8 200 OK 9 200 OK 10 200 OK 11 200 OK 12 200 OK summarised 12 of 12 tickets in 24 s
That gets you through today. But the error comes back the day you add more tickets, or run a second copy of the script. And guessing the wait is slow. The API was already telling you how long to wait: you just have to know what it's counting, and where to look.

What 429 is counting
429 isn't a bug in your code. It's a standard HTTP status, added to the web's rulebook in 2012, and it means: too many requests in a given amount of time.
Picture a fairground ride with a bucket of five tickets at the gate. Every ride takes one ticket. A helper drops one new ticket in every second. Arrive when the bucket is empty, and the gate stays shut: come back in a moment.
An LLM API keeps several of these buckets for you. There's one for requests per minute, one for tokens per minute, and one for requests per day. Tokens are the small pieces of text the model reads and writes. Empty any one of them, and you get the same 429. On Gemini's free plan, the requests-per-minute bucket holds fifteen. Your first run took twelve. The second run arrived before the minute was over, and found it almost empty.
Find the wait time
So how long should you wait? Usually, the 429 itself tells you. To find where, we've made a small practice API that runs on your own laptop, with no key. The file practice.env points your script at it, instead of Gemini. Load it, and run the same script, unchanged. Its bucket holds five: five answers, then seven 429s.
source practice.env
python send.py1 200 OK 2 200 OK 3 200 OK 4 200 OK 5 200 OK 6 429 Too Many Requests 7 429 Too Many Requests 8 429 Too Many Requests 9 429 Too Many Requests 10 429 Too Many Requests 11 429 Too Many Requests 12 429 Too Many Requests summarised 5 of 12 tickets
This little ask script sends one request, and saves the reply in two files: one for the headers, one for the body. Every response starts with headers, which are short labelled lines. After them comes the main text, called the body. One of those headers matters here. It's called Retry-After, and its value is one: wait one second, then try again. And the body names the limit you hit.
./askHTTP/1.1 429 Too Many Requests
cat headers.txtHTTP/1.1 429 Too Many Requests Server: BaseHTTP/0.6 Python/3.12.3 Date: Wed, 02 Dec 2026 01:43:48 GMT Content-Type: application/json Content-Length: 144 Retry-After: 1
jq -r .error.message body.jsonRate limit reached: 5 requests at once, then one every 1 s.
The trouble is, not every provider puts the wait there. Back to Gemini's 429, saved the same way. Guess first: does it have a Retry-After header? No. Searching the saved headers finds zero lines with that name. Its wait is inside the error body instead: please retry in thirty-six seconds.
source gemini.env
./askHTTP/2 429
grep -ci retry-after headers.txt0
jq -c '.[0].error.details[] | select(.retryDelay)' body.json{"@type":"type.googleapis.com/google.rpc.RetryInfo","retryDelay":"36s"}
So where do you look? Most often, it's a Retry-After header. That's the web standard, and Claude's API uses it. Some, like Gemini, put it in the error body. Other services send the time the bucket refills, in a different header. We'll see one of those at the end. And sometimes there's no hint at all.

One retry, any provider
So your retry has to cope with all four, including no hint at all. Here's one function that does. If the answer isn't a 429, hand it straight back to your code. If there's a Retry-After header, wait exactly that long. If there's no header, as with Gemini, we don't try to read the body: every provider writes it differently, so this function plays it safe. It waits one second, then two, four, eight. Each time, it adds a small random extra. You'll see why soon. And after six tries, it gives up and shows the error.
Then the fix in your own loop is one line: where you called ask, call ask-with-retry instead.

On the practice API, it reads Retry-After and waits one second each time: twelve of twelve, in seven seconds.
python retry.py1 200 OK 2 200 OK 3 200 OK 4 200 OK 5 200 OK 429: waiting 1.0 s 6 200 OK 429: waiting 1.0 s 7 200 OK 429: waiting 1.0 s 8 200 OK 429: waiting 1.0 s 9 200 OK 429: waiting 1.0 s 10 200 OK 429: waiting 1.0 s 11 200 OK 429: waiting 1.0 s 12 200 OK summarised 12 of 12 tickets in 7 s
Now the question from the start: when can retrying make things worse? Remember that small random extra in our function? Take it out, and run twenty copies of your script at once: twenty workers. In this test they get no Retry-After, and they all arrive at the same moment: five get through, and fifteen find the bucket empty. Each one waits exactly one second, then two, then four. Guess first: what happens? They collide again. Every worker comes back in the same instant, and the bucket has only refilled a little. The last worker finishes after twenty-three seconds.

Now put the randomness back: each worker waits a random time, somewhere between zero and its doubled wait. That randomness is called jitter. Our retry function has its own: the small random extra you saw earlier. Same twenty workers: done in fifteen seconds, not twenty-three. It didn't reduce the refusals. It just stopped the workers from all coming back at the same instant, so each new ticket is taken as soon as it lands. Across three runs each, jitter finished sooner every time.
python workers.py same20 of 20 workers answered, last one after 23.1 s requests refused with 429: 52
sed -n '/wait = min/,/time.sleep/p' workers.pywait = min(8, 2 ** attempt) time.sleep(wait if MODE == "same" else random.uniform(0, wait))
python workers.py jitter20 of 20 workers answered, last one after 15.4 s requests refused with 429: 65
One thing before you write any of this yourself. The official library you install to call the API, called an SDK, may already retry for you. Our test script uses the OpenAI Python library, which can talk to the practice API too. It retries a 429 twice by default. Here's one call to an empty bucket. One answer comes back, but the practice API counted three requests. Two were refused, and you never saw them. So pick one: let the library retry, or turn its retries off and use your own. Both together multiply your requests.
cat sdk.pyimport os from openai import OpenAI client = OpenAI(base_url=os.environ["API_BASE"], api_key=os.environ["API_KEY"]) try: reply = client.chat.completions.create(model=os.environ["MODEL"], messages=[ {"role": "user", "content": "Summarise in five words: I was charged twice for November."}]) print(reply.choices[0].message.content) except Exception as e: print(type(e).__name__, getattr(e, "status_code", ""))
python sdk.pySummary: words: I was charged twice for November.
curl -s localhost:8080/{"requests": 3, "ok": 1, "limited": 2}
Send fewer requests
Retries get you through a limit. Better is not hitting it. Guess first: what's the smallest number of requests that can summarise all twelve? One. Put all twelve tickets in one prompt, as a numbered list, and ask for a numbered list back. One request, twelve summaries, from the real Gemini API. The catch: it's a bigger request, so it draws more from the tokens bucket.
sed -n '/^prompt = /,/^prompt += /p' batch.pyprompt = "Summarise each support ticket in five words. One line per ticket, same numbers.\n" prompt += "\n".join(f"{n}. {t}" for n, t in enumerate(tickets, 1))
python batch.py200 OK 1. Incorrect company name on invoice. 2. Password reset email missing. 3. Export button generates empty file. 4. Cancel subscription month end. 5. Mobile app keeps logging out. 6. Can I add second user? 7. Charged twice for November. 8. Dashboard slow since yesterday. 9. How to change billing address? 10. Uploaded photo appears sideways. 11. Need last year receipts. 12. Search fails for own name. 12 tickets, 1 request
So you have three ways to live with a limit. Retry is fastest here, because it only pauses when it's refused. Pacing means sending one request a second on purpose, so nothing is refused, but it's a little slower. And batching sends one request for the lot. Keep the retry either way, and batch when you have many small jobs.

When waiting won't help
Everything so far assumes the bucket refills in seconds. What if it won't refill until tomorrow? This is OpenRouter, one service that gives you many models, some of them free. We've used up today's free requests. Still 429, but read the message: free models per day. Its reset header holds a time: midnight UTC, about twenty-two hours away. Our retry waited, doubled, and after six tries, about a minute, it stopped. That's the six-try limit doing its job: it didn't keep retrying all day. For a daily limit, wait for the reset, switch model, or add credit.
./askHTTP/2 429
jq -r .error.message body.jsonRate limit exceeded: free-models-per-day. Add 10 credits to unlock 1000 free model requests per day: https://openrouter.ai/settings/credits?utm_source=api&utm_campaign=free_daily_limit
grep -i -E 'x-ratelimit|retry-after' headers.txtaccess-control-expose-headers: WWW-Authenticate,PAYMENT-REQUIRED,Payment-Receipt,PAYMENT-RESPONSE,Location,X-Generation-Id,x-openrouter-error-origin,x-openrouter-error-tool,X-Provider-Name,request-id,x-openrouter-subscription-passthrough,anthropic-ratelimit-unified-status,Retry-After,cf-ray x-ratelimit-limit: 50 x-ratelimit-remaining: 0 x-ratelimit-reset: 1796256000000
python retry.py429: waiting 1.0 s 429: waiting 2.7 s 429: waiting 4.1 s 429: waiting 8.4 s 429: waiting 16.7 s 429: waiting 32.5 s still 429 after 6 tries: {"error":{"message":"Rate limit exceeded: free-models-per-day. Add 10 credits to unlock 1000 free model requests per day: https://openrouter.ai/settings/credits?utm_source=api&utm_campaign=free_daily_
Recap
So: 429 means a bucket ran empty, not a bug. Find the wait: a header, or the body. Retry with doubling waits and jitter, and cap the tries. Send fewer, bigger requests. And if it says per day, stop retrying.

If your requests are getting answers again, a like helps YouTube show this to more beginners, and subscribing means the next error you hit may already have its video here.
The lab files and every command are linked in the description, practice API included, so you can try all of it without a key. Thanks for watching Cloud Explainers.
Sources
Demos: one container on our own Mac standing in for your laptop; the support tickets are made up. The practice API is our own small program with a real rate limit, so you can try every step without a key. Every command, output and number was real. Watch the full video on YouTube.