A model charges $2.00 per million input tokens and $8.00 per million output tokens. A request sends 1,500 input tokens and generates 600 output tokens. Compute the cost of this single call.
Bill input and output tokens separately at their own per-million rates, then add: 1,500 in and 600 out here cost $0.003 + $0.0048 = $0.0078.
Imagine a taxi that charges one rate to drive you in and a higher rate to drive you home. The trip there is longer but cheaper per mile; the trip back is shorter but the meter ticks faster. An LLM bill works the same way. The words you send in are charged at one rate, and the words it writes back are charged at a higher rate. Here you send more words in, yet the reply still costs more — because each word it writes is charged about four times as much as each word you send. So you add up the two trips to get the total fare.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Pricing a single LLM call looks like trivial arithmetic, and the arithmetic genuinely is trivial. The reason it shows up in interviews is that it quietly tests three things at once: whether you know APIs bill input and output at different rates, whether you can handle the per-million unit without a factor-of-1000 slip, and whether you draw the right conclusion from the numbers.
That last part is where most answers separate. Two engineers can both arrive at $0.0078 and walk away with opposite mental models. One notices that input had more tokens and files away "prompt is the cost." The other notices output cost more despite fewer tokens and files away "output is the lever." Only the second model survives contact with a real bill.
This walkthrough builds the formula from first principles, runs the exact numbers, scales them to a production fleet so the asymmetry becomes money you'd actually care about, and then layers in the refinements — cached input, retries — that turn a textbook formula into a usable cost model.
The two-term formula and the per-million trap
Every token-billed API charges on two independent meters. Input tokens — your system prompt, context, and user message — bill at one rate. Output tokens — everything the model generates — bill at another, usually higher rate. The total for one call is just the sum of the two meters:
The 10^6 in each denominator is where people slip. Rate cards quote dollars per million tokens because per-token numbers would be a string of leading zeros. So $2.00 per million is $0.000002 per token. If you mentally treat the rate as per thousand, you land 1000× too high; if you forget to divide at all, you're a million times off and quoting dollars per call that should be fractions of a cent.
The discipline that prevents the slip is to always write two lines, never one blended number. Compute the input line, compute the output line, then add. Collapsing them into total_tokens × some_rate throws away the rate difference and produces a wrong answer that often looks plausible. Keeping the lines separate also makes the next step — reasoning about which line to attack — fall out for free, because the cost is already broken down the way you'll want to optimize it.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Line | Tokens | Rate (per 1M) | Cost |
|---|---|---|---|
| Input | 1,500 | $2.00 | $0.0030 |
| Output | 600 | $8.00 | $0.0048 |
| Total | 2,100 | — | $0.0078 |
Real products, models, and research that use this idea.
- OpenAI's API pricing page lists separate per-million input and output rates for each model, with output several times higher.
- Anthropic's Claude pricing similarly quotes input, output, and discounted cached-input rates per million tokens.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does prompt caching change the per-call cost formula?
Split input into cached and fresh portions and bill the cached share at the discounted rate, leaving output unchanged.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Adding the two token counts together and multiplying by one blended price — input and output have different rates and must be computed on separate lines.
60 second bullets to scan on the way to the call.
The two-term per-call cost formula with separate input and output rates
Converting per-million pricing to a single call's token counts
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.