On this page
What you need first
This lesson uses ideas from these earlier lessons. Read them first if any idea is new to you.
01Why interviewers ask this
A free AI feature goes live, and the bill is ten times the plan. How do you control it?
A weak answer is "use a cheaper model". A strong answer sizes the model to each request, caps the output, and limits each user and the total.
02The idea in plain words
Think of a phone plan: each user gets a data pack, so one heavy user cannot use all the data.
Lesson 118 gave the formula: cost of one call = input tokens x input price + output tokens x output price. The cheapest call is the one you do not make: reuse a saved answer, or pay less for a prompt start that the provider has seen before (lesson 121). Five controls follow:
- Route by difficulty. Routing sends each request to the model that fits it. Anthropic's pricing page (20 Oct 2026) lists a large model at $4 and a small model at $0.10 per million input tokens: 40 times less. A classifier is a cheap first call that labels a request easy or hard; easy ones go to the small model. In cheap first, the small model answers and a check decides if it is good enough. If not, the large model tries. A classifier adds a call to every request and can label wrongly. Cheap first pays twice for a hard request.
- Cap the output. Set a maximum for output tokens. The model stops there.
- Batch work that can wait. A batch is many calls sent together to be answered later, such as a nightly summary. Anthropic charges 50% less. A batch finishes within 24 hours or expires.
- Budget for each user and day. The provider limits the whole account, not each user. Give each user a token bucket (lesson 56) that holds rupees. Before a call, take the worst case (input cost plus capped output cost); after it, give back what was not used. Add a total daily cap, because each fake account gets its own free budget.
- Alert on spend. Add up the cost of every call and alert at 80% of the daily cap. Set the provider's monthly limit; at that limit, calls fail for everyone.
Stuck on something? The AI tutor has read this lesson. Ask it with a free account
03Pause and predict
Pause. Guess first.
A chat costs Rs 1.10 on the large model and Rs 0.11 on the small one. 70 of 100 chats are easy. A classifier (Rs 0.003 a chat) sends them to the small model. What does one chat cost on average: about Rs 0.20, Rs 0.40 or Rs 0.80?
Write your guess before you read on. The answer is in the worked example.
04Worked example
SwadKart has 1,000 chats a day. Assumptions: prices as in lesson 118. The small model costs one tenth (Rs 10 and Rs 50 per million tokens). 70% of chats are easy. The classifier runs once for each chat on the small model, with 300 input and 5 output tokens. The cheap-first check is free code.
- No routing: 1,000 x Rs 1.10 = Rs 1,100.
- Classifier: its call costs 300 x Rs 10 / 1,000,000 + 5 x Rs 50 / 1,000,000 = Rs 0.00325. A chat costs 0.7 x 0.11 + 0.3 x 1.10 + 0.00325 = Rs 0.41 (the predict box: about Rs 0.40). A day is Rs 410.25, a 63% saving.
- Cheap first: a hard chat costs 0.11 + 1.10 = Rs 1.21. Average: 0.7 x 0.11 + 0.3 x 1.21 = Rs 0.44.
- Cap: 4,000 output tokens cost 4,000 x Rs 500 / 1,000,000 = Rs 2.00.
- Batch: 1,000 summaries (8,000 input and 200 output tokens each, large model) cost 0.80 + 0.10 = Rs 0.90 each, so Rs 900. Batch price: Rs 450.
- Budget: B = Rs 2, r = Rs 2 a day. A user spends at most B + r x T = 2 + 2 x 1 = Rs 4 on day one, then Rs 2 a day. 1,000 fake accounts spend Rs 4,000, then Rs 2,000 a day. Normal use is Rs 410, so set a total cap of Rs 800 and alert at 80%: Rs 640.
05Trade-offs
- Routing solves most of the bill (Rs 1,100 to Rs 410). It costs wrong labels. I would test it on fixed cases (lesson 122).
- A cap solves the worst case. It costs cut answers. I would set it from the p95 length (lesson 4).
- A budget for each user solves one user taking all. It costs angry users, and misses many accounts. I would add a total cap.
06Common misconceptions
"The provider's spend limit is my budget." It covers the whole account, so one user can stop everyone.
"A limit for each user is enough." 1,000 free accounts at Rs 2 each cost Rs 2,000 a day.
07How to say it in the interview
Say it like this
I work out each request's cost from its tokens, send easy ones to a small model, cap the output and batch work that can wait. I give each user a daily budget in a token bucket, set a total daily cap, and alert before the provider's limit stops everyone.
08Check your understanding
- Name the five controls. Why is the provider's limit not enough?
- A day has 2,000 chats, 60% easy. With the prices of the predict box, what does a day cost with and without routing?
- A script makes 5,000 free accounts, each with a Rs 2 bucket refilled Rs 2 a day. What is the most spent on day one, and each day after? What do you add?
09Answers
Show the answers
- Route, cap, batch, budget, alert. The provider counts the whole account, not each user.
- Without: 2,000 x 1.10 = Rs 2,200. With: 0.6 x 0.11 + 0.4 x 1.10 + 0.003 = Rs 0.509 a chat, so Rs 1,018.
- Day one: 5,000 x 4 = Rs 20,000. After: Rs 10,000 a day. Add a total daily cap and a sign-up limit for each IP address (lesson 56).
10Sources
- Anthropic: https://platform.claude.com/docs/en/about-claude/pricing (opens in a new tab) (Opus 5.5 $4, Haiku 5.5 $0.10, up to 100,000 prompt tokens), https://platform.claude.com/docs/en/build-with-claude/batch-processing (opens in a new tab), https://platform.claude.com/docs/en/api/rate-limits (opens in a new tab) (checked 20 Oct 2026). Other numbers are assumptions.
Try it now, no sign-up
- Play Level 1: one server and 100 users. Free, no sign-up.
- Read today’s Drill: one real situation, answered in about 7 minutes.
More practice, in the app (free account)
Related lessons and practice
Ask the AI tutor about this lesson
The tutor has read this lesson. Ask in your own words, any time. Free account, 20 questions a day.
Reading never needs an account. The account is for the tutor, the quiz, your notes and your progress.