Skip to content
Inference Academy

Cost per million tokens: how to calculate what your LLM really costs to serve

A step-by-step method for turning GPU prices into cost per million input and output tokens for a self-hosted LLM, with a worked example for a 70B model on H100s, why output tokens cost several times more than input tokens, and the five levers that move the number most.

Key takeaways

  • Cost per million tokens is GPU cost per hour divided by millions of tokens served per hour, at the latency target you actually need.
  • Split the cost: prefill GPUs set the input-token price, decode GPUs set the output-token price.
  • In the worked 70B example, output tokens cost about 6 times more than input tokens, which is why APIs price them higher.
  • Average utilisation matters as much as GPU price: hardware idle half the day doubles the cost of every token.
  • The latency target, prefix caching, quantisation and GPU choice are the biggest levers after utilisation.

By

7 min read

Share
On this page

API providers quote prices per million tokens. GPU providers quote prices per hour. If you self-host, or are deciding whether to, you need to convert one into the other, and the conversion hides most of the interesting decisions.

#The formula

cost per million tokens=GPU cost per hourmillions of tokens served per hour\text{cost per million tokens} = \frac{\text{GPU cost per hour}}{\text{millions of tokens served per hour}}

The top is easy: GPUs times price per GPU-hour, plus a share of networking, storage and CPU hosts if you're being thorough. The bottom is where the work is. Tokens per hour depends on the model, the hardware, the engine, the traffic shape, and above all the latency target, because a stricter target means smaller batches and fewer tokens per GPU.

So never quote a cost per token without saying at what latency.

#Split input and output

Input tokens (prefill) and output tokens (decode) use the GPU very differently (prefill vs decode):

  • Prefill processes thousands of tokens in parallel and is compute-bound. Tokens per second is high.
  • Decode produces one token per sequence per step and is bandwidth-bound. Tokens per second is much lower.

If you serve them on separate pools, cost each pool separately. If they share GPUs, split the GPU time by how much each phase uses (engines' metrics or a profile tell you).

#A worked example

Take the capacity plan from how many GPUs do you need to serve an LLM: a Llama-class 70B in FP8 on H100s, 1,000 requests a minute, 8K-token prompts, 1K-token answers, P95 time to first token under 1 s and P95 end-to-end under 10 s. That plan used 8 nodes:

Pool Nodes GPUs Work per hour
Prefill 4 32 about 491 million input tokens
Decode 3 24 about 61 million output tokens
Headroom 1 8 spare capacity for failover

Assume $2.50 per H100-hour for illustration (use your own quote; prices vary widely by provider, commitment and region). Then:

  • Prefill: 32 × $2.50 = $80 per hour, over 491 million input tokens: about $0.16 per million input tokens.
  • Decode: 24 × $2.50 = $60 per hour, over 61 million output tokens: about $0.98 per million output tokens.
  • Headroom: the spare node adds 8/7 to both, giving about $0.19 input and $1.12 output.

Output tokens cost about 6 times more than input tokens here. That ratio is why API price lists charge more for output: it's a direct consequence of decode being bandwidth-bound.

#A smaller example: an 8B model on one GPU

Not every deployment is 64 GPUs. Take a Llama-class 8B model with FP8 weights and an FP8 KV cache on one H100, serving 64 concurrent chats that each hold about 2,048 tokens of context.

Each decode step reads the weights once (about 8 GB) plus every sequence's KV cache (64 × about 0.13 GB, about 8.6 GB). At 70% of the H100's bandwidth, that's about 7 ms per step, producing 64 tokens:

640.007 s≈9,000 output tokens per second\frac{64}{0.007 \ \text{s}} \approx 9{,}000 \ \text{output tokens per second}

That's about 32.6 million output tokens per hour. At $2.50 per GPU-hour, decode costs about $0.08 per million output tokens, before utilisation and overheads. Small models are dramatically cheaper to serve, which is why routing easy requests to a small model is one of the biggest cost levers in production.

This is a bandwidth-model estimate, not a measurement; real engines add overheads, and a strict latency target might cap the batch below 64. Measure before you rely on it.

#From tokens to cost per request

Product teams think in requests, not tokens. Convert with your request shape. Using the 70B prices from the worked example:

Request Input tokens Output tokens Cost per request Cost per million requests
Document Q&A 8,192 1,024 about $0.0027 about $2,700
Same, with a reasoning model thinking 5,000 tokens first 8,192 6,024 about $0.0083 about $8,300

Reasoning models change the economics: thinking tokens are output tokens, the expensive kind, so a model that "thinks" before answering can cost several times more per request even at the same price per token. Track output tokens per request, not just request counts.

#Where the GPU price comes from

The $2.50 used above is a placeholder. Real prices vary a lot:

  • On-demand cloud is the most flexible and most expensive per hour.
  • Reserved or committed capacity (one to three years) is usually much cheaper per hour, but you pay whether you use it or not, which makes utilisation even more important.
  • Spot or preemptible capacity is cheapest, but can be taken away at short notice; it suits batch jobs and stateless replicas behind a router that can retry.
  • Owned hardware turns the hourly price into purchase cost spread over its useful life, plus power, cooling, space and staff.

Plug your actual price into the formula; the method doesn't change.

#The catch: utilisation

That example assumes steady traffic at exactly the planned rate, around the clock. Real traffic has peaks and troughs. If you size for the peak and can't scale down, the effective cost is:

effective cost=cost at full loadaverage utilisation\text{effective cost} = \frac{\text{cost at full load}}{\text{average utilisation}}
Average utilisation Effective output-token cost (from $1.12)
80% about $1.40
50% about $2.24
25% about $4.48

This is the single biggest reason self-hosting disappoints: an idle GPU still costs money. Autoscaling, batch jobs in the troughs and sharing GPUs across models all raise average utilisation (autoscaling policies, batch and offline inference).

#The levers, ranked

Lever Typical effect Example from the plan above
Utilisation Cost scales with its inverse 50% instead of 100% doubles every token's cost
Latency target Looser targets allow bigger batches Relaxing end-to-end from 10 s to 20 s cuts decode from 3 nodes to 2
Prefix caching Shared prompt tokens skip prefill 50% shared prompt tokens halves the prefill pool
Quantisation Fewer bytes per weight and per KV entry FP8 to FP4 roughly halves the weight bytes read each decode step (FP8 vs INT4 vs FP4)
GPU choice Price per unit of bandwidth or compute A newer GPU wins if its price rises less than its bandwidth (H100 vs H200 vs B200)
Model size Fewer parameters, fewer bytes and FLOPs An 8B model needs roughly a tenth of the 70B's hardware

Notice that the GPU choice is near the bottom. Product decisions (latency targets, prompt design for cache reuse, model size) usually matter more.

#Costs people forget

  • Headroom for failover and traffic spikes, as in the example.
  • Idle replicas kept warm to avoid cold starts (cold starts and model loading).
  • Evaluation and staging GPUs for testing new models and engine versions.
  • Engineering time to run the platform: on-call, upgrades, incidents. At small scale this can exceed the GPU bill.
  • Networking and storage: model weights in object storage, egress, logs.

#Check it against reality

  1. Run your real traffic shape on one node and record tokens per second per GPU at your latency target (how to benchmark an LLM server).
  2. Read the average utilisation from a week of production metrics, not a guess.
  3. Compute cost per million input and output tokens, then compare with API prices for a comparable model (self-hosting vs API).

The token cost calculator and the self-host vs API calculator do the arithmetic for you.

#A spreadsheet you can build in ten minutes

One row per pool (prefill, decode, headroom), with these columns:

  1. GPUs in the pool.
  2. Price per GPU-hour.
  3. Cost per hour (1 × 2).
  4. Measured tokens per second for the pool at your latency target.
  5. Millions of tokens per hour (4 × 3,600 ÷ 1,000,000).
  6. Cost per million tokens at full load (3 ÷ 5).
  7. Average utilisation from production metrics.
  8. Effective cost per million tokens (6 ÷ 7).

Add a headroom row whose cost is spread across the others, and a monthly engineering cost divided by monthly tokens. Change one input at a time (latency target, prefix-cache hit rate, precision, GPU type) to see which lever matters most for you.

#Common mistakes

  • Quoting a cost per token without a latency target. The same GPUs can give very different numbers at different targets.
  • Assuming 100% utilisation.
  • Blending input and output tokens into one price when your traffic is unusually input-heavy or output-heavy.
  • Ignoring reasoning tokens in output counts.
  • Using a benchmark's peak throughput instead of goodput at your targets (serving metrics).

#FAQ

Why is my cost per token so much higher than API prices? Usually low utilisation, a strict latency target or a small deployment without batching. API providers run at very high utilisation across many customers.

Should input and output be priced separately internally? If you charge back to teams, yes: it encourages shorter outputs and cache-friendly prompts, which are the cheapest savings available.

How often should I recompute this? Whenever the model, engine version, hardware, prices or traffic shape changes, and at least every few months.

#Go deeper

Capacity planning and cost covers this method in full, and queueing theory for LLM capacity explains how much headroom a latency target needs. Both are in the Serving AI in Production course.

costcapacity-planningservinggpusinference-engineering

Found this useful?

Send it to someone who is learning the same thing.

Share this article

Next: learn it step by step, free

Capacity planning and cost

Turn traffic and latency targets into a GPU count and a monthly bill. A free lesson with step-through diagrams and a quiz.

Get new articles by email

One short email when a new guide is out. Unsubscribe any time.