esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Letโ€™s talk

Iโ€™ll build the agent for it.

How Do You Handle Rate Limits and 429 Errors?

What a 429 error means, how to retry it safely and how to stay under the limit, explained simply for your AI interview.

In short

A 429 error means your app has sent too many requests or tokens in a short window. Wait the time the Retry-After header gives, or back off with random waits under a growing ceiling, cap the retries, and keep your own traffic under the limit.

12 min readIntermediateCommon ยท estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A 429 means I've sent too many requests or tokens in a short time. First I read the Retry-After header and wait that long. If there's no header, I back off: each try gets a higher ceiling, and I pick a random wait under it, so many failed jobs don't retry together. I cap the tries, and I keep my own traffic under the limit. A spend cap is different: retrying won't help until someone raises it.

What is a 429 error, in plain words?

A 429 is the provider's way of saying: too many requests, slow down. Model APIs (the doors your code uses to call the AI) cap how many requests, input tokens and output tokens (small chunks of text the model reads and writes) one organisation can use in a time window, for each model. Go over a cap and you get a 429 back instead of an answer. A 429 is about how much you send per minute, so a very long prompt can use up the token limit too.

Think of a claims desk that can take 60 calls a minute. The 61st caller gets a busy tone. Redialling in a tight loop only jams the line for everyone, so the sensible move is to wait a little and call back.

Here is a made-up case with a realistic shape. An insurer's claims agent reads 800 claim files after a storm, and the provider starts sending 429s halfway through. The team has to finish every file, without losing any and without hammering the API.

Key words

Rate limit
The cap on requests, or tokens, that you can send in a time window.
429
The standard web reply code for too many requests. It means try again later.
Retry-After
A header in the reply saying how many seconds to wait before retrying.
Backoff
Waiting longer after each failed try, instead of trying at once.
Jitter
A random wait picked below each ceiling (the longest wait allowed for that try), so many clients don't retry together.

What kinds of limit send a 429?

  • Rate

    Too many per minute

    A cap on requests per minute, and on input and output tokens per minute, for each model.

  • Sudden jump

    Too fast, even under the cap

    A sharp rise in use can get a 429 while the minute total still looks fine.

  • Spend cap

    Monthly money limit reached

    Waiting does not help. The 429 keeps coming until the limit resets or someone raises it.

Bursts matter as much as totals. Anthropic's docs give a simple case: 60 requests a minute might be enforced as one request a second, so a short burst fails even when the minute looks fine. OpenAI says the same kind of thing: a slow_down error can come even when you are inside the per-minute limits.

Azure's docs warn that a 429 can arrive even while your usage shows below your quota. So the dashboard total is not the whole story, and the error reply is the thing to read.

What happens when a request hits a limit

Your claim request

one claim summary to the model

Provider API

counts requests and tokens per minute

What comes back

Answer

under the limit, so it goes through

429 Too many requests

over a limit, so it says wait

Your code waits

Read Retry-After

wait the seconds it gives

Back off with jitter

random wait, under a growing ceiling

  1. 1Your app sends one request to the provider.
  2. 2The provider answers within its limits, so the claim moves on.
  3. 3Over a limit, the provider sends back a 429 instead.
  4. 4Your code reads the Retry-After header first.
  5. 5Only when there is no header, it picks a random wait under a growing ceiling.
Your request goes to the provider, which answers within its limits. Over a limit it returns a 429, and your code reads Retry-After, or backs off with a random wait. Nothing retries the same call with no wait.

How do you retry a 429 safely?

  1. 1

    Read Retry-After first

    If the reply has a Retry-After header, wait that many seconds, the number the provider gives.

  2. 2

    No header? Back off

    Double the ceiling after each failed try, up to a maximum, so the load falls away instead of piling on.

  3. 3

    Add jitter

    Pick a random wait under each ceiling. Without the randomness, a thousand jobs that failed together retry together and fail together again.

  4. 4

    Cap the attempts

    Stop after a few tries, log the claim ID, and put the work on a retry queue. An endless loop turns a slow API into an outage.

  5. 5

    Never retry a spend cap

    Check the error code first. A monthly cap needs someone to raise it, or a new month to start.

  • โ€œWhen the response has a retry-after header, wait that many seconds before retrying.โ€

    Anthropic

  • โ€œFollow Retry-After when it's present, reduce your request rate, and then increase it gradually.โ€

    OpenAI

  • โ€œImplement a retry strategy by using truncated exponential backoff.โ€

    Google Cloud

Many SDKs, the ready-made code libraries vendors give you, do some of this for you. Anthropic's SDK retries a failed request twice by default, and without a Retry-After it waits from half a second up to eight seconds. AWS's architecture team found that adding jitter cut both the client work and the load on the server a lot. You still need to read the error code, because retrying a spend cap only fails again.

Here is a small version in plain Python. The provider is made up, and the code prints each wait instead of sleeping, so it runs at once.

Python
import random

random.seed(7)  # same numbers on every run

def full_jitter(attempt, base=1.0, cap=8.0):
    # A random wait up to a doubling cap, so many clients don't retry at the same moment.
    return random.uniform(0, min(cap, base * 2 ** attempt))

def provider(attempt):
    # Made-up provider: over its limit for the first three tries, then it answers.
    return 429 if attempt < 3 else 200

def send_claim(retry_after=None):
    for attempt in range(6):
        if provider(attempt) == 200:
            return f"attempt {attempt + 1}: answered"
        # Obey Retry-After when the provider sends it; otherwise back off with jitter.
        wait = retry_after if retry_after is not None else full_jitter(attempt)
        print(f"attempt {attempt + 1}: 429, wait {wait:.2f} s")
    return "gave up after 6 attempts"

print(send_claim())
print(send_claim(retry_after=2))

Output

attempt 1: 429, wait 0.32 s
attempt 2: 429, wait 0.30 s
attempt 3: 429, wait 2.60 s
attempt 4: answered
attempt 1: 429, wait 2.00 s
attempt 2: 429, wait 2.00 s
attempt 3: 429, wait 2.00 s
attempt 4: answered

The first call has no header, so each wait is a random time under a ceiling that doubles with each try. In this run the second wait (0.30 s) came out shorter than the first (0.32 s). The second call gets a Retry-After of 2 seconds and obeys it every time. Either way the loop stops as soon as the call succeeds, and never runs more than six tries.

How do you stay under the limit in the first place?

  • Cap concurrency

    Limit how many calls run at the same time (concurrency), with a queue in front of the API. Ten workers, not a thousand.

  • Spread the bulk work

    Run batch jobs at a steady rate, not all at once. Google's advice is similar for pay-as-you-go models: if your model uses Standard pay-as-you-go, smoothing traffic and reducing large spikes can help.

  • Cache the repeated text

    Cache reads do not count toward Anthropic's input token limit, so a policy document read thousands of times uses far less of your allowance.

  • Use the batch lane for offline work

    Batch processing has its own limits, shared across all models. Overnight work does not spend the live chat's allowance.

  • Split the budget by workspace

    Anthropic lets you set spend and rate limits for each workspace, so one team's job can be kept from using up the whole organisation's allowance.

Worked example, with made-up numbers. Say the provider allows 300 requests a minute for the claims agent. If 800 files hit it in one burst, about 500 of them get a 429 in the same minute. Spread evenly at 250 a minute instead, the same 800 files take a little over three minutes, and none fail.

How would you run 50,000 summaries overnight without breaking live chat?

Give the batch job its own lane. Run the summaries at a steady rate in the background, with a retry queue. Keep live chat on its own budget, so a heavy night never blocks a customer at 9 a.m.

  • Without a plan

    One shared budget

    The batch uses most of the allowance, and live chat starts getting 429s when people log in.

  • With a plan

    Two lanes

    The batch runs slowly in its own workspace, chat keeps its share, and both retry with Retry-After.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: a 429 means too many requests or tokens in a time window.
  • Read Retry-After first, then back off with jitter.
  • Cap the retries and queue the work, so nothing loops forever.
  • Keep your own traffic under the limit: concurrency, spreading, caching.
  • Know the spend cap: retrying will not clear it.
  • Watch how close you run to the limit and how often 429s happen, in production dashboards, not only in the logs.

Common traps

  • Trap"Just retry in a loop until it works."

    BetterA loop with no wait adds load to an API that is already saying slow down. Wait, add jitter, and stop after a few tries.

  • Trap"A 429 means my code has a bug."

    BetterOften it is the shape of the traffic, or prompts that are too long. Look at bursts, concurrency and prompt length before you blame the code.

  • Trap"A bigger tier fixes it."

    BetterA higher limit helps, but a burst still fails at any limit. Smooth the traffic too.

Can you spot the risky fix?

Spot the risky fix

Your claims agent gets a 429 on every call. Which fix is safest to ship first?

Quick check

A 429 arrives with no Retry-After header, and the error says the monthly spend cap is reached. What should the code do?

Can you answer these from memory?

Flash cards ยท tap a card to flip it

1 / 6

What will they ask next?

  1. Q331When do you use batch APIs?9 min
  2. Q337Timeouts, retries and backoff?14 min
  3. Q326Prompt cache vs semantic cache vs KV cache?13 min
  4. Q324How do you estimate token cost for a feature?11 min
  5. Q334How do you cut cost on a cloud-hosted LLM workload?13 min

Last updated on 27 November 2026

Building a claims or support bot that cannot drop requests?

I design and build AI agents and the systems behind them, including the queues, retries and limits that keep them running. Book a short call and tell me what yours needs to do.