Token Rate Limits: One Bucket per Team, Reserve Input Plus Max Output, Refund the Rest
One bank's team pastes whole contracts every morning and by nine the shared quota is gone, so 500 small businesses get 429s. Give each of 40 teams a 40,000-token share of a 2 million TPM pool plus a 400,000 burst pool, reserve input plus max output before each call, and refund the rest after (synthetic numbers).
What you will learn
- Explain why tokens per minute (TPM) matter more than requests per minute (RPM) for an LLM
- Reserve input plus max output before a call and refund the unused part after
- Split one shared pool into guaranteed team shares plus a small burst pool
- Name the metrics and the failure test that prove one team's flood stays with that team
Before you start
- LLM Tokens, Context Windows and Cost
- Back Pressure for LLM Traffic
Many teams, one shared model, and one limit on how much text it can handle each minute. How do you share that fairly? A token is a small piece of text, roughly part of a word, and the model's limit is counted in tokens per minute. If you only count requests, one giant prompt can use up everyone's share.
One model, many customers
Our assistant answers support tickets for 500 small businesses and three banks, all on one platform, and it runs on one shared model. One bank's team pastes huge prompts every single morning: whole contracts, whole email threads, all in one go.
By nine o'clock the shared quota, the amount you're allowed to use, is gone. So the small businesses get a 429, the code for "too many requests". They did nothing wrong. One team's habit became everyone's outage.
Many teams share one model and one tokens-per-minute limit. Split it, and enforce it.
- Give each team a token share in its own bucket (a counter of tokens left), for each model.
- Before each call, reserve the input plus the max output, and refund the rest after.
- At the limit, queue or degrade (give a simpler answer), and tell the team why.
That's the 30-second answer: count tokens, not just requests.
A plan in gigabytes, not calls
Think of a mobile phone plan. A plan that only counted calls would be silly, because a short call and a huge download would count the same. That's requests per minute, RPM. Real plans are measured in gigabytes, because that's what really uses up the plan. That's tokens per minute, TPM.
And a family plan gives each person their own share of one pool. That's per-team quotas: one person streaming all day can't eat the whole family's data. Providers limit both RPM and TPM, so track both.
Reserve first, refund after
A request comes in with 3,000 input tokens. You estimate that with the model's tokenizer, the tool that splits text into tokens. The max output is 1,000, the most the reply is allowed to use.
So the team's bucket holds 3,000 + 1,000 = 4,000 tokens before the call starts. If the bucket doesn't have 4,000, the call doesn't start. The reply only uses 400, so the real cost is 3,400, and the extra 600 go back to the bucket for the team's next call.
Here is the same idea as pseudocode (an outline of the logic, not code from the lecture):
# pseudocode
need = count_tokens(prompt) + max_output # 3,000 + 1,000
if not bucket[team].take(need): # not enough left this minute
queue_or_degrade(team, reason="token share used")
else:
reply = call_model(prompt, max_tokens=max_output)
used = input_tokens + reply.output_tokens # 3,000 + 400
bucket[team].give_back(need - used) # 600
Shares inside one pool
Now put sizes on the shared pool (synthetic numbers). The model gives the whole org 2 million tokens per minute, shared by 40 teams. With no shares, ten prompts of 200,000 tokens each add up to 2 million, and the whole pool is gone in one burst.
So split it. Each team gets a guaranteed share of 40,000. Forty times 40,000 is 1.6 million. The other 400,000 stay as a shared burst pool for any team that needs a little more.
The bank's team can now use its own 40,000 plus the burst pool: 440,000. One big call reserves 200,000 input plus 1,000 max output, 201,000 tokens. So it fits only two big calls a minute, and the third one waits. The other 39 teams keep 1.56 million that nobody else can touch.
Counting the wrong thing
The trap weak candidates fall into is counting requests only. A huge prompt counts as one request, and the max output isn't counted at all, so one team's giant context can starve everyone else.
The strong answer counts tokens per team and reserves before each call. Then the big team waits, alone, and nobody else notices. The limit should protect the others, not punish them.
The numbers, and the failure test
- Headroom: free tokens per minute, and the share each team uses.
- 429s by cause, split into request limit and token limit, so you know which one is really biting.
- Reserve gap: reserved against actual tokens. If it's always large, max output is set too high and you're locking tokens nobody uses.
- Failure test: one team floods the model, and the other teams see no new 429s.
The follow-ups are all about sharing fairly:
- Why reserve first instead of charging after? Charging after lets many big calls start at once, and you blow past the limit before any of them finish.
- Can a quiet team lend its unused share? The interviewer wants a rule for lending, and for taking it back the moment the owner needs it.
- When do you ask for more capacity? Forecast from headroom and team share before the limit is hit, not after.
Token shares sit next to request-level rate limiting and fair queues, covered in Queues, Backpressure and Multi-Tenant Quotas, and next to the dollar side of the same tokens in Cost Tracking and Budget Guards.
Recap
| Rule | What to remember |
|---|---|
| Count tokens | Track TPM and RPM; one long prompt can cost a hundred short ones |
| Reserve, refund | Hold input + max output (3,000 + 1,000), give back the unused 600 |
| Per-team buckets | One bucket per team per model: a guaranteed share plus a small burst pool |
| At the limit | Queue or degrade, and say why |
| Prove it | One team floods, the others see no new 429s |
Try it yourself
A team sets max output to 4,000 on every call, but its replies average 300 tokens. Work out its reserve gap on a 2,000-token prompt, and say what it does to the team's two-calls-a-minute style budget.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.
