LLM Inference Cost Control: A Practical Guide to Token Billing
This article explains why LLM inference bills often grow non-linearly and breaks down the three key cost variables: unit price, prefix cache hit rate, and context length. It covers model routing to reserve high-capability models for high-stakes tasks, budget observability with alerts and circuit breakers, context compression, a practical price anchor for individual users, and a vendor selection checklist centered on keeping the model backend replaceable.
1. Where the Problem Starts: Why Token Bills Suddenly Spike
Many teams have no real sense of inference cost during the prototype stage. Only after the application goes live and daily call volume climbs do they notice that the billing curve is not linear — it jumps sharply at a certain point. The phenomenon described in the source material is common: with the same plan and the same usage habits, a change in the upstream pricing policy alone can shrink the supported call volume by several times. This is not a usage problem; the cost model itself is extremely sensitive to unit price.
To understand this, start by breaking a single request down into its token components. Tokens are commonly divided into input (prompt) and output (completion), and the input side is further split into a reusable common prefix and the incremental content that changes on every call. The common prefix includes system prompts, tool definitions, fixed repository context, and long document templates; the incremental content is what the user actually submits on that call. This distinction is the foundation for every optimization technique that follows.
2. Three Key Variables in the Cost Structure
2.1 Unit Price: The Most Visible but Least Controllable
Unit price is the only variable decided unilaterally by the provider. For consumers, the goal is not to predict unit price but to avoid treating a “low price” as a permanent assumption in the business model. Any architecture designed on the premise that “the current unit price allows unlimited calls” will break the moment prices move.
2.2 Cache Hit Rate: The Underrated Lever
Mainstream inference services generally offer prefix caching: when the common prefix is identical across multiple requests, that portion of the input can reuse existing computation, substantially reducing both billing and latency. The key takeaway is that caching is usually priced differently for the “hit” and “miss” portions, and the discount on the cached portion is often far larger than on the output portion. So when a caching policy tightens and the unit price of the hit portion rises several times over, the supported call volume drops proportionally — even if the total token count is unchanged. The gap in the source material, where supported volume falls from the billions to the low billions, is essentially the hit-rate weight being repriced.
The engineering practice for raising the hit rate is a stable prefix design:
[Fixed zone] System instructions + tool schema + long-term memory + examples[Semi-fixed zone] Repository structure summary, interface conventions (low-frequency updates)[Variable zone] Current user input, retrieved snippets
Once the order is shuffled, or timestamps, random IDs, or request sequence numbers are mixed into the fixed zone, the cache is invalidated entirely.
2.3 Context Length: The Hidden Multiplier in Linear Cost
Even with an unchanged unit price, repeatedly sending the entire conversation history makes cost grow roughly quadratically with the number of turns. Turn N carries the full content of the previous N-1 turns, and in long sessions this is the main source of bill inflation — not longer individual outputs.
3. Tiered Routing: Spend on the Right Model
The core practice in the source material is worth abstracting: use low-cost models for “exploratory, disposable” subtasks and high-capability models for “decision-making, precision-critical” main tasks. Architecturally, this is called model routing or tiering.
A typical division of labor:
| Task type | Characteristics | Suggested tier |
|---|---|---|
| Codebase search, file location, initial log triage | High volume, high fault tolerance, verifiable results | Low-cost tier |
| Unit test generation, comment completion | Patterned, batchable | Low-cost tier |
| Architecture design, difficult defect localization, cross-module refactoring | Low frequency, high cost of error | High-capability tier |
A minimal working router:
def route(task):if task.kind in ("search", "locate", "summarize_log", "test_scaffold"):return cheap_modelif task.risk == "high" or task.requires_reasoning:return strong_modelreturn cheap_model
The point to stress is that tiering does not mean “always use the cheap model.” Instead, the intermediate results produced by the cheap model (candidate files, suspicious code segments) become the input to the high-capability model, which compresses the high-capability model’s context length. This step lowers two variables at once: the token volume of the expensive model and the overall cache pressure.
4. Budget Governance: Turning Cost into an Observable Metric
Cost governance starts with observability. At minimum, collect these dimensions: token consumption by day and by business line, cache hit ratio, average context length, average turns per task, and number of failed retries. Retries are the most easily overlooked cost sink — a single timeout retry often means paying for the entire long context again.
Supporting alerting and circuit-breaking policies:
- Daily budget threshold alerts (for example, notify at 70%, degrade at 90%);
- A per-session turn cap, after which context compression is forced instead of continued appending;
- Automatically check whether the prefix has been polluted when the hit rate falls below baseline;
- Back off and retry failed requests to avoid avalanche-style repeated billing.
Context compression can replace full history replay with a rolling summary:
def build_context(history, keep_turns=3, max_summary_tokens=800):recent = history[-keep_turns:]older = history[:-keep_turns]summary = summarize(older, max_tokens=max_summary_tokens) if older else ""return f"[Summary]{summary}\n[Recent]{render(recent)}"
5. The Price Anchor: An Acceptable Range for Everyday Users
From the demand side, for inference services to become a routine expense “like water and electricity,” the price needs to sit within a psychological anchor. Based on the source material, the upper limit an ordinary individual user will accept is roughly one to three yuan per hundred million tokens; above three yuan, it only suits niche or high-value scenarios. The value of this anchor is that it provides a hard constraint for selection: when an option pushes monthly cost beyond the anchor, the right move is to optimize context and tiering strategy rather than passively accept the bill.
6. Selection Checklist
- Does it support prefix caching, and is the hit rate observable?
- Does it offer multiple model tiers to enable tiered routing?
- Does it provide usage dashboards, budget alerts, and quota management?
- Do data compliance, invoicing, and settlement processes meet organizational requirements?
- Is there single-vendor lock-in, and can the backend be switched through a unified abstraction layer?
The last point matters most. Once model calls are wrapped behind your own abstraction layer, changes in price and capability become configuration adjustments rather than architecture rewrites:
class ModelBackend:def call(self, prompt: str, tier: str) -> str: ...# Switch backends via configuration; business code is unaware of the concrete implementationBACKEND = load_backend(config["llm"]["backend"])
7. Conclusion
Uncontrollable inference cost usually does not come from using too much, but from an architecture missing three pieces: cache-friendly design, tiered routing, and budget observability. Get these three solid, and even a several-fold upstream price change leaves the business within an acceptable spending range. And because the market moves fast, keeping the backend replaceable is the fundamental defense against uncertainty.
