Cost per Million Tokens
A configurable cost estimator whose every input says where it came from, fed with measured power and throughput and with dated prices: what cost per token is made of, how utilisation and batch size move it, how a forecast differs from a metered run and from a bill, and why the price of a token is not the price of an answer.
On one machine, with one model, a conditional estimate of the cost of a million useful output tokens ranges from $0.285 at full utilisation with the chapter's batch-4 server to $32.72 at 2% utilisation with batch 1: roughly a 115-fold span. Those dollars are not an invoice or a measured cash outlay. They result from applying explicitly chosen capital, electricity, operating-life and overhead assumptions to measured model throughput and GPU-board power. Even at an assumed 100% busy fraction, changing the decode batch from one to sixty-four reduces a narrower capital-plus-board-energy estimate from $0.676 to $0.087 per million generated tokens. The two tables use different cost boundaries and cannot be compared as though they were alternative measurements of one price. What matters is the structure: idle hours, effective batch fill and the denominator can dominate a token-cost calculation.
Most of the money inputs are not measurements. The system price, tariff, residual value, life, opportunity cost of capital, unmeasured host power and zero operations allowance are stated placeholders. Qwen3-0.6B throughput and NVIDIA-reported GPU-board power were measured locally; the latter was not checked with a wall meter. The forecast’s apparent agreement within 0–17% of the Chapter 36 metered-at-assumed-rates estimates is not a comparison with a bill or with power sampled during the load runs. Both sides use the same financial and power assumptions. The reconciliation is valuable because it reveals why a poor busy-fraction prediction can coexist with a similar cost-per-output-token estimate, but it is not independent evidence that a deployment would cost these dollars. The absence of invoiced spend remains NOT_RUN.
The chapter’s plan asks for a configurable local-cost estimator with documented assumptions, a sensitivity test of utilisation, and a distinction between forecast and measured spend. They are implemented and checked against saved results. The chapter also estimates GPU-board joules per generated token, allocates modeled whole-system cost to input and output tokens under an explicit rule, and prices the saved tokens-per-correct-result figures from Chapters 33–35. The allocation is not provider pricing, and the last calculation excludes parts of real request cost—including some prompt processing, networking and execution overhead. Those boundaries are essential to interpreting the headline numbers.
The question
Cost per million tokens is a quotient whose numerator and denominator both hide a decision. The numerator is a cost over a stated accounting interval: a capital recovery charge, electricity consumed while powered, operations and maintenance, networking, and possibly rental or additional infrastructure charges. Some of these are estimates rather than payments. The denominator is a count of tokens: input or output, useful or thrown away, delivered in some number of hours of which the machine was busy for some fraction. Change the assumed powered hours, the observation window, the delivered output-token mix, the allocation rule or the treatment of failed work, and the result can change by a multiple. Input and output tokens should not silently share a single denominator.
So the questions are: which inputs does the cost depend on, and by how much; what is the difference between a machine being busy, being full and being efficient; what does a forecast get right and wrong when set against a metered run; how independently metered wall energy and real invoices would validate the model; and how the cost per correct outcome changes when generation strategy and answer quality change. In this chapter, comparing prices across models never implies comparable answers.
Where this sits
Chapter 32 turned a provider’s published prices into the cost of a workload, including the break-even of caching, with a mock and no bill. Chapters 33, 34 and 35 each ended with a count of tokens spent per problem solved, which this chapter prices. Chapter 36 defined utilisation’s cousins (the window, the request rate, the output-token rate) and supplied the capacity test and the load runs that are metered here. Chapter 38 examines GPU-reported utilisation; here busy fraction means the proportion of a specified powered/observation interval with at least one request in service. The two are not interchangeable. Chapter 36’s finite load tests also supply a reminder that capacity under a burst, steady-state capacity under Poisson load, and goodput subject to latency targets are different quantities.
Where the starter was wrong
The starter takes a dollar rate per hour, output tokens per second and a utilisation multiplier and computes dollars per million tokens. Under an explicitly fixed output capacity, powered-time billing and a stated utilisation definition, that quotient is sound. Its limitations are missing accounting boundaries and provenance: it has only one rate although prefill and decode have very different throughput, no allocation of capital versus idle or incremental power, no batch-fill factor, no prompt/output split, and no separation of forecast, modeled retrospective charge and invoiced spend. Its four utilisation examples are a one-variable sweep, not empirical validation of the input assumptions. This chapter’s replacement estimator retains the simple quotient but makes the rate, workload, usage and provenance visible. The starter and its original tests remain untouched.
The model, and what each input is
hourly cost F + V u
output tokens/hour T u
cost per million (F + V u) / (T u) x 10^6 (+ egress)
F the standing cost of a powered hour: capital + operations + the power of an idle machine
V the extra energy cost of a fully busy hour over an idle one
T useful output tokens in an hour of full use = 3600 x capacity x output tokens a request / (1 + waste)
u utilisation: the fraction of powered hours in which the accelerator is executing requests
The capital term uses a capital-recovery factor applied to purchase price less the discounted end-of-life residual value, then divides the resulting annual charge by assumed powered hours per year. At zero interest, the code uses straight-line annual recovery of purchase price less residual. This is an economic allocation, not a depreciation schedule, a receipt, or a cash payment made every hour. The modeled waste_ratio multiplies the assumed work needed per useful output token by 1 + waste_ratio. That treats wasted work as capacity-consuming at the same average resource intensity as useful work; actual retries, cancellations and partially executed requests can have very different prefill/decode and energy costs. Do not add the same waste again when a tokens-per-solved measure already contains discarded generations. Capacity is requests a second at full use, measured, for a stated workload.
cost_core.Assumptions requires each field to have a basis label (measured, quoted, derived or assumption) and a nonempty provenance note, and checks numerical ranges. That is useful audit metadata, not an automated verification that a note is truthful, that a source was read or that one assumption is consistent with another. Every input is also checked against a range (a life of zero years, a power factor below 1 and an active power below the idle power are errors). The reference is a hypothetical dedicated use of the measured desktop hardware. Its inputs, including a powered-hours assumption equivalent to a year-round average, are:
| Input | Value | Basis |
|---|---|---|
| system price | 1,500 USD | assumption (placeholder; replace with the receipt) |
| life, residual, cost of capital | 3 years, 10%, 5% a year | assumption |
| powered hours a year | 8,766 | assumption (always on) |
| operations | 0 USD a month | assumption |
| idle power | 60.1 W | derived estimate: 26.1 W GPU-board reading + 34 W assumed non-GPU allowance; no wall meter |
| busy power | 160.7 W | derived estimate: 110.7 W GPU-board reading during batch-4 decode + 50 W assumed non-GPU allowance |
| electricity | 0.30 USD per kWh | assumption (placeholder tariff) |
| egress | 0 USD per GB; 104 bytes per output token | assumption |
| capacity | 3.213 requests/s at batch 4; 1.007 at batch 1 | measured (Chapter 36’s capacity test) |
| workload | 215 prompt tokens, 32 output tokens a request | measured (Chapter 36’s workload) |
| prefill’s share of busy time | 9.0% at batch 4, 3.6% at batch 1 | derived from phase microbenchmarks and an assumed batch/workload shape, not traced per request |
| waste | none | assumption |
At these input values the annualized capital charge is $0.0574 per powered hour, idle-energy allowance $0.0180 per hour, and incremental busy-energy allowance $0.0302 per fully busy hour. Thus `F = $0.0754/h, V = $0.0302/hand the assumed full-batch useful-output capacityT = 370,166 output tokens/h. T` is calculated from Chapter 36’s 3.213 requests/s capacity test and an assumed 32 output tokens/request; it is not a sustained production service-rate measurement. With a receipt, a measured whole-system idle/active power profile, an actual tariff and a deployment duty cycle, these can be replaced and the calculation rerun. Even then, a measured cost of electricity would not by itself establish fully loaded operational cost.
Utilisation is defined operationally, not supplied by a GPU dashboard. In the analytical model, u is the fraction of paid, powered time when the serving system is doing inference work, and T assumes the same effective full-use batch throughput whenever it is busy. That second assumption matters: a batch-4 engine can be busy on batches of one, in which case u rises without reaching batch-4 capacity. For the Chapter 36 reconciliation, busy_fraction() estimates service activity by taking the union of all request intervals from submission to finish. On its work-conserving single-worker queue, that is a reasonable proxy for server-busy time, but it includes queued requests, is not an instrumented GPU-active-time trace, and is not a direct measurement of GPU compute utilisation. Chapter 38 addresses the latter separately.
Measuring what the machine does
The estimator needs a workload-specific production rate and a power-versus-time profile. A token’s marginal cost also depends on whether it is a prefill or decode token, the batch and context, and how idle energy is allocated. cost_lab.py pins the process to the performance cores (Chapter 36 found why), reads the GPU board’s power from nvidia-smi about every 100 ms, and runs prefill and decode at different sizes. Only NVIDIA driver-reported GPU-board power is sampled, not a wall-socket meter. The inferred system power adds assumed host allowances; the 100 ms sampling interval is coarse for subsecond prefill phases and does not establish a high-precision joules-per-request trace. The readings are useful for scale and batch trends, but should not be presented as whole-system measurements.
Decode, context 256, 128 steps. The saved analyzer selects the faster of two timed repetitions after warm-up for each batch and associates it with that repetition’s sampled board power. This is a throughput-oriented selection rule, not an estimate of the mean or a confidence interval; a repeat on an otherwise idle machine would better establish uncertainty:
| Batch | Step (ms) | Output tokens/s | Board power (W) | Joules per token |
|---|---|---|---|---|
| 1 | 29.4 | 34 | 85 | 2.49 |
| 2 | 28.0 | 71 | 92 | 1.29 |
| 4 | 27.7 | 145 | 111 | 0.77 |
| 8 | 34.5 | 232 | 129 | 0.56 |
| 16 | 57.1 | 280 | 138 | 0.49 |
| 32 | 102.6 | 312 | 143 | 0.46 |
| 64 | 196.6 | 326 | 148 | 0.45 |
The driver-reported idle board power averaged 26.1 W across 138 readings (20.0–34.5 W); this is not whole-machine standby power. Tokens a second rose 9.6 times from batch 1 to batch 64 while the power rose 1.7 times, so the energy of a token fell from 2.5 to 0.45 joules. Step time remains near 28–29 ms up to a batch of 4 (the loop is launch-bound, as in Chapters 33 and 36) and then grows as the GPU runs out of idle capacity: throughput increases slowly beyond batch 32 in this particular 256-context, 128-step experiment. Energy per output token is average board energy divided by generated tokens, not incremental energy above idle, nor energy per correct answer.
Prefill is a different measurement regime. The measured prefill throughput ranged from 3,647 tokens/s for one 128-token prompt to 7,694 tokens/s for eight 512-token prompts; one 512-token prompt reached 6,165 and one 1,024-token prompt reached 4,821. The GPU-board readings in those runs ranged roughly from 74 to 166 W, but some individual prefills were so short that the power sampler saw only one observation. Measured wall/GPU timing for a token in these isolated runs should not be translated into a universal input-versus-output price: the phases differ in parallelism, batch size, sequence length and host work. The approximate prefill-share calculation below uses their timings as an allocation hypothesis and should eventually be replaced by phase-separated energy measurements on the same workload as Chapter 36.
Utilisation, and the sensitivity test
The implementation gate asks for sensitivity to defined busy fraction, holding batch-4 or batch-1 full-use capacity constant. These are conditional model sweeps, not measurements made after changing real utilisation on the machine. For the batch-4 and batch-1 servers (capacities 3.213 and 1.007 requests a second), the modeled whole-system cost per million useful output tokens at the documented placeholder rates, with egress set to zero:
Assumed busy fraction u |
Batch 4: modeled USD / 1M useful output tokens | Batch 1: modeled USD / 1M useful output tokens | Batch 4: modeled USD / 1,000 requests |
|---|---|---|---|
| 0.02 | 10.27 | 32.72 | 0.329 |
| 0.05 | 4.16 | 13.21 | 0.133 |
| 0.10 | 2.12 | 6.70 | 0.068 |
| 0.25 | 0.897 | 2.80 | 0.029 |
| 0.50 | 0.489 | 1.49 | 0.016 |
| 0.75 | 0.353 | 1.06 | 0.011 |
| 1.00 | 0.285 | 0.844 | 0.009 |
At low u, most dollars are incurred regardless of whether the GPU executes inference: cost/1M = 10^6 · [F/(T·u) + V/T], plus any egress. The first term therefore grows approximately as 1/u, while this model’s incremental busy-energy term per useful output token stays constant. At batch 4 and utilisation 0.1, 0.5 and 1.0, capital contributes approximately $1.55, $0.31 and $0.155 per million; the modeled idle-energy allocation contributes $0.49, $0.10 and $0.049; and the modeled incremental busy energy contributes $0.082 in each case. At full use, the selected tariff and financial assumptions allocate about 54% of the estimated cost to capital, 17% to baseline power and 29% to extra busy power. This is a breakdown of a formula, not an empirical decomposition of real invoices. If powered hours, tariff structure, effective batch fill, rental billing or power-cycling policy change with load, the neat 1/u relationship need not hold.
Local sensitivity, not a probabilistic forecast. The tornado function varies one assumed or measured input at a time between author-chosen endpoints, with the others fixed, then divides the difference between the two modeled costs by the base cost (at u = 0.5, $0.489 per million). A swing of 2.15 is a 215%-of-base endpoint spread, not a 215% probability, elasticity, or observed change:
| Input (range) | Endpoint cost swing / base cost at u = 0.5 |
at u = 0.1 |
|---|---|---|
| hours powered a year (2,000 to 8,766) | 2.15 | 2.48 |
| system price (500 to 3,000 USD) | 1.06 | 1.22 |
| waste ratio (0 to 1) | 1.00 | 1.00 |
| capacity (2 to 4 requests/s) | 0.80 | 0.80 |
| operations (0 to 50 USD a month) | 0.76 | 0.87 |
| life (2 to 5 years) | 0.52 | 0.60 |
| electricity (0.10 to 0.50 USD per kWh) | 0.49 | 0.36 |
| busy power (120 to 300 W) | 0.30 | 0.07 |
| cost of capital (0 to 15%) | 0.21 | 0.24 |
| idle power (40 to 100 W) | 0.10 | 0.21 |
The ranking is conditional on the chosen endpoints. For this dedicated, assumed-always-powered machine, effective useful throughput, powered hours and standing costs dominate within the tested ranges; the sampled GPU-board power and assumed electricity price affect a smaller share. However, the tornado changes capacity and waste independently even though an actual deployment’s batching, error rate, power and duty cycle can move together. The exercise is most useful for asking which measurement or business assumption to improve next, not for ranking universal determinants of inference economics. A rented GPU paid continuously by the hour has a different standing-cost structure, and a rental that can be stopped when idle has a different relation between powered time and utilisation. The chapter does not test either configuration.
Busy is not full
The busy-fraction model cannot on its own explain costs as batch fill changes. Holding a dedicated system active all the time and looking only at the decode microbenchmark, the analyzer spreads the same assumed capital plus zero operating charge over each batch’s output rate and adds its measured GPU-board energy per token. It intentionally excludes the rest of the machine’s electricity, prefill, hosting and networking. These are not complete per-request costs and are not on the same accounting boundary as the preceding utilisation table:
| Decode batch | Capital and operations | GPU energy | Total |
|---|---|---|---|
| 1 | 0.468 | 0.208 | 0.676 |
| 2 | 0.224 | 0.107 | 0.331 |
| 4 | 0.110 | 0.064 | 0.174 |
| 8 | 0.069 | 0.046 | 0.115 |
| 16 | 0.057 | 0.041 | 0.098 |
| 32 | 0.051 | 0.038 | 0.089 |
| 64 | 0.049 | 0.038 | 0.087 |
(The energy column is the board only, and the table does not include the idle power of the rest of the machine, so it is not comparable with the previous table’s totals.) Under the isolated decode-only accounting rule, batch 1 to batch 8 reduces the modeled cost per generated token from $0.676 to $0.115, approximately 83%. That does not establish 100% GPU compute utilisation; it assumes the decode benchmark has work to execute continuously. A cost model with utilisation alone would call these the same. Useful output delivered per paid hour depends jointly on busy fraction, achieved batch fill, token lengths and discarded work. The reconciliation below estimates these effects from recorded request intervals; it does not measure batch occupancy’s precise contribution to GPU energy.
Input tokens and output tokens
A provider has separate input- and output-token prices. For this self-hosted experiment, split_by_class instead allocates an assumed hourly total between prefill and decode according to estimated phase busy-time share, then divides by each class’s assumed token count. The 9.0% prefill share for batch 4 comes from an idealized combination of measured phase microbenchmarks and a modeled batch shape; it was not timed as a 9% fraction of the Chapter 36 live serving runs. At u = 0.5, this accounting convention assigns $0.0066 per million input tokens and $0.445 per million output tokens (about 68:1); at u = 0.1, $0.0285 and $1.93; and at full busy fraction, $0.0038 and $0.260. The input and output figures are allocated shares of the same hourly cost, not separately metered marginal prices, and should be used together with the corresponding token volumes rather than each mistaken for the all-in output-token rate of $0.489.
Allocating by token count would produce a different price for each class, as would allocating by phase energy, peak capacity or reserved memory. Prefill typically processes many tokens in parallel whereas autoregressive decode advances output one step at a time, but this implementation cannot conclude that every output token universally costs 68 times an input token. The dated API price table shows output/input ratios around 5:1 or 6:1 for the named products and tiers. Those ratios are commercial prices, not public measurements of the providers’ internal marginal energy or compute costs; they may reflect workload mix, cache policy, capacity reservations, operations, margins and strategy. There is no valid inference about a provider’s underlying costs or profitability from comparing its list-price ratio with this allocation.
Forecast, metered, billed
The estimator keeps three evidence categories separate, but a category label alone is not external verification. forecast() predicts costs from an offered rate and a full-batch capacity. meter() reprices observed workload volume using assumed financial and power inputs unless explicitly supplied independently measured energy. reconcile() accepts an external invoice line only if its dictionary reports basis: billed and contains cost_usd; it does not authenticate an invoice or verify that its period and token mix match. The distinction is therefore both a reporting convention and a checklist for evidence still to collect.
- Forecast is the cost predicted from an offered arrival rate, assumed full-batch capacity, fixed output-token mix and assumed financial and power rates; a finite observation window is used to calculate total modeled cost.
- Metered-at-assumed-rates is a retrospective model estimate: its window, observed output tokens and request-overlap proxy for busy fraction come from the saved run. No load-run wall-socket energy, purchase transaction or invoice was measured.
- Billed would be an actual invoice, scoped to a billing period with line items, taxes, discounts and currency recorded. No invoice was supplied, so
NOT_RUNis correct. The present code checks thebilledlabel and the presence ofcost_usd, not the documentary authenticity or comparability of an invoice.
For the Chapter 36 open-loop experiments, meter_runs reuses the recorded request submission/finish times and output counts after dropping warm-up requests. It derives the observed interval, estimates busy_fraction from the union of request-in-system intervals, and recalculates an average prompt/output token mix. It then calls meter() without an energy_j measurement, causing energy to be priced from the same assumed idle and active power inputs used by forecast(). Consequently the following tables compare an offered-rate/full-batch-capacity projection with a finite-run retrospective estimate under shared monetary and power assumptions. They test how useful delivered tokens and the workload’s actual server-busy fraction affect cost accounting; they do not validate measured electrical expenditure or billed spend. For batch 1:
| Offered (req/s) | Forecast busy fraction (model) | Request-overlap busy fraction | Forecast (modeled USD/1M output) | Retrospective estimate (same rates) | Retrospective / forecast |
|---|---|---|---|---|---|
| 0.39 | 0.39 | 0.43 | 1.903 | 1.909 | 1.00 |
| 0.79 | 0.78 | 0.87 | 1.051 | 1.075 | 1.02 |
| 1.18 | 1.00 | 1.00 | 0.867 | 0.943 | 1.09 |
| 1.78 | 1.00 | 1.00 | 0.867 | 0.945 | 1.09 |
| 2.47 | 1.00 | 1.00 | 0.867 | 0.975 | 1.12 |
The same retrospective calculation for batch 4, which frequently runs a partially filled batch at light load, shows a much larger divergence between the estimated busy fraction and the constant-full-batch assumption:
| Offered (req/s) | Forecast busy fraction (model) | Request-overlap busy fraction | Forecast (modeled USD/1M output) | Retrospective estimate (same rates) | Retrospective / forecast |
|---|---|---|---|---|---|
| 0.39 | 0.12 | 0.41 | 1.788 | 1.971 | 1.10 |
| 0.79 | 0.25 | 0.66 | 0.936 | 1.076 | 1.15 |
| 1.18 | 0.37 | 0.82 | 0.652 | 0.762 | 1.17 |
| 1.68 | 0.52 | 0.88 | 0.485 | 0.552 | 1.14 |
| 2.47 | 0.77 | 0.98 | 0.356 | 0.388 | 1.09 |
| 3.55 | 1.00 | 1.00 | 0.293 | 0.330 | 1.13 |
Across the fourteen recorded runs the retrospective cost per useful output token divided by forecast cost ranges from about 1.00 to 1.17. This is a within-model reconciliation, not an empirical 17%-accuracy bound against actual costs. At batch 4 and roughly 0.39 offered requests/s, the forecast uses u≈0.12 but the request-overlap proxy gives u≈0.41, about 3.4 times as large. The code’s identity decomposes the per-token-cost ratio into a utilisation/spreading factor (approximately 0.33) and a delivery-rate factor (approximately 3.31): their product is about 1.10. The identity follows algebraically because both terms use the same F, V and output-token accounting and egress is zero here; it does not independently validate the energy assumptions or explain every physical cause of the discrepancy.
The direction of the mismatch is consistent with static batch fill. At low arrival rates the batch-4 worker often serves batches smaller than four, so it can be occupied much longer than an offered-rate divided by peak-batch-capacity forecast predicts, while producing roughly the offered number of useful output tokens. For an always-powered dedicated machine the standing charge accrues over the whole wall-clock window even when the queue is empty. With near-equal forecast and observed delivered volumes, dividing similar standing charges by those volumes can yield close per-token estimates despite a poor forecast of the busy fraction. At higher offered rates, arrival variability and incomplete full-batch utilisation also lower observed delivery compared with a 40-request burst capacity test. The proposed explanation is consistent with the server design and the recorded volumes; a phase-level power trace and batch-occupancy analysis were not performed to apportion the residual to individual mechanisms. In particular, the residual 0–17% is not an independently measured forecast error against electricity spend.
This reconciliation is between a model and a measurement priced with the model’s own rates. It is not between the model and money. A billed or wall-meter-backed number could disagree for many reasons absent here: the true electricity contract, idle duty cycle, metering accuracy, cooling and power-supply losses, maintenance, rental charges, retries, taxes, idle reservations and unused capacity. The code’s optional invoice slot is not a substitute for matching the accounting period, currency, volume, rate tier and service level before comparing costs.
The price of a token and the price of an answer
A low unit cost is useful only when the workload’s successful outcomes are counted consistently. Chapters 33–35 report generated tokens per solved GSM8K problem or per exactly-right synthetic order record. cost_analysis.priced multiplies those recorded ratios by a single batch-4 modeled output-token rate at 50% busy fraction, $0.489 per million, to illustrate how quality and retry choices change output-token expenditure per success. It does not rerun those tasks on the batch-4 serving workload, and it does not include input/prefill tokens, variable prompt lengths, separate GPU tool execution, external API fees or per-request standing overhead. The Chapter 34 no-tool row uses mean token count and mean correctness across eight samples rather than a literal first-sample cost baseline; see that chapter’s caveat. The cross-chapter columns are illustrative, not a shared calibrated cost for all three experiments:
| Original task and method | Recorded generated tokens / correct outcome | Modeled output-token USD / 1,000 correct outcomes | Ratio within same chapter |
|---|---|---|---|
| GSM8K (Chapter 33), one non-thinking sample | 474 | 0.232 | 1.0 |
| majority of 3 | 1,338 | 0.654 | 2.8 |
| majority of 8 | 3,383 | 1.654 | 7.1 |
| thinking, budget 128 | 596 | 0.291 | 1.3 |
| thinking, budget 1,024 | 2,180 | 1.066 | 4.6 |
| adaptive thinking | 2,591 | 1.267 | 5.5 |
| GSM8K (Chapter 34), no tool | 444 | 0.217 | 1.5 |
| tool loop | 293 | 0.143 | 1.0 |
| tool loop, 30% faults, 3 runtime retries | 394 | 0.193 | 1.3 |
| order records (Chapter 35), constrained | 114 | 0.056 | 1.0 |
| braces cut out, unconstrained | 158 | 0.077 | 1.4 |
| as written | 301 | 0.147 | 2.6 |
| validate and retry | 616 | 0.301 | 5.4 |
Under the chosen generated-token-only allocation, an eight-sample majority in Chapter 33 is about 7.1 times as expensive per solved problem as one non-thinking sample, in exchange for its recorded accuracy difference. Chapter 35’s unsuccessful validate-and-retry path costs about 5.4 times as much per exactly-right record as constrained decoding, because repeated generations remain in the token numerator. Chapter 34’s calculator loop is the cheapest per correct result in the displayed model, yet it solves only 28% of the same 100 tasks against 57% for the no-tool first sample: lower cost per success can hide unacceptable coverage or very different failure consequences. These are ratios of saved generated-token totals divided by counts of correct outputs, not end-to-end prices for external services. A system purchase decision needs both its task-specific quality/SLO gate and the cost of the entire attempted workload, including incorrect results, prompts, extra calls and irrecoverable failures. Applying an additional general waste multiplier to these already waste-inclusive token ratios would double-count some work.
Against list prices
Price snapshots, not a cross-model value ranking. The repository freezes USD-per-million-token price entries as they were read on 23 October 2026, including Claude Haiku 5.5 (prompts up to 100,000 tokens) $0.10 input/$0.50 output, Haiku 4.5 $1/$5, Sonnet 5.5 $2/$10 and Fable 5.1 $10/$50; and OpenAI gpt-6-luna $0.10/$0.50, gpt-5.6-luna $0.20/$1.20 and gpt-6.1-sol $2/$10. The same dated source register records examples of cache, batch, long-context and region-dependent prices; they are not included in the comparisons below. Lambda’s recorded single-GPU hourly examples were $0.69 for a Quadro RTX 6000, $1.29 for an A10, $1.99 for an A100 40 GB and $3.29 for an H100 PCIe. Consult the primary pages before using any figure operationally: model availability, price tiers, cached-input discounts, billing increment, region and term can change. These are posted rates, not a price quote for equivalent accuracy, latency, uptime or capacity. None of these external products was benchmarked against the local model.
The next two calculations are price-threshold thought experiments using these frozen October 2026 rate inputs and the chapter’s local assumptions. They do not compare model quality, measured provider bills, hardware equivalence, or end-to-end total cost of ownership.
Break-even utilisation, on an output-token-only basis. Solving 10^6·(F + V·u)/(T·u) = P for the assumed batch-4 system gives a break-even busy fraction of about 0.49 against a $0.50-per-million *output* price, about 0.18 against $1.20, 0.041 against $5, 0.021 against $10 and 0.004 against $50. Those are algebraic thresholds within the 32-output-token workload and zero-egress model. They ignore billed input tokens, provider minimums, caching, any service-level differences and the model’s task accuracy. The cheapest API output price is not necessarily a cheaper answer, and the 0.6B local model’s result is not quality-equivalent to a hosted model merely because both count tokens.
Rental break-even, distinguishing peak-when-busy rate from wall-clock rate. The helper required_tokens_per_second(hourly_rate, target_output_price, utilisation) calculates the required tokens/s during busy hours, assuming the rental is paid for all hours and achieves no output while idle. For an A10 at the frozen $1.29/GPU-hour and target $0.50 per million outputs, that is about 717 tokens/s while busy at 100% utilisation, 1,433 while busy at 50%, and 2,867 while busy at 25%; the corresponding wall-clock averages at all three thresholds are approximately 717 tokens/s, because the hourly rental charge does not fall when the machine is idle. At $10 per million, the busy-hour thresholds are about 36, 72 and 143 tokens/s. An H100 PCIe at $3.29/GPU-hour requires about 1,828, 3,656 or 7,311 tokens/s while busy to match $0.50. If the rental can actually be switched off or billed only while busy, those equations must change. Additional charges, GPUs per instance, failure reserve, reliability and prompt costs are excluded. The measured peak of 326 tokens/s is from different hardware and does not establish any rental’s performance.
Pope and colleagues’ paper on scaling transformer inference is the standard reference for why the two regimes in the measurements above exist at scale. Pope et al. was published at MLSys 2023, not merely as an unplaced arXiv preprint. Its abstract reports 29 ms per output token at low batch size using int8 weights and 76% model FLOPs utilisation during large-batch input processing for PaLM 540B on TPU v4. Those are performance measurements, not prices, and none was reproduced here. For energy accounting, Samsi et al. (IEEE HPEC 2023), Fernandez et al. (ACL 2025), and Vellaisamy et al. (2026 preprint) further motivate measuring energy per complete request as well as per generated token: prompt length, decode length, hardware, batch and server overhead jointly determine useful cost. Their findings are external context, not substitutes for a wall-meter trace of the book’s own machine.
Egress
The assumed 104 bytes per output token (roughly four text bytes plus 100 bytes of amortized streaming/transport framing) yields 104 million bytes for one million output tokens, or 0.104 decimal GB. Actual framing normally depends on stream chunking, not one independent frame per token; the value is a placeholder, not a captured network trace. At $0.01, $0.05, $0.09 and $0.12 a gigabyte that adds $0.001, $0.005, $0.009 and $0.012 to a cost of $0.49, or 0.2%, 1.1%, 1.9% and 2.5%. Under these assumed tariffs and message format, egress is a small addend rather than a measured operational fact. Media payloads, inter-region traffic, retries, downloads and billing minimums can change that conclusion. The line is retained to make such costs explicit in future deployment measurements.
What the numbers do not show
No spend or invoice has been verified. The purchase price, financial life, residual value, operating charge and electricity rate are placeholders. Even the energy bill for the Chapter 36 runs is modeled from the saved busy fraction and assumed whole-machine power profile, not from power sampled during those runs. The tables establish arithmetic and sensitivity under a documented scenario; they do not establish an observed cost of ownership or a 17%-accurate financial forecast.
Only GPU-board power was sampled. nvidia-smi produced NVIDIA driver-reported board power at roughly 100 ms intervals, with no independent instrument verification. The additional 34 W idle and 50 W busy for the rest of the computer, and the assumed PUE of 1.0, are placeholders. They leave out uncertainty from CPU load, memory, storage, fans, power-supply loss and facility overhead. Some short prefill runs have too few readings for a precise joules-per-token estimate; the table is a local operational characterization, not an electrical-meter validation.
Prices are dated observations. All quoted API and GPU-rental rates in the repository were recorded on 23 October 2026. Their current validity, applicable context tier, billing granularity, region, storage/network charges, contract terms and discount eligibility must be verified from the linked provider pages before a purchasing decision. A dated list price is not a bill, a contract, a model-quality comparison or an estimate of a comparable end-to-end workload.
Quality and service levels are not interchangeable. Self-hosting a 0.6-billion-parameter model is not a substitute for a more capable API without matched evaluations on the same prompts, accuracy requirements, refusals, structured-output policy and latency targets. Even comparing two methods of the same model by tokens per correct answer must account for how many users received wrong or missing answers, not only the price of the successful subset.
One shared desktop is not a serving fleet. The model, CPU-affinity policy, Hugging Face Python loop, static-batch capacity and GPU-board measurement are machine- and workload-specific. No multi-node scheduler, autoscaling, power-down policy, real customer workload, continuous batching, reserved redundancy, production uptime, actual invoice or independently metered energy was tested. Larger models, quantisation changes and long contexts can change both throughput and energy per request.
Inference Lab increment
examples/ch37/cost_core.py adds Assumptions (required provenance labels, notes and range validation, but no external evidence verification), hourly_cost, cost_per_million_output_tokens, cost_per_request, split_by_class, breakdown, sweep_utilisation, sweep, tornado, break_even_utilisation, required_tokens_per_second, forecast, meter, decompose, reconcile and default_local. meter can accept independently measured joules but the Chapter 36 retrospective runs do not supply them; required_tokens_per_second returns a busy-hour rate at partial utilisation.
examples/ch37/cost_lab.py adds a driver-based GPU board power sampler and the commands power and phases. phases reports fixed-shape isolated prefill/decode measurements; it does not record whole-system watts during Chapter 36 service runs, or account for power-sampling error on very short prefill runs.
examples/ch37/cost_analysis.py freezes the 23 October 2026 list-price snapshots, energy_per_token, decode_cost_by_batch, reference_assumptions, busy_fraction, meter_runs (request-interval-derived busy fraction, modeled power), tokens_per_solved, priced, break_even_tables and egress_check.
To rebuild the derived tables from the repository’s existing measurements and prior chapters’ saved runs (this is analysis only; it does not gather new power data or provider bills):
python research/ch37/build_results.py
To repeat the chapter’s local GPU-board phase microbenchmarks (requires the recorded model and GPU environment; duration and power precision vary). This is not a rerun of Chapter 36’s serving load or a wall-socket measurement:
python examples/ch37/cost_lab.py phases --out research/ch37/measurements/phases.json
The rule this chapter adds: price useful work over a named time window, with a named numerator and denominator. Separate standing capital/operating cost from idle and incremental busy energy; label every rate and workload input by its actual evidence basis; distinguish percent of time doing any work from batch fill and delivered throughput; and report whether the result is a projection, observed usage priced at assumed rates, independently metered electricity or an invoice. Cost per output token is a diagnostic, not an adequate buying criterion until correctness, latency, prefill/decoding mix, retries and the costs of failed requests have been included.
What you should now be able to do
- Write cost per million tokens as a standing cost and a variable cost over delivered tokens, and say what each input of the model is and where it came from.
- Distinguish a machine being busy, a batch being full and a GPU being efficient, and say which of them a given “utilisation” is.
- Estimate average GPU-board joules per generated token from sampled power and throughput, explain sampling/error boundaries, and distinguish it from whole-system energy per completed request.
- Run a one-at-a-time sensitivity test and read which inputs decide the cost at low and at high use.
- Share a cost between input and output tokens by a stated rule, and say why the answer differs from a provider’s price ratio.
- Separate forecasts, retrospectively observed token counts priced at assumed rates, independently measured energy, and billed spend; interpret the algebraic reconciliation without mistaking it for external cost validation.
- Price an answer and not only a token, including the work thrown away.
- Calculate illustrative rental or self-hosted break-even busy-hour throughput thresholds under paid-idle assumptions, and explain why matched quality, input charges and service-level targets remain necessary.
Key terms
- Amortisation: spreading a purchase price over a machine’s life, here with a residual value and a cost of capital.
- Standing cost: cost that accrues with the clock, whether or not the machine is busy.
- Utilisation (busy fraction): the fraction of powered time the serving system executes inference work; in this chapter’s retrospective code, estimated by the union of request-in-system intervals, not a GPU activity meter.
- Batch fill: how much of the machine’s peak throughput a batch delivers.
- Waste ratio: work done and discarded per unit of useful work.
- Forecast: a cost from a model and planned load.
- Metered-at-assumed-rates cost: observed request volume and window priced using the model’s financial and power assumptions; independent joule measurements are optional and absent from these runs.
- Billed spend: the amount on an invoice.
- Tornado: a chart of the effect of moving each input alone across its range.
- Goodput-style denominator: generated work per correct task outcome; this does not by itself encode availability, latency, or the cost of the complete attempted workload.
Reader exercises
- Replace the placeholders with your own receipt, tariff and a wall-socket power meter, and rerun the sensitivity test; report which input now dominates.
- Measure the whole machine’s power, not the board’s, at idle and under batch-4 decode, and say how much of the cost the allowance in the chapter misjudged.
- Add a rental paid for all reserved hours (F becomes the hourly rate, V zero), then add a second rental that can be released when idle. Compare busy-hour and wall-clock output-rate thresholds for both contracts.
- Make the estimator price a cache hit: a fraction of prompt tokens served from a cache at a tenth of the cost, and compare with Chapter 32’s break-even.
- Replace static batching with a continuous-batching loop in Chapter 36’s server and repeat the metered runs; see whether the utilisation and delivery effects still cancel.
- Add an error budget: aborted requests that did half their work, and compare the waste ratio with the work discarded in Chapter 34’s retries.
- Obtain a real, authorised month’s invoice and wall-meter logs. Extend
reconcileto verify currency, billing period, evidence path, unit prices and corresponding usage before splitting differences into rate, volume, mix and fixed costs. - Add a test that refuses an invoice with a mismatched time window and a test that distinguishes request-overlap busy fraction from directly sampled GPU-active time. Require a matched-quality/SLO comparison before asserting an economic winner.
References
- Efficiently Scaling Transformer Inference — Pope et al.; Proceedings of Machine Learning and Systems 5 (MLSys 2023). Analytical treatment of partitioning, latency and MFU for very large transformer inference, with 29 ms/token and 76% MFU reported for distinct generation/prefill regimes on PaLM 540B/TPU v4. Not reproduced; no provider monetary cost established.
- From Words to Watts: Benchmarking the Energy Costs of Large Language Model Inference — Samsi et al.; IEEE HPEC 2023. Studies LLaMA inference energy and performance across V100/A100 hardware and multi-GPU model sharding. Cited for experimental energy-accounting context; not reproduced.
- Energy Considerations of Large Language Model Inference and Efficiency Optimizations — Fernandez et al.; ACL 2025. Shows that measured inference-energy effects depend on hardware, software and workloads and that theoretical performance surrogates can mislead. Not reproduced.
- Characterization of Request and Token Energy Costs for LLM Inference Workloads on GPU Platforms — Vellaisamy et al.; arXiv preprint, August 2026. Separates fixed request/prefill energy from marginal generation work and compares energy per request with energy per output token. Not peer-reviewed venue-verified in this review; not reproduced.
- Pricing — Anthropic; official, changeable provider price list. Chapter’s entries frozen as quoted on 23 October 2026; current contract, context tier and region require rechecking.
- API pricing — OpenAI; official, changeable rate schedule. Entries in
cost_analysis.pyare historical October 2026 snapshots; distinguish Standard, Batch/Flex and Fast/other service tiers. - Pricing — Lambda; published GPU-rental examples read 23 October 2026, not a contracted or fully loaded price and with billing granularity unverified in the saved source.
- Qwen3-0.6B — the tested local model; Apache-2.0; checkpoint revision
c1899de289a04d12100db370d81485cdf75e47ca.
Evidence in this chapter
| Claim | Category |
|---|---|
| GPU-board readings: 26.1 W idle, 85 W batch-1 decode and 148 W batch-64; average board joules/generated token 2.49 to 0.45 | Book result (nvidia-smi readings; no wall-meter or independent calibration) |
| Prefill ran at 3,647 to 7,694 tokens/s and decode at 34 to 326 tokens/s on this model and machine | Book result |
| At the placeholder rates the cost of a million output tokens fell from $10.27 (batch 4) and $32.72 (batch 1) at 2% use to $0.285 and $0.844 at full use | Book result conditional on placeholder money inputs |
| At 100% busy the capital and GPU energy cost of a million generated tokens fell from $0.676 at batch 1 to $0.087 at batch 64 | Book result conditional on placeholder money inputs |
| Hours powered, price, waste and capacity decide the cost more than electricity price or power draw | Book result conditional on the stated ranges |
| Across fourteen runs, forecast and retrospective cost estimates using the same assumed power/financial rates differed by 0–17%, even though their modeled/request-overlap busy fractions differed up to 3.4-fold | Book arithmetic reconciliation; not measured electricity expenditure or external predictive accuracy |
| Busy-time allocation assigns output about 68 times input per-token cost under a modeled phase share at 50% busy fraction; list-price ratios are about 5–6 | Book-derived cost allocation versus dated, externally quoted prices, not provider marginal-cost evidence |
| A solved problem cost up to 7.1 times, and an exactly right record up to 5.4 times, the cheapest method of its chapter at one price per token | Book result from earlier chapters’ counts |
| Egress at assumed tariffs of up to $0.12/GB added at most 2.5% | Book result conditional on an assumed 104 bytes a token |
| Billed spend or independently metered whole-machine electricity for the load runs | NOT_RUN (neither an invoice nor whole-system load-run joule measurement supplied) |
| Provider prices and discounts as quoted, rental prices as quoted | Reported by the pages on 23 October 2026; not a quote for any contract |
| Pope et al.’s latency and MFU figures | Reported by the abstract; not reproduced |
| Whole-machine power, real prices, tariff, life and operating costs, other GPUs, model quality | NOT_RUN |
Implementation status
- Manuscript:
content/books/inference/37-chapter.md - Runnable examples:
examples/ch37/cost.py(original, unchanged),examples/ch37/cost_core.py(the estimator),examples/ch37/cost_lab.py(power and phase measurements),examples/ch37/cost_analysis.py(analyses and dated prices) - Tests:
tests/test_ch37_cost.py(original),tests/test_ch37_cost_lab.py(27 tests: provenance labels/notes and range validation, JSON round trip, capital recovery with and without interest, the cost formula by hand, monotonicity in utilisation, breakdown and class split adding up, waste and egress, break-even and required-throughput inverses, the tornado, forecast, metered and billed entries and the decomposition identity, busy fraction, energy per token, within-chapter ratios, the frozen results being read, and the starter’s single rate) - Evidence:
research/ch37/sources.md,research/ch37/results.json,research/ch37/measurements/,research/ch37/build_results.py,research/evidence-register.md. The load-run energy is modeled from Chapter 36’s request timestamps and assumed watts, not captured from a load-time wall power meter - Verification command:
python -m unittest discover -s tests -v
The chapter is available for publication review (draft = false) but retains evidence qualifications. No real money, whole-machine load-run energy, production hosted inference quality comparison or GPU rental throughput was measured. The strongest result is an auditable way to expose assumptions and reconcile forecasted and observed workload volumes, not a claim that the chosen dollars are real spend or that the cheapest output token is the cheapest acceptable answer. Chapter 38 examines GPU utilisation from a different measurement perspective.