All posts

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.

CodeKrypt 7 min read

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.

Three details catch teams out:

  1. 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.
  2. 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.
  3. Not every 429 is temporary. Anthropic's docs say that reaching a monthly spend cap returns a 429 of type rate_limit_error without 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:

Retries also duplicate side effects in agent workflows; see AI agent retries and idempotency before adding retries around tool calls.

Retry, queue or shed load: which response fits?

SituationBest responseWhy
Occasional single 429 on a user-facing callBackoff with jitter, 2–3 attemptsCheap, usually clears quickly
Sustained 429s from background jobsQueue with a concurrency capSmooths bursts instead of fighting them
One tenant flooding a shared keyPer-tenant budget, reject or delay that tenantProtects everyone else
Provider overloaded (5xx) or long outageFail over to another model or providerWaiting will not help; see fallback providers
Spend-cap 429, no retry-afterAlert a human, stop retryingRetries fail until the cap resets or is raised
Non-urgent bulk workBatch APISeparate limits from your live traffic

What does a resilient architecture look like?

Requests pass through a per-tenant limiter and a priority queue with a concurrency cap before reaching the LLM API, with backoff on 429 responsesApp requestsPer-tenantbudget checkPriority queue+ concurrency capLLM API429 → wait Retry-After + jitter, requeueover budget → reject early

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:

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?

  1. Measure tokens per request for your real prompts: p50 and p95, input and output separately.
  2. Estimate peak concurrent users, not average. Multiply by requests per user action; agents can make many calls per action.
  3. 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.
  4. Leave headroom. Anthropic's docs describe limits as maximums, "not guaranteed minimums."
  5. Load-test with the queue in place, ramping gradually to avoid acceleration limits that a synthetic spike would trigger.
  6. 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

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 avatar

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.

Related reading

Chat on WhatsApp