Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 96/ 160
05. AI System Design

Provider Rate Limits

RPM/TPM quotas, backoff strategies, and multi-key/multi-provider fan-out.

BeginnerRPM/TPM · Backoff3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

The AI provider only lets you ask so many questions, or send so many words, per minute, so your app has to pace itself and wait politely when it hits the limit.

Think of it like…

A toll bridge that lets a fixed number of vehicles and total weight through per minute: a smart driver paces arrivals, takes a second bridge when one is full and doesn't all queue up to honk the moment the gate reopens.

Where you’ve seen it

An assistant has a limit of 10,000 requests per minute and 2,000,000 tokens per minute. Each request uses 3,100 input and 420 output tokens (3,520 total), so RPM allows 10,000 requests but TPM allows only 2,000,000 ÷ 3,520 = 568 requests a minute (9.5 a second): TPM is the binding limit. Peak demand is 15 requests per second (900 a minute), 332 a minute more than the quota. Options: trim retrieved context so each request averages 2,620 tokens (763 requests a minute), cache and route easy queries to a second model with its own quota, add a second provider (2 × 568 = 1,136 requests a minute covers 900), request a higher tier, or queue non-urgent traffic for the batch API. A client-side token bucket sized to 80% of the limit paces calls, reserving max_tokens in advance; the concurrency cap is 9.5 requests per second × 3.4 s ≈ 32 in flight. A 429 is retried with full-jitter backoff honouring Retry-After, with a retry budget of 10%.

Words you’ll hear

RPM and TPM
Requests per minute and tokens per minute quotas, whichever is hit first binds.
429 and Retry-After
The 'too many requests' status and the header telling you how long to wait.
Token bucket
A limiter that refills at a fixed rate and lets calls through only when enough tokens are available.
Retry budget
A cap on the share of traffic that may be retries so failures don't amplify load.

Visual diagram

Loading interactive diagram

Theory & deep dive

Understanding and measuring the limits

Limits vary by provider, model and account tier, and are often expressed as RPM, TPM (sometimes separate input and output TPM) and sometimes concurrency or daily token caps. The binding limit depends on request size: with 3,520-token requests and limits of 10,000 RPM and 2,000,000 TPM, TPM allows only 568 requests a minute, so TPM binds. Providers differ in how they count tokens (some count the requested max_tokens against the limit at admission, then adjust; some count only actual usage), so check the documentation, read the rate-limit headers returned on each response (remaining requests and tokens, reset times; names vary) and log them.

Plan capacity from peak, not average: peak requests per second × tokens per request × 60 versus TPM, with headroom (target about 70% to 80% of the quota). Shrinking tokens per request (prompt trimming, prefix caching on providers where cached tokens count less, output caps) raises effective throughput at no extra quota. Remember per-model limits (a router that moves easy traffic to a small model also moves it to a different quota), organisation-wide limits shared by all your services (a nightly backfill can starve production) and limit increases that follow spend tiers or a request to the provider.

Which limit binds

Limits: 10,000 RPM and 2,000,000 TPM. Request size 3,520 tokens. RPM allows 10,000/min; TPM allows 2,000,000 ÷ 3,520 = 568/min. The effective limit is 568 requests per minute (9.5 per second), well below the RPM figure.

Key takeaway: Compute the binding limit from request size, read the headers and plan capacity from peak with headroom.

Client-side control, retries and fan-out

Put a client-side limiter in front of the provider: a token bucket with capacity and refill rate set to about 80% of the quota (separate buckets for requests and tokens), where each call acquires its estimated tokens (input plus reserved output) before sending and releases any unused reservation afterwards. A concurrency semaphore sized by Little's law (request rate × duration, here 9.5 × 3.4 ≈ 32) prevents a latency spike from piling up in-flight calls. A shared limiter service (Redis, or a gateway such as LiteLLM or an internal proxy) keeps multiple application instances inside one global budget, with priority classes so interactive traffic is served before bulk work and per-tenant sub-limits.

When a 429 or a 5xx occurs, retry with full-jitter exponential backoff, honour Retry-After, cap attempts (2 or 3) and keep a retry budget so retries stay under about 10% of traffic. Fan-out options: distribute across models (each has its own limits), regions or projects where the provider allows per-project quotas, and multiple providers. Note that creating many API keys under the same organisation usually does not multiply limits, and attempting to evade quotas through extra accounts can violate terms, so use legitimate means: tier upgrades, committed-use agreements and provisioned throughput. Move non-urgent work to batch APIs, shed or degrade low-priority requests under pressure and alert on the 429 rate, queue wait times and the fraction of requests delayed by the limiter.

Full-jitter backoff

Base 0.5 s, cap 8 s. Attempt n waits random(0, min(8, 0.5 × 2ⁿ)) unless Retry-After says longer. Thousands of workers hitting a 429 at once spread their retries over seconds instead of returning in one synchronised wave.

Key takeaway: Limit locally with token buckets, retry with jitter and budgets, and fan out through legitimate quota channels.

How it works, step by step

Step 1 of 4
Engineering

1. Find the binding limit

Convert RPM and TPM to requests per minute for your request size; read rate-limit headers and log them.

TPM binds: 568 req/min vs RPM 10,000
Key numbers at this step
Peak
not average

When to use it & trade-offs

What it is

LLM providers cap usage with rate limits, typically requests per minute (RPM) and tokens per minute (TPM) (sometimes split into input and output tokens), plus concurrency and daily quotas, applied per organisation or project and per model. Exceeding a limit returns HTTP 429 (often with a Retry-After header). Handling them well means measuring your real constraint (usually TPM, not RPM), limiting client-side with a token bucket so you rarely hit 429s, retrying with exponential backoff and jitter, queuing and prioritising work, spreading load across models, projects or providers where the terms allow, and using batch tiers for bulk work.

Why it matters: Rate limits turn traffic spikes and batch jobs into user-visible errors and retry storms. A burst of retries multiplies load right when the provider is rejecting you, and an agent loop or backfill can starve interactive traffic. Capacity planning for an AI feature includes quota planning: whether the tokens per minute you're allowed can serve your peak, and what degrades gracefully when it cannot.

When to reach for it

  • Capacity planning for AI features
  • Protecting interactive traffic from bulk jobs
  • Designing retry and fallback behaviour

When to avoid or be careful

  • Retrying 429s immediately
  • Assuming RPM is the limit that matters
  • Using many keys in one organisation expecting extra quota

Ways to get more throughput under limits

Reduce tokens per request
Best for: Immediate quota relief without new contracts

Strengths: Also cuts cost and latency.

Watch out: May reduce context quality.

Add models or providers
Best for: Resilience and extra quota

Strengths: Independent limits and failover.

Watch out: Prompt portability and compliance work.

Higher tiers or provisioned throughput
Best for: Predictable large workloads

Strengths: Higher guaranteed limits.

Watch out: Commitment and cost.

Interview signals & numbers to know

When this topic comes up

  • “We get 429 errors at peak”
  • “Backfill broke production”
  • RPM versus TPM
  • Retry-After header
  • Token bucket limiter

Benchmarks & rules of thumb

2,000,000 ÷ 3,520 = 568 -
requests per minute allowed by TPM
80% -
target share of the quota for client-side limits
≤ 10% -
retry budget as a share of traffic

Common mistakes & follow-ups

Common interview mistakes

  • Letting a nightly job share the quota with production without priorities.
  • Ignoring max_tokens in token estimates and being throttled unexpectedly.
  • Synchronised retries that cause a thundering herd.

Likely interviewer follow-ups

  • How would you design around provider rate limits?
  • Why is TPM usually the binding limit?
  • How does jitter help?
Interview tip: Convert limits to requests per minute for your own request size. It reveals the binding limit and the shortfall at peak in one calculation.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Provider Rate Limits with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Async Job Pipelines
Next topic
Multi-tenant Design