LLM API rate limits and 429 errors: queueing, backoff and capacity planning
Hitting 429s from an LLM API in production? How rate limits really work, why naive retries make it worse, and how to build queues, backoff and per-tenant budgets that hold up.
Your demo handled ten users. Launch day brings a few hundred, and the logs fill
with 429 Too Many Requests. LLM API rate limits and 429 errors are one of
the first production problems an AI product hits, and the instinctive fix,
wrapping the call in a retry loop, often turns a brief spike into a prolonged
outage.
This post covers how provider limits actually work, what to do when you hit
them, and how to design so you hit them rarely. It is about the domain, not
any specific deployment of ours; all provider facts come from the public docs
linked inline, and limits change, so check your own console for current numbers.
How do LLM API rate limits actually work?
Limits are not a single number. Both major providers meter several dimensions
at once and reject you when any of them runs out.
OpenAI meters RPM, requests per day, tokens per minute, tokens per day
and more, and says limits can be hit "across any of the options depending on
what occurs first." Limits apply at organisation and project level and vary
by model.
Three details catch teams out:
Short windows. Anthropic notes a 60 RPM limit might be enforced as one
request per second, so a burst can trigger errors even when your per-minute
average is fine. It uses a token bucket, so capacity replenishes
continuously rather than resetting on the minute.
Growth rate counts. Anthropic warns of "acceleration limits" after a
sharp usage increase, and OpenAI documents a slow_down 429 that can occur
even within RPM and TPM limits. Ramp traffic gradually.
Not every 429 is temporary. Anthropic's docs say that reaching a monthly
spend cap returns a 429 of type rate_limit_errorwithout a
retry-after header, and retries fail until access resumes. Your retry
logic must tell the two apart (Anthropic exposes enforced_spend_limit_reached
in the error details).
Why do naive retries make 429s worse?
OpenAI's guidance is blunt: unsuccessful requests contribute to your per-minute
limit, so "continuously resending a request won't work." Picture 200 requests
failing at once, each retrying after a fixed one second. You have just built a
synchronised wave that hits the limit again, and again.
The documented fix has three parts:
Honour Retry-After when present. OpenAI treats it as a minimum and
recommends adding a small random delay. Anthropic says earlier retries fail.
Otherwise use exponential backoff with random jitter, so clients spread out.
Cap both the attempts and the total retry time. An unbounded retry loop
holds a user's request open and a worker busy while the system is already
struggling.
Retries also duplicate side effects in agent workflows; see
AI agent retries and idempotency
before adding retries around tool calls.
The components, in the order a request meets them:
1. A per-tenant budget check. On a shared API key, one heavy customer can
exhaust the limit for everyone. Enforce per-customer caps before the request
ever reaches the provider. We cover the design in
usage limits per customer for AI SaaS.
2. A priority queue with a concurrency cap. Interactive chat should jump
ahead of nightly summarisation. Cap in-flight calls below your limit so bursts
wait in your queue, not in a retry storm. Your queue is also the natural place
to apply the Retry-After delay: requeue the job with a not-before time rather
than sleeping in a worker.
3. Header-aware pacing. Both providers return the remaining budget on every
response: Anthropic's anthropic-ratelimit-*-remaining and -reset headers,
OpenAI's x-ratelimit-remaining-requests and x-ratelimit-remaining-tokens.
Reading them lets you slow down before the 429 rather than after.
4. Estimating tokens up front. Token limits are what bite long-context and
agent workloads, not RPM. Anthropic notes ITPM is estimated at the start of a
request and adjusted as it completes, so a few huge prompts can consume a
minute's budget. Count tokens before sending and queue large jobs separately.
5. Fallbacks for the unrecoverable cases. Backoff cannot fix a capacity
problem that lasts an hour. Route to a secondary model when the queue wait
exceeds what the product can tolerate.
How can you use fewer tokens per minute in the first place?
The cheapest rate-limit fix is not sending the tokens. Two documented levers:
Prompt caching. Anthropic states that its default ITPM limits count only
uncached input: cache_read_input_tokens do not count toward ITPM. Its own
example: with a 2,000,000 ITPM limit and an 80 percent cache hit rate you can
process 10,000,000 total input tokens per minute. That is a vendor example,
not a promise for your workload; your hit rate decides it. Our guide to
prompt caching covers how to structure
prompts to get hits. OpenAI's limits are described differently, so check how
cached tokens count under your own model's limits.
Batch APIs. OpenAI's docs say the Batch API lets you run large
collections of requests without impacting your synchronous rate limits, and
Anthropic's Message Batches API has its own separate limits. Move evals,
backfills and overnight enrichment there.
Beyond that, the general cost levers in
reducing LLM API costs (smaller models for easy
steps, shorter prompts, fewer agent turns) all reduce rate-limit pressure too.
How do you plan capacity before launch?
Measure tokens per request for your real prompts: p50 and p95, input and
output separately.
Estimate peak concurrent users, not average. Multiply by requests per
user action; agents can make many calls per action.
Compare against your tier's RPM, ITPM and OTPM for the exact model, using
the numbers in your provider console. Tiers and limits differ by model and
change over time.
Load-test with the queue in place, ramping gradually to avoid
acceleration limits that a synthetic spike would trigger.
Alert on queue depth and 429 rate, and separately on spend-cap proximity.
If the numbers say you need more, request a tier increase early;
Anthropic places organisations on tiers based on usage history, so higher
limits may not be available the day before launch.
What to do next
Classify your 429s today: temporary rate limit, acceleration, or spend cap.
Replace fixed-delay retries with Retry-After plus jittered backoff and a hard cap.
Put a queue with a concurrency limit and per-tenant budgets between your app
and the provider.
Move non-urgent work to a batch API and fix prompt structure for caching.
If you are building a multi-tenant AI product and want this layer designed in
from the start, that is the work behind our AI SaaS service, linked below.
CodeKrypt
Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write
Frequently asked questions
What does a 429 error from an LLM API mean?
The request exceeded a temporary rate limit: requests per minute, tokens per minute, or a limit on how fast your traffic grew. Wait for the Retry-After value when the response includes one, then retry. A 429 can also mean you hit a monthly spend cap, and that one will not clear by waiting.
Should I retry immediately after a 429?
No. Both OpenAI and Anthropic document that you should wait at least the Retry-After time. OpenAI also notes that failed requests count toward your per-minute limit, so tight retry loops make the problem worse.
How do I avoid rate limits without buying a higher tier?
Smooth your traffic with a queue, cache repeated prompt prefixes (on Anthropic, cached reads do not count toward input-tokens-per-minute), and move non-urgent work to a batch API, which has separate limits.
Do I need a queue in front of the LLM API?
Once you have background jobs, agents running parallel steps or more than one tenant sharing a key, yes. A queue is where you enforce concurrency, priorities and per-customer budgets in one place.
Self-hosting an open-weight LLM looks cheaper per token, until utilisation, engineering time and quality are counted. A break-even method you can run with your own numbers.
One heavy tenant can erase the margin on a flat-priced AI feature. How to meter LLM usage per customer, set limits at the right layer, and choose a pricing shape that survives power users.
LLM model deprecation is a recurring cost, not an incident. What provider notice periods actually look like, what breaks besides the model name, and a migration plan built on evals.