Decompose the cost of a single API call into its components and explain which dominates.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Write the cost formula for a single LLM API call given non-cached input tokens, cached input tokens, and output tokens. Explain which term typically dominates on production workloads and what that implies for cost optimization.
Per-call cost splits into new input, cached input, and output tokens; output tokens are roughly five times pricier per token, so output usually dominates the bill.
Think of a taxi ride with two meters. The first meter runs while you read out your destination to the driver, that is the input. The second meter runs while the driver narrates the whole route back to you, that is the output. The reading-out meter is cheap and ticks fast in parallel. The narrating meter is several times more expensive per word, because the driver speaks one word at a time and you pay a premium for each. There is even a loyalty discount: if you give the same long address every trip, the company remembers it and charges almost nothing to re-read it. So your bill is mostly driven by how much the driver talks back, not how much you said up front.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: write the three-term formula, state the output 5x and cached 0.1x ratios, derive the crossover, then rank caching and output trimming as the levers and flag agent-loop compounding.
| Token type | Phase | Relative rate | Cost lever |
|---|---|---|---|
| New input | Prefill, parallel, compute-bound | 1x baseline | Trim only after output is minimized |
| Cached input | Prefill, served from cache | About 0.1x | Cache every stable prefix |
| Output | Decode, sequential, bandwidth-bound | About 5x | Shorten responses, the top lever |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming the bill tracks total token count, so trimming a long prompt is the big win. Output tokens cost several times more each, so a short response usually matters more than a short prompt.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.