A million requests a day costs $21,000 a month on an illustrative API, or about $15,100 on two rented GPUs. Four numbers set the bill: tokens, the price of an hour, memory bandwidth and batch size.
Drag the traffic and pick a setup. Watch where the two cost lines cross. Then we build every number on this chart from zero, one chapter at a time.
You need a little Python and the idea that a language model writes one token at a time. We build the rest from zero.
Part of the Inference Engineering family, with Serving Engines and Speculative Decoding. Every price on this page is illustrative. GPU specs come from NVIDIA's product pages, read on 22 November 2026.
Illustrative model: 500 input and 300 output tokens per request, and an API at $0.50 and $1.50 per million tokens. Self-hosting: two H100s at $2 per GPU-hour, 70% utilisation, $6,213 a month fixed. Chapters 0 to 6 derive each number.
Chapter 0
Turn a traffic number into a monthly bill you can recompute by hand
Your app added an AI feature. Finance asks two things: what does it cost a month, and what happens if usage doubles? The billing dashboard shows a running total. It is a receipt, not an answer.
A token is the unit a model reads and writes, about three quarters of an English word. Hosted APIs charge per million tokens, with one price for input tokens (the prompt you send) and a higher price for output tokens (the reply). So the bill is a count of tokens times a price.
Take the app we price all lesson. It serves 1,000,000 requests a day. Each request sends 500 input tokens and gets 300 output tokens back. Call the number of days in the month D and the requests a day R. Call the tokens per request nin and nout, and the prices per million tokens pin and pout.
M equals D times R times, n-in times p-in plus n-out times p-out, all over ten to the six.
Price one request: n-in times p-in plus n-out times p-out, divided by a million. Multiply by the requests a day R and by the days D. That is M.
With illustrative prices: 500 × 0.50 + 300 × 1.50 = 700, divided by a million, so one request costs $0.0007. M = 30 × 1,000,000 × 0.0007 = $21,000 a month.
Every term is a straight multiplication by R. Double the requests and the bill doubles to $42,000. On a pay-per-token API the bill is linear in traffic. Chapter 5 shows where self-hosting breaks that.
Top bar: tokens. Bottom bar: dollars. Teal is input, warm is output. Drag the reply length and watch output take over the dollars.
Illustrative prices of $0.50 and $1.50 per million tokens. Input stays at 500 tokens per request. Real prices change often; check the provider's price page on the day you budget.
Output is 300 of the 800 tokens, 37.5%. It is $450 of the $700 a day, 64%. So cut reply length before prompt length.
The failure: a team budgets from last month's invoice. Symptom: the bill jumps after a prompt change. Measure: log tokens in and out per request. Fix: budget from the formula, not the invoice.
Chapter 1
Divide what an hour of hardware costs by the tokens it makes in that hour
Rent your own GPUs and nobody hands you a price per token. You get two other numbers. The cloud charges per GPU per hour. Your serving stack makes some number of tokens per second. Divide the first by the second and the hours cancel.
Our setup: a 70-billion-parameter model on two H100 GPUs. Call the price of the whole instance per hour h. At an illustrative $2 per GPU-hour, h = $4. Call the tokens it makes per second at full load T, the raw throughput. Chapter 2 derives T = 3,063 for this setup.
The GPU bills every hour, busy or idle. Traffic has gaps and quiet nights. The share of paid time that does useful work is the utilisation, u. Take u = 0.7 for a well-run service.
c equals h divided by, T times u times thirty-six hundred, times ten to the six.
Multiply T by u to get the useful tokens per second. Multiply by 3,600 to get tokens per hour. Divide the hourly price h by that, then scale to a million. That is c.
With the illustrative price: 3,063 × 0.7 = 2,144 tokens per second. Times 3,600, that is 7.72 million tokens an hour. So c = 4 / 7,718,400 × 106 = $0.518 per million output tokens.
The curve is c against useful tokens per second. Your setup is the dot. Change the batch and see how far the dot slides.
Raw throughput per batch comes from Chapter 2 (two H100s, 70B in 16-bit, 20.9 ms per step). GPU prices are illustrative; on-demand and reserved prices differ by provider and change over time.
Batch 1 costs $33.17 per million tokens. Batch 64 costs $0.518. The GPU and the hourly price did not change: 64 users share one read of the weights. Utilisation is the second free lever. From 70% to 95%, c falls by 0.70 / 0.95, to $0.382.
The failure here is a unit slip. Symptom: a self-hosted price a thousand times off the API price. Measure: recompute it the other way, as seconds per token times dollars per second. Fix: keep every quantity in seconds and tokens until the last step.
Chapter 2
Derive tokens per second from the size of the weights and the speed of memory
The model writes its reply one token at a time. This is decode. To make one token, the GPU must read every weight of the model from its memory once. The arithmetic per weight is tiny. So the time of a step is the time to read the weights: decode is memory-bound.
Call the bytes of weights W. A 70B model in 16-bit numbers holds 2 bytes per parameter, so W = 140 GB. Call the memory bandwidth BW, the bytes per second the GPU can stream. NVIDIA lists 3.35 TB/s for one H100 SXM, so two give 6.7 TB/s. One step takes W / BW = 140 / 6,700 s = 20.9 ms.
A step serves every request in the batch at once. The weights are read once and used for each sequence. Call the number of requests in the batch B. One step makes B tokens.
T equals B times BW over W.
Divide BW by W to get steps per second. Each step gives one token to each of the B requests, so multiply by B. That is T.
6,700 / 140 = 47.9 steps per second. That is each user's speed. With B = 64, T = 64 × 47.9 = 3,063 tokens per second for the whole GPU pair.
Each purple block is one read of all 140 GB. Each warm dot is a token. Change the GPU, then the batch. Only one of them changes the block length.
Bandwidth from NVIDIA product pages (read 22 Nov 2026): A100 80GB 2,039 GB/s, H100 SXM 3.35 TB/s, H200 4.8 TB/s. The model ignores the reads of the KV cache, so real steps are somewhat slower.
Price each pair at batch 64 with Chapter 1's formula and 70% utilisation. The GPU prices are illustrative.
| GPU pair | Bandwidth | $/GPU-hour | Step | $ per M output tokens |
|---|---|---|---|---|
| 2× A100 80GB | 4.08 TB/s | 1.50 | 34.3 ms | 0.64 |
| 2× H100 SXM | 6.7 TB/s | 2.00 | 20.9 ms | 0.52 |
| 2× H200 | 9.6 TB/s | 2.80 | 14.6 ms | 0.51 |
A faster GPU shortens the step. A higher price eats most of the gain.
The failure: long contexts. Symptom: measured tokens per second far below B × BW / W. Measure: add the KV cache bytes per step to W. Fix: count them, or cap the context. The Serving Engines lesson covers the cache.
Chapter 3
Price the prompt from FLOPs, and see why input tokens cost less than output tokens
Before the first reply token, the model reads the whole prompt. This is prefill. All 500 prompt tokens go through the model in one pass, side by side. Each weight read now serves 500 tokens, so memory is no longer the limit. The arithmetic is: prefill is compute-bound.
A forward pass costs about 2 floating-point operations per parameter per token: one multiply and one add. Call the parameter count N. Call the GPU's peak arithmetic rate F, in FLOPs per second. NVIDIA lists 1,979 TFLOPS of BF16 for an H100 SXM with sparsity. Dense models get half, 989.5, so two GPUs give F = 1,979 TFLOPS.
No kernel hits peak. The share it reaches is the MFU (model FLOPs utilisation), m. Take m = 0.4.
T-pre equals F times m over two N.
Multiply the peak F by the MFU m to get the FLOPs you get each second. Divide by the 2N FLOPs one token needs. That is T-pre.
1,979 × 0.4 = 791.6 trillion FLOPs per second. One token needs 2 × 70 billion = 140 billion. T-pre = 791.6 / 0.140 = 5,654 tokens per second. With u = 0.7 and h = $4, Chapter 1 gives $0.281 per million input tokens.
Decode costs $0.518, prefill $0.281: a ratio of 1.85 on the same hardware. That is the physical reason input is cheaper. API price ratios are a business choice on top of it.
Now price one request. Add its input share and its output share:
Teal is prefill, warm is decode. Drag the prompt long, as in document questions, and watch which phase owns the dollars.
Self-hosted rates from this chapter: $0.281 and $0.518 per million tokens, illustrative GPU price. The model treats the two phases as separate GPU time; engines that mix them in one step blur this a little.
At 4,000 prompt tokens, prefill is 88% of the dollars. For long prompts, optimise prefill first.
The failure is the MFU guess. Symptom: prefill costs more than planned. Measure: time a long prompt and compute FLOPs per second over F. Fix: better kernels and no padding. At m = 0.25 prefill costs $0.449; at 0.55 it costs $0.204.
Chapter 4
Find the batch where free sharing ends and every extra request slows the rest
Chapter 2 said a bigger batch is free: the weight read takes 20.9 ms whatever B is. That holds only while the arithmetic fits inside the read. Each request in the batch adds 2N FLOPs per step. At some batch the arithmetic takes longer than the read.
The time between two tokens for one user is the inter-token latency (ITL). Below the crossover, ITL stays at 20.9 ms. Above it, the step grows with B, and every user waits longer.
Set the two times equal. The read takes W / BW. The arithmetic takes B × 2N / (F × m). With 2-byte weights, W = 2N, and the 2N cancels. Call the crossover batch B*.
B-star equals F times m over B-W.
Multiply F by m to get the useful FLOPs per second. Divide by BW. The result B-star is how many tokens of arithmetic fit inside one weight read.
791.6 / 6.7 = 118. Up to about 118 requests, ITL stays 20.9 ms. At B = 400 the step takes 400 × 0.177 ms = 70.7 ms.
Top: ITL in ms. Bottom: price per million tokens, on a log scale. Slide the batch, then change the MFU and watch the crossover move.
Two H100s, 70B in 16-bit, h = $4, u = 0.7, peak and bandwidth from NVIDIA's page. The step is the larger of the read time and the arithmetic time, a simple roofline model.
| Batch | Regime | ITL | $ per M output tokens |
|---|---|---|---|
| 8 | memory-bound | 20.9 ms | 4.15 |
| 64 | memory-bound | 20.9 ms | 0.518 |
| 118 | crossover | 20.9 ms | 0.281 |
| 400 | compute-bound | 70.7 ms | 0.281 |
Past the crossover the price stops falling. It sits at prefill's $0.281, because decode is now as compute-bound as prefill. ITL keeps rising. So batch up to the crossover for free, and go past it only for offline jobs.
The failure: a full batch that waits for arrivals. Symptom: slow first tokens at low traffic. Measure: 1,000,000 requests a day is 11.6 a second, so filling a batch of 32 takes 2.8 s. Fix: a short maximum wait, then run what waits in the queue.
Chapter 5
Add the fixed cost, then solve for the volume where the two bills meet
First, one price per million tokens for each option. Our app's tokens are 62.5% input and 37.5% output. The API blend is 0.625 × $0.50 + 0.375 × $1.50 = $0.875. Self-hosting blends the same way, because GPU time adds up token by token:
At $0.370 against $0.875, self-hosting looks 2.4 times cheaper. It is not, because self-hosting has a fixed cost: money you pay whatever the traffic. Take one spare instance kept on for spikes, $4 × 24 × 30 = $2,880, and a fifth of a $200,000-a-year engineer, $3,333. Call the fixed cost per month K: $6,213, illustrative.
Call the monthly volume V, in millions of tokens. The API costs p × V. Self-hosting costs K + c × V. Set them equal and solve for the volume V*.
V-star equals K over, p minus c.
Each million tokens you move off the API saves p minus c. Divide the fixed cost K by that saving. V-star is how many millions it takes to pay K back.
With illustrative costs: V* = 6,213 / (0.875 − 0.370) = 6,213 / 0.505 = 12,300 million tokens, 12.3 billion a month, about 512,000 requests a day. Our app does 24 billion: self-hosting costs $6,213 + $8,875 = $15,088 against $21,000, a 28% saving.
Blue is the API. Purple is self-hosting, which starts at the yellow fixed cost. Drag the fixed cost up, as if you hire a full-time engineer.
Blended prices $0.875 (API) and $0.370 (self-host) per million tokens, both illustrative. Real contracts add volume discounts and reserved-instance prices; plug yours into the same formula.
| Billion tokens a month | Self-host | API | Cheaper |
|---|---|---|---|
| 5 | $8,062 | $4,375 | API, by $3,687 |
| 12.3 | $10,762 | $10,762 | tie |
| 24 | $15,088 | $21,000 | self-host, by $5,912 |
| 50 | $24,703 | $43,750 | self-host, by $19,047 |
The failure: a K that leaves out people. Symptom: self-hosting "saves" money on paper and loses it in practice. Measure: count on-call hours, the spare instance and upgrades. Fix: with a full-time engineer, K = $19,547 and V* rises to 38.7 billion. Our app then loses money by moving.
Chapter 6
Price each lever against the same $15,088 bill, and catch the one that backfires
Each lever changes one input of the formulas you have. Price all of them against the same self-hosted bill, $15,088 a month, so they compare.
Each bar is fixed cost (yellow) plus GPU time (purple). Switch levers on together and compare with the sum of their solo savings.
Baseline $15,088 from Chapter 5, all prices illustrative. The fixed cost of $6,213 never shrinks, which is why savings do not add.
Quantization plus caching saves 34.4%, not 29.4 + 10.0 = 39.4%. The second lever acts on a bill the first already shrank, and K does not move.
Speculative decoding lets a small draft model guess k tokens; the big model checks all of them in one step. Call the chance that the big model accepts each guess α. Count the tokens one round yields, E, including the one the big model always adds.
E equals one minus alpha to the k plus one, over one minus alpha.
The first guess survives with chance alpha, the first two with alpha squared, and so on up to k. Add those chances, plus one for the token the big model adds. The sum is E.
0.75 = 0.168, so E = (1 − 0.168) / 0.3 = 2.77 tokens per round. With a 7B draft, a round at batch 1 takes 1.4 big steps, so the user sees 2.77 / 1.4 = 1.98 times the speed.
Warm is plain decode. Green is speculative decoding, red where it loses. Slide the batch past 24 and watch the check step hit the crossover.
Roofline model of Chapter 4 with k = 4 and a 7B draft whose steps cost a tenth of the 70B's. Acceptance rates depend on the task; measure yours.
At batch 64 the check step holds 64 × 5 = 320 tokens, well past the crossover of 118. It turns compute-bound and throughput falls to 0.89 times plain decode. So speculation buys speed for a few users and costs money at full load. The Speculative Decoding lesson goes deeper.
Chapter 7
Send every request to a small model first and pay for the big one only when it must
Many requests are easy: a greeting, a lookup, a short rewrite. A 3B model handles them. A cascade sends every request to the small model first. If its answer fails a check, the request escalates to the 70B model and pays again.
Price per million tokens scales with N, so the 3B model costs 3/70 of the 70B's $0.370: cs = $0.0158. Call the big model's price cb, the monthly volume V (24,000 million tokens) and the share that escalates e. Call the cascade's monthly GPU bill C.
C equals V times, c-s plus e times c-b.
Every token pays the small price c-s. The share e also pays the big price c-b. Add the two per-token prices and multiply by the volume V. That is C.
With illustrative prices: C = 24,000 × (0.0158 + 0.4 × 0.370) = 24,000 × 0.164 = $3,930 a month, against $8,875 for the 70B alone. That is 55.7% off the GPU bill.
The left bar is the 70B alone. The right bar is the cascade: small pass plus escalations. Push escalation toward 100%.
GPU cost only; fixed costs are left out. Scaling price with N is optimistic for small models, whose steps are short enough that overheads start to count.
Set C equal to V × cb and solve: the cascade stops paying at e = 1 − cs/cb = 1 − 3/70 = 95.7%. The escalated requests also wait for two models. The failure is a weak check. Symptom: users see bad small-model answers. Measure: grade a sample of answers the router kept. Fix: tighten the check, and accept a higher e.
Chapter 8
Price embeddings, images and speech with the same rule: GPU-seconds times the price of a second
Not every model writes text one token at a time. The rule from Chapter 1 still holds: find the GPU-seconds a unit of work takes, then multiply by the price of a second. At an illustrative $2 per GPU-hour, one second costs $0.000556. Only the unit changes.
| Modality | Unit | What sets the GPU time | Compute floor |
|---|---|---|---|
| Embeddings | million tokens | one parallel pass, like prefill | $0.0003 |
| Image generation | image | denoising steps × time per step | $0.0014 |
| Text to speech | audio-hour | real-time factor × audio length | $0.10 |
| Speech to text | audio-hour | real-time factor × audio length | $0.20 |
Embeddings. An encoder reads all its tokens at once and writes no reply, so it is compute-bound like prefill. A 110-million-parameter encoder needs 0.22 GFLOPs per token. One H100 at 40% MFU gives 396 TFLOPS, so 1.8 million tokens a second and $0.0003 per million. A corpus of a million 500-token documents costs about $0.15 to embed.
Images. A diffusion model runs a fixed number of denoising steps. At an illustrative 100 ms per step, 25 steps take 2.5 s: $0.0014 per image. Fewer steps cost less, at some loss of detail.
Speech. The real-time factor (RTF) is GPU time over audio time. A TTS model at RTF 0.05 makes an hour of audio in 3 minutes: $0.10. Transcription at RTF 0.1 costs $0.20 per audio-hour.
Pick a modality, then turn its own knob. The bar is GPU time; the read-out is that time at $2 an hour.
All step times, real-time factors and the GPU price are illustrative. These are compute floors; hosted prices add margin, idle time and operations, so they sit well above.
The failure: a floor read as a price. Symptom: a budget that assumes $0.0003 per million embedding tokens and misses. Measure: divide your real GPU bill by the units you served. Fix: apply your utilisation, as in Chapter 1. At 10% utilisation the floor is ten times higher.
Chapter 9
Keep the numbers, the checklist and the code in one place
The bill is tokens times price. A self-hosted price is dollars per hour over useful tokens per hour. Decode speed comes from bandwidth and batch; prefill speed comes from FLOPs and MFU. Batching is free up to B*. Self-hosting pays above V*. Levers and routing shrink the variable part and never the fixed part.
| Term | Meaning | This lesson's number |
|---|---|---|
| Monthly API bill | D × R × (ninpin + noutpout) / 106 | $21,000 |
| Decode step | W / BW, one read of all weights | 20.9 ms |
| Decode price | batch 64, 70% utilisation | $0.518 / M |
| Prefill price | MFU 40%, 70% utilisation | $0.281 / M |
| Crossover batch B* | F × m / BW | 118 |
| Blended self-host c | token-weighted average of the two prices | $0.370 / M |
| Break-even V* | K / (p − c) | 12.3 B tokens / month |
| Self-hosted bill | K + c × V | $15,088 |
| Speculation yield E | (1 − αk+1) / (1 − α) | 2.77 at α = 0.7, k = 4 |
| Cascade bill C | V × (cs + e × cb) | $3,930 at e = 0.4 |
pythondef price_per_m(hour_usd, tok_per_s, util): # Chapter 1 return hour_usd / (tok_per_s * util * 3600) * 1e6 N, W, BW = 70e9, 140e9, 6.7e12 # params, weight bytes, bytes/s (2x H100) F, mfu, hour, util = 1979e12, 0.4, 4.0, 0.7 # dense FLOP/s, MFU, $/hour (illustrative), busy share step = W / BW # 0.0209 s per decode step c_out = price_per_m(hour, 64 / step, util) # 0.518 (Chapter 2, batch 64) c_in = price_per_m(hour, F * mfu / (2 * N), util) # 0.281 (Chapter 3) b_star = F * mfu / BW # 118 (Chapter 4) c = (500 * c_in + 300 * c_out) / 800 # 0.370 blend prices, not throughputs p, K, V = 0.875, 6213, 24000 # API blend, fixed $/month, M tokens/month print(K / (p - c)) # 12,300 M tokens: break-even (Chapter 5) print(K + c * V, p * V) # 15,088 vs 21,000
Now press Present or Teach. Explain from memory why a reply token costs more, where B* comes from, and why hiring moves the break-even. Then go back to the chart, switch the setup to int8, and predict where the lines cross before you look.