The PDF that ate the quota
Your app answers questions about documents: 2,000 req/s, and 1 in 200 asks the model something, 10 calls a second. That's 600 calls a minute, well under your quota of 1,000. Then you launch "chat with your PDF", and now 3 in 10 questions send a whole 50 page document with them. The provider starts refusing calls, and the quota can't be raised before tonight.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
A model provider doesn't only count calls. It counts requests, input tokens and output tokens a minute, each with its own limit, and refills them like a token bucket. Hit any one of them and calls are refused.
Run traffic and look at the LLM API. Calls are well under 1,000 a minute. But each PDF question sends about 30,000 tokens, and the whole document goes again with every follow-up. That's about 10,000 input tokens a call on average, 6 million a minute, against a limit of 2 million.
You can't buy more quota today, so send fewer tokens. Click **LLM API** and tick **Cache long prompts**: the document is stored after the first question, and later questions read it from the cache. On most Claude models cached reads don't count toward the input token limit, and they cost a tenth of the price.
Your own limiter should count what the provider counts. A token bucket per user, filled with tokens and not requests, stops one person with a 500 page upload using everyone's share. You can't know a reply's length in advance, so take max_tokens out of the bucket up front and give back what wasn't used.
What you have to achieve
2,000 requests a second at the busiest hour, 2% of them writes.
- No broken or illegal connections
- Stay within your LLM API quota of 1k calls and 2M input tokens a minute
- No component is overloaded
- Fewer than 0.1% of requests fail
- p99 response time under 4 s
What you learn
Calls were never the problem: tokens were. The cache helped the bill too: without it, answering every question would cost almost three times as much in tokens. Measure what your provider measures, or the first sign of trouble is the provider saying no.
Check yourself
Your app sends 600 calls a minute against a limit of 1,000, yet the provider refuses some. What's the likely cause?
- The provider is down
- You're over a tokens-a-minute limit, not the calls limit
- You have too many app servers
Show the answer
You're over a tokens-a-minute limit, not the calls limit. Providers limit tokens as well as calls. A few huge prompts can use up the token limit while the call count looks fine.
Someone asks 10 questions about the same 30,000 token PDF. With prompt caching, about how many of the document's tokens count toward your input limit?
- All 300,000
- About 30,000: the first time it's read
- None at all
Show the answer
About 30,000: the first time it's read. The first question writes the document to the cache, and that counts. On most Claude models the reads after it don't count toward the input limit.
Your own rate limiter allows each user 20 requests a minute. Why isn't that enough here?
- One request can be 100 times bigger than another in tokens
- Counting requests is too slow
- It is enough
Show the answer
One request can be 100 times bigger than another in tokens. Counting requests treats a one-line question and a whole book the same. A bucket of tokens per user measures the cost that actually runs out.