Why Inference Costs Are Far Lower Than Billable Token Counts Suggest
A developer's billing report showed roughly $200 in subscription fees alongside 16 billion consumed tokens—a figure that would cost around $100,000 under standard pay-per-token pricing. This article explains why that gap is structural rather than subsidized, covering two mechanisms: KV cache reuse, which makes repeated prefixes nearly free to process, and speculative decoding, which multiplies output throughput in long sessions. It also explains why coding agents benefit most, and ends with a practical checklist for context engineering and local cost observability.
1. The Bill That Started the Debate: 16 Billion Tokens
A senior developer recently published a year’s worth of usage data from an AI coding tool: the subscription cost was in the low hundreds of dollars, while the dashboard reported a cumulative 16 billion tokens consumed. Converted at typical pay-per-token rates, that volume would come to something in the six-figure range. The post split the community in two directions: one camp argued the vendor was subsidizing users with investor money, the other suspected the metering itself was broken.
Then more measured data appeared. Different subscription tiers were reported to support anywhere from a few hundred million to nearly ten billion equivalent tokens per week, and a semiconductor and compute analysis group estimated that top-tier plans correspond to metered usage worth tens of times the subscription price. On paper, this looks like a business that must be losing money.
That conclusion is premature. The real question is whether every one of those tokens triggered a complete forward pass from scratch.
2. Misread Tokens: Billable Volume Is Not Compute Volume
In early chat-style applications, one question produced one answer, and token consumption tracked compute consumption roughly linearly. Coding agents changed that relationship fundamentally. To keep a task coherent, the agent must resend the system prompt, project structure notes, conversation history, previously read file excerpts, and tool call results on every single turn.
The result is a defining characteristic: the prefix is highly repetitive. Within a session, the input to a later request is usually a superset of the previous one, with new observations appended only at the tail. In other words, most input tokens are being replayed, not newly written.
If both billing and cost accounting assume a linear relationship with raw token counts, the resulting conclusion is badly distorted. In real systems, that repeated prefix does not need to be recomputed.
3. Mechanism One: KV Cache Reuse Makes Repeated Prefixes Nearly Free
Every layer of a Transformer generates Key and Value tensors for each token—the KV. They supply the contextual representations that attention needs during subsequent generation. Computing KV requires full matrix operations, while reading cached KV is just a memory-bandwidth transfer, and the two differ in cost by several orders of magnitude.
That is why mainstream inference implementations use prefix caching: the content features of the input prefix serve as an index, and on a hit the existing KV is reused directly, with computation limited to the newly added portion:
# Pseudocode: prefix cache lookup and incremental computationdef build_request(context_messages, new_observation):prefix = context_messages # history, identical to the previous turndelta = [new_observation] # content added this turncache_key = hash(normalize(prefix))if cache_store.hit(cache_key):kv = cache_store.load(cache_key) # memory/VRAM read onlytokens_billed_as_full = len(prefix) # still counted on the billtokens_actually_computed = count(delta)else:kv = prefill(prefix) # first time requires full prefillcache_store.save(cache_key, kv)return generate(kv, delta)
This is the first layer of divergence between the bill and actual cost: billable tokens are counted in full, while compute is paid for only incrementally. The higher the hit rate, the lower the marginal cost per token—and the session structure of a coding agent naturally pushes that hit rate very high.
One engineering constraint matters here: the cache is indexed by exact prefix, so any rewrite of earlier content invalidates everything after it. A stable prefix with tail-only appends is therefore the most cost-efficient way to organize context.
4. Mechanism Two: Speculative Decoding Multiplies Output in Long Sessions
The second underappreciated technique is speculative decoding. The idea is to have a lightweight draft model guess several consecutive tokens, then have the main model verify them in a single parallel pass, accepting the matching prefix and recomputing from the point of divergence.
Because verification across multiple positions can run in parallel while autoregressive generation must wait on each token serially, a single round can produce several tokens when the draft hit rate is decent, substantially raising end-to-end throughput. Coding work is especially well suited to this: code completion, boilerplate structure, repeated branches, and common API call patterns are all highly predictable.
Draft model: for (int i = 0; i < n; i++) { -> guesses 8 tokensMain model verify: accepts the first 6, diverges at the 7th -> recompute from that positionResult this round: one forward pass produces 6 tokens instead of 1
Stacked together, the two mechanisms multiply: cache reuse drives down input-side cost, while speculative decoding raises output per unit of time. What looks like excessive margin is really a structural mismatch between the metering convention and physical cost, not a subsidy.
5. Why Coding Is the Ideal Ground for These Mechanisms
Coding agents hit nearly every favorable condition:
- Long, stable context prefixes: system instructions, repository structure, and dependency lists stay unchanged throughout a task.
- Append-style interaction: reading files, running tests, and inspecting errors all add new observations at the tail.
- High output predictability: code and structured text are highly regular, which raises draft hit rates.
- Long, continuous sessions: a single task can span dozens of turns, so cache reuse is amortized repeatedly.
Open-ended writing or casual chat is the opposite: short prefixes, divergent output, and fragmented sessions shrink the gains from both mechanisms considerably. This explains a common observation—why the same subscription lasts so much longer when used for coding.
6. A Practical Checklist for Developers
Once the mechanisms are clear, cost optimization has concrete levers:
- Keep the prefix stable: put system prompts, convention notes, and directory structure first and leave them unchanged; avoid reordering or rewriting them mid-task.
- Append at the tail: add new retrieval results and tool output at the end to preserve cache hits.
- Control context growth: truncate and summarize logs and test output, and read long files in segments on demand.
- Use structured output: ask the model for parseable formats, which improves verifiability and raises draft hit rates.
- Split sessions: start a new session when switching tasks so unrelated history does not occupy the context window indefinitely.
- Instrument for observability: log input/output tokens, cache hit ratio, and end-to-end latency on the application side, and use monitoring, alerting, and a log service to establish a cost baseline.
A minimal local metrics hook:
metrics = {"input_tokens": 0, # billable input"cached_tokens": 0, # portion served from cache"output_tokens": 0,"latency_ms": 0,}def record(resp):metrics["input_tokens"] += resp.usage.input_tokensmetrics["cached_tokens"] += getattr(resp.usage, "cached_tokens", 0)metrics["output_tokens"] += resp.usage.output_tokensmetrics["latency_ms"] += resp.latency_mshit_ratio = metrics["cached_tokens"] / max(metrics["input_tokens"], 1)return hit_ratio
When the hit ratio stays low over time, look first at whether the context is being rewritten frequently, rather than rushing to swap models or cut features.
7. Conclusion
The “cache tax” confusion comes from measuring a nonlinear system with a linear yardstick. KV cache reuse pushes the marginal cost of repeated prefixes toward zero, speculative decoding multiplies output in long sessions, and AI coding happens to exploit both to the extreme. For developers, the payoff is not in arguing whether vendors lose money, but in mastering context engineering: fix the parts that do not change, append the parts that are new, and keep measuring hit performance with data. To put this into practice in your own environment, you can run inference services on a container platform, store sessions and artifacts in object storage, and track cost metrics through a logging and monitoring stack—striking a controllable balance between quality and spend.
