How to Calculate LLM Inference Costs: From Hardware Procurement to Cost per Million Tokens
A practical framework for calculating large language model inference costs. This article explains how to build a unified cost model across hardware depreciation, data center expenses, operations, and effective throughput, how prefill and decode phases differ, how cache hit rates affect pricing, and how to derive the final cost per million tokens.
How to Calculate LLM Inference Costs: From Hardware Procurement to Cost per Million Tokens
Why Token-Based Cost Accounting Matters
LLM services are metered by tokens, so inference cost ultimately comes down to a single metric: cost per million tokens. Comparing individual server prices or GPU specifications alone cannot answer two key questions: how much service volume a given budget can support, and whether your service pricing leaves room for profit. Only by putting hardware investment, data center expenses, and actual throughput into the same accounting framework can you make comparable decisions.
Three things must be standardized before calculating:
- Accounting period — typically annualized
- Unit of measurement — cost per million input + output tokens
- Load assumptions — input/output ratio, cache hit rate, concurrency, and utilization
If any of these differ, results cannot be compared directly.
The Four Components of a Cost Model
1. Hardware Procurement and Depreciation
Equipment purchase price is the most straightforward item. Bulk purchases typically come in below list price, but discount levels depend on order volume, contract length, and delivery schedules — use the actual contract figures. The depreciation period determines annualized cost: a longer period lowers annual amortization, but rapid technical iteration can render hardware uncompetitive before end of life. A common practice is straight-line depreciation over three to five years, with a separate sensitivity analysis on the depreciation period.
Annualized hardware cost = Total equipment purchase price ÷ Depreciation period (years)
2. Data Center and Power
Inference clusters consume significant power, so electricity becomes a substantial share of long-term operating cost. Electricity prices vary widely by region, and a facility’s PUE (Power Usage Effectiveness) changes actual power consumption. Operating costs also include rack rental, network bandwidth, cooling upgrades, and spare-part replacement. It’s advisable to aggregate these expenses annually as a separate line item rather than mixing them with hardware depreciation.
3. Operations and Personnel
As clusters scale, monitoring, incident handling, model version upgrades, and performance tuning all require dedicated staff. This component is usually a small share of total cost, but for small teams it can become a major variable.
4. Effective Throughput
Effective throughput is the key denominator when converting cost into per-token pricing. It refers to the number of tokens a production environment can sustainably output, which is typically lower than benchmark stress-test results. Benchmarks run at ideal concurrency with fixed input lengths, while real traffic has pronounced peaks and valleys and far more complex request length distributions. A common industry practice is to apply a discount factor to benchmark figures before using them for capacity planning.
Prefill and Decode: Two Phases with Different Characteristics
Every inference request goes through two phases.
Prefill processes all input tokens at once. Computation here is highly parallel and compute-bound. The longer the input, the longer this phase takes, and the higher the time-to-first-token (TTFT).
Decode generates output tokens one at a time. Each new token requires reading the accumulated KV Cache, so this phase is bound by memory bandwidth and memory access latency.
Because the two phases have different bottlenecks, the same hardware can show significantly different throughput depending on the input/output ratio. Code assistance and long-document analysis workloads, where inputs dominate, are prefill-heavy; content generation workloads, where outputs dominate, are decode-heavy.
How Cache Hit Rate Affects Cost
When multiple requests share the same prefix — for example, an identical system prompt, a long document, or a code repository context — the server can reuse the already-computed KV Cache and skip that portion of prefill computation. Cached input tokens can therefore be billed at a lower unit price, and the provider’s compute cost drops accordingly.
The effect of cache hit rate can be expressed as a weighted average:
Blended input price = Hit rate × Cached price + (1 − Hit rate) × Uncached price
The higher the hit rate, the lower the blended price. Common ways to improve hit rate include:
- Keeping the system prompt at a stable prefix position
- Minimizing the insertion points of per-request variable content
- Expanding cache capacity across the cluster
Caching can be tiered: combining GPU memory, host memory, and local SSD allows more historical prefixes to be retained. Each tier has different access latency, however, so the choice should be balanced against your application’s TTFT requirements.
Prefill/Decode Disaggregated Deployment
A common architecture deploys prefill and decode on separate node groups. Prefill nodes focus on high-throughput computation, while decode nodes focus on memory capacity and bandwidth; each group scales independently according to its load. The benefit is higher resource utilization, especially when input and output lengths differ significantly. The trade-off is that KV Cache must be transferred between nodes, raising both network bandwidth requirements and scheduling complexity.
Whether to adopt disaggregated deployment depends on three factors: whether the workload’s input/output ratio is stable, whether cluster scale is large enough to amortize scheduling overhead, and whether the team has the operational expertise to run it. For small clusters, collocated deployment is usually simpler and easier to troubleshoot.
Calculating Cost per Million Tokens
Combining the factors above yields an annualized cost model:
Cost per million tokens = (Annualized hardware cost + Annualized data center cost + Annualized operations cost)÷ (Annual tokens processed ÷ 1,000,000)Annual tokens processed = Effective throughput (tokens/s) × Operating seconds per year × Utilization
The output is a single figure — cost per million tokens — that lets you compare hardware options on equal footing, validate your pricing model, and identify which levers (depreciation period, cache hit rate, utilization, deployment architecture) move the economics most.
