The Real Cost of LLM Subscriptions: Cache Reuse and Speculative Decoding
A deep dive into why high token counts on a coding-agent workload translate into surprisingly low actual compute costs. This article explains how prompt cache reuse, speculative decoding, and continuous batching let subscription plans stay profitable, breaks down the four metering units behind a bill, lists five anti-patterns that destroy cache hit rates ("cache taxes"), and gives six practical rules plus a cost formula for building cacheable, predictable, and attributable LLM applications.
1. The Billing Paradox: Why “Billions of Tokens Used” Doesn’t Equal “Billions of Dollars Spent”
Let’s define the problem precisely. A developer who uses an AI coding tool intensively over a year tallied token counts in the tens of billions. When converted at raw API per-token pricing, that figure came to hundreds of times what they actually paid in subscription fees. The comparison is common in the industry: at the same budget, a subscription tier often grants “equivalent quota” worth dozens of times the pay-as-you-go allowance.
The gap isn’t mysterious. It comes from a widely misread premise: token count is a capacity metric, not a cost metric.
Under most billing schemes, a single request is split into four metering units:
| Metering unit | Compute nature | Relative cost |
|---|---|---|
| Uncached input (requires full forward pass) | Compute-intensive, scales with sequence length | Baseline price |
| Cached input | Only reads the already-cached intermediate state | Significantly below baseline (often around one-tenth) |
| Cache write | Extra cost of establishing the cache for the first time | Slightly above baseline input |
| Output | Token-by-token autoregressive generation, serial and compute-intensive | Usually several times the input |
The “total tokens” on a bill is typically the sum of these categories. When more than ninety percent of monthly consumption is cached-input reads, the account figure and the actual compute cost can diverge by one to two orders of magnitude. This is exactly the defining trait of coding-agent workloads.
2. The Structure of Agent Workloads: A “Heavy Replayer”
Early conversational interactions were simple question-and-answer exchanges. Context length grew linearly with each turn, and repetition was limited. Agents are entirely different. Their work loop is fundamentally high-frequency replay over a continuously growing context:
def agent_loop(task, tools, max_turns=40):# Stable prefix: system instructions + tool definitions, unchanged throughoutmessages = [{"role": "system", "content": SYSTEM_PROMPT},{"role": "user", "content": task},]for _ in range(max_turns):resp = model.chat(messages=messages, tools=tools) # replays full history every turnif not resp.tool_calls:return resp.textmessages.append(resp.assistant_message)messages.append(execute(resp.tool_calls)) # only appends at the tail
In the request at turn 40, the content from the first 39 turns is byte-for-byte identical to the request at turn 39; only the latest tool-execution result is appended at the end. In other words, most of the input in a long session is pure repeated content, and the newly generated, genuinely new information may account for only a few percent of the input.
This workload structure has decisive implications for inference systems:
- Repeated prefixes can be cached and reused. The server keeps the key-value (KV) state of a given prefix in GPU memory or tiered storage. When a later request hits that prefix, it skips the forward computation for that portion and simply continues computing new tokens. The compute cost of the hit portion approaches a single GPU memory-bandwidth read, which is on a completely different scale from recomputing the full prefix.
- Coding-task prompts are naturally highly stable. System instructions, tool and function signatures, project-level convention files, and repository summaries barely change during a task, and this is precisely the longest part of the context.
- Speculative decoding further compresses serial overhead. A lightweight draft proposes several candidate tokens, which the main model then verifies in parallel and accepts up to the correct prefix. Code text is more locally predictable than natural language (indentation, closing brackets, fixed API shapes, templated structures), so acceptance rates are typically higher. This effectively turns “generating token by token in series” into “batch verification,” lowering both the time and compute cost per unit of output.
Layer on top of this continuous batching and paged KV-cache management on the service side: requests from different users are packed into the same batch, the GPU doesn’t sit idle while waiting for a long session to decode its next token, and memory fragmentation is pushed to a minimum. The macro effect is that the same hardware can serve far more subscription users under this specific workload, and that is the technical foundation that makes subscriptions viable.
3. The Business Logic of Subscriptions: Statistical Reuse, Not Charity
A subscription plan is essentially wholesale capacity plus statistical reuse, the same idea behind airline overbooking, shared broadband bandwidth, and cloud reserved resource pools:
- What’s sold in a bundle is “average capacity after peaks and valleys are mixed,” not “instantaneous peak.” Users don’t run at full load around the clock, and even within a single session there’s plenty of time spent thinking, reading, and switching tasks.
- Heavy users drive retention and word of mouth, while costs stay controllable. Cache hit rates are extremely high in coding scenarios, and the heaviest users tend to be exactly the ones who benefit most from caching. Their marginal cost is structurally diluted.
- Tiered pricing does the filtering. Lightweight tiers cap concurrency and context length, while heavy tiers open up quota, using a price gradient to steer resources toward scenarios that can bear a premium, while engineering pushes overall utilization higher.
Conversely, both the “outrageous profit” and “huge loss” narratives are illusions. Profitability depends on workload structure, not on total token count. For the same token count, actual compute cost can differ by more than ten times between a conversational scenario with a 5% cache hit rate and an agent scenario with a 95% hit rate.
4. What Kills the Cache Dividend: Five “Cache Taxes”
Caching isn’t unconditionally free. The following anti-patterns make hit rates fall off a cliff and push costs back up to pay-as-you-go levels:
- Prefix pollution. Inserting the current timestamp, a random request ID, a randomly ordered tool list, or a changing user profile into the system prompt or the first message. Any single byte of change invalidates all caching that comes after it.
- Editing history in place. “Correcting,” “compressing,” or “reformatting” earlier messages so the prefix is no longer byte-for-byte identical.
- Tool-set bloat. Injecting a hundred or more tool definitions at once, which both lengthens the fixed prefix (consuming context budget even when cached) and makes the model’s selection harder.
- Repeated context-window trimming. Sliding the window or reordering summaries with a different strategy each turn, which destabilizes the range that can be hit.
- Poor cache-lifecycle management. Caches have a time-to-live; after a long pause, the first request must write the cache again, and frequently written small fragments dilute the cost of cache writes.
The way to check is direct: monitor whether the prefix fingerprint is stable.
import hashlib, jsondef prefix_fingerprint(messages, upto):blob = json.dumps(messages[:upto], ensure_ascii=False, separators=(",", ":"))return hashlib.sha256(blob.encode()).hexdigest()[:12]# Across a multi-turn loop, check whether each round's newly added# content and the existing prefix fingerprint stay consistent.# If the fingerprint changes, caching was broken this round, and you# need to locate which message changed.
5. Engineering Practice: Six Rules for Fully Capturing the Cache Dividend
- Fix the order and keep the prefix stable. Arrange content as “system instructions → tool definitions → project-level long-term context → task and history,” and always put volatile information last.
- Append, don’t rewrite. Append to history messages only; never rewrite them. When a correction is needed, state it in a new message rather than editing old content.
- Load tools and context on demand. Dynamically expose the relevant subset of tools based on the task phase, and accept a single cache invalidation at natural boundaries such as phase transitions, rather than jittering every turn.
- Read large files in chunks. When reading a codebase, append it in blocks instead of rereunning the whole file, and reference line numbers instead of copying the entire text.
- Set a checkpoint at the end of the session. When a long task approaches the context limit, proactively produce a structured summary and use it as the new prefix starting point, trading one write for many rounds of high hit rates afterward.
- Make the output more predictable. Constrain the model’s output with an explicit structure convention (fixed fields, fixed order), which both improves speculative-decoding acceptance rates and lowers downstream parsing costs.
It’s worth standardizing on five observability metrics: cache hit rate, uncached-input token ratio, number of cache writes, time-to-first-token, and cost per task. Without the first two, any cost optimization is guesswork. For data collection, you can compose general-purpose capabilities: use logging and monitoring/alerting to accumulate metrics and fire threshold alerts, use a message queue to smooth out batch-task peaks, use object storage to archive sessions and evaluation sets, and use a container platform to handle elastic scaling of the inference service.
6. The Cost Model: A Formula You Can Apply Directly
Here $N{in}^{hit}$ is the number of input tokens that hit the cache. Plug in typical agent-scenario ratios (output is a few percent of input, and over ninety percent of the input hits the cache), and apply the relationship $p{cache} \ll p_{in}$, and you can explain why a book value of tens of billions of tokens collapses into a very small actual spend.
This yields two practical rules:
- Improving the hit rate pays off more than shrinking the total token count. Prioritize eliminating prefix jitter rather than rushing to trim the prompt.
- Shortening the output pays off more than shortening the input. Output is usually priced at a higher rate and cannot be cached, so having the model cut the fluff and deliver actionable changes directly gives the most immediate payoff.
For enterprise adoption, three more things are needed: first, attribute cost to team/project/scenario dimensions rather than looking only at the aggregate; second, set quotas, concurrency caps, and queue-degradation strategies for batch tasks to avoid peaks trampling each other; third, run quality regression on a fixed task set to confirm that cost optimization hasn’t come at the expense of effectiveness.
7. Conclusion
The gap between tens of billions of tokens and the subscription fee isn’t a broken business model. It’s the combined result of metering conventions and workload structure. Cache reuse turns repeated context into a near-free read, speculative decoding turns serial generation into batch verification, and continuous batching fills idle compute. Stacked together, these three are what keep an extreme workload like a coding agent sustainable under a subscription model. General practices at cloud providers such as Baidu AI Cloud, across inference services and observability, similarly center on the theme of “raising effective utilization.”
For developers, the takeaway is practical: don’t fixate anxiously on total token count; watch prefix stability and output density. Shape your requests into a form that is cacheable, predictable, and attributable, and you capture the cost advantage, the latency advantage, and output-stability advantage at the same time. In inference engineering, those three have never been mutually exclusive goals.
