Reducing LLM Inference Costs: A Technical Guide to Unit Cost per Token
This article presents a vendor-neutral engineering approach to lowering the unit cost per token of large language model (LLM) inference while keeping quality loss within an acceptable range. It starts with a cost model showing why output length usually dominates spending, then walks through six practical techniques: model routing, quantization and distillation, prefix and semantic caching, batching and scheduling, output length governance, and observability with cost attribution. It also covers common pitfalls such as judging models by price alone, stuffing entire documents into prompts, retry storms, and one-off overhauls, and closes with a phased rollout plan that tracks cost per thousand requests alongside quality scores.
1. Background: Why Unit Cost per Token Is the Core Metric
A recurring narrative in recent industry discussions is that a new model delivers results close to those of leading closed-source models at a fraction of the price, often with open weights or free quotas. When this kind of message spreads, it usually carries a promotional element, and arguments in the comments about whether something is an ad or an independent review point to one thing: what users actually care about is reproducible cost and quality data, not the wording of a launch presentation.
This article therefore strips out all specific products and brands and focuses on a neutral, long-lived engineering question: how to reduce the unit cost per token of LLM inference in your own application while keeping quality loss within an acceptable range. The value for practitioners is direct: serve more requests under the same budget, or turn gross margin positive at the same request volume.
Any claim of being “N times cheaper” must be tied to a verifiable basis, otherwise the comparison is meaningless. It helps to align internally on four measures:
- Billing basis: whether input and output tokens are priced separately, and whether cache hits are discounted;
- Quality basis: pass rate or human rating on the same evaluation set with the same decoding parameters;
- Latency basis: time to first token and overall throughput measured separately;
- Failure basis: hidden costs from timeouts, truncation, and rate-limit retries.
2. Cost Model: Do the Math First
Let the input tokens per request be $L{in}$, the output tokens be $L{out}$, the input price be $p{in}$, and the output price be $p{out}$. The cost per request is approximately:
Cost = L_in * p_in + L_out * p_out
Because output tokens are usually generated autoregressively one token at a time, $p{out}$ is generally higher than $p{in}$, so output length is often the dominant cost driver. This leads to three immediately actionable conclusions:
- Compressing output is more effective than compressing input: constraints such as “output JSON only” or “no more than 200 words” reduce cost linearly;
- Reusable parts of the input should hit the cache as much as possible to amortize the cost of repeated prefixes;
- Long-context scenarios require caution about “billing the full prefix repeatedly”, which needs to be addressed at the architecture level.
3. Six Practical Cost-Reduction Techniques
3.1 Model Routing
Split requests by difficulty: send simple intent recognition, format conversion, and extraction tasks to smaller models, and escalate only complex reasoning and long-form writing to large models. Routing signals can come from rules, a classifier, or the confidence of the previous turn.
def route(req):if req.task in {"classify", "extract", "format"} and req.length < 2000:return "small_model"if req.reasoning_depth >= 3:return "large_model"return "mid_model"
Engineering notes: the router itself must be extremely lightweight, so that the savings are not eaten by routing overhead; also keep a manually overridable allowlist to prevent a bad downgrade from degrading the user experience.
3.2 Quantization and Distillation
Weight quantization (for example 8-bit or 4-bit) has controllable loss on most generation tasks, and memory usage drops roughly linearly, which increases concurrency on the same GPU. Distillation uses a large model to generate high-quality samples for training a smaller model, compressing capability into a smaller footprint. The two can be combined: distill a small model first, then quantize it for deployment.
Note: after quantization you must run regression evaluations, especially for numerical computation, long-chain reasoning, and code tasks, which are more sensitive to precision.
3.3 Prefix Caching and Semantic Caching
- Prefix caching: fixed prefixes such as system prompts, tool definitions, and few-shot examples can reuse the KV cache, reducing repeated computation;
- Semantic caching: cache final answers for frequent, similar questions and return them on a hit.
User question -> normalize (strip spaces / unify case / remove punctuation)-> vector similarity above threshold ?hit: return cached answer directlymiss: call the model and write back to cache
Risk note: semantic caching needs a TTL and an invalidation policy, and caching must be disabled when real-time data is involved (prices, inventory, account status).
3.4 Batching and Scheduling
Offline tasks (log summarization, bulk labeling, content moderation) should go through an asynchronous batch queue that aggregates requests into large batches to improve GPU utilization. Online tasks should use continuous batching with a sensible maximum concurrency to control tail latency. A typical split:
- Online: message queue for peak shaving + elastic scaling on a container platform + rate limiting and graceful degradation;
- Offline: land raw data in object storage, rerun batch jobs uniformly, which also makes cost accounting easier.
3.5 Output Length Governance
State structural constraints explicitly in the system instruction, and combine them with a server-side max_tokens limit and streaming responses to control cost and improve perceived speed. Example:
{"response_format": "json","max_output_tokens": 512,"instructions": "Output JSON only, no explanation; fill missing fields with null"}
3.6 Observability and Cost Attribution
Without measurement there is no optimization. Log the following for every call: model tier, input/output tokens, whether the cache was hit, latency, and retry count, tagged with a business-line label, to build a cost dashboard by team and by endpoint. The logging service handles collection, and monitoring and alerting notify the owner when a single endpoint’s cost spikes.
4. Common Pitfalls
- Looking only at unit price, not effective output: a cheap model that needs multiple rounds of rework can cost more overall;
- Blindly extending context: stuffing an entire document collection into the prompt raises both input cost and truncation risk; use retrieval augmentation instead and recall only relevant fragments;
- Ignoring retry storms: retries without backoff under rate limiting inflate the bill, so exponential backoff and circuit breaking are mandatory;
- One-off big-bang rewrites: cost reduction should roll out gradually, validating quality and latency on a small traffic share before ramping up.
5. Suggested Rollout Plan
- Week 1: complete call instrumentation and the cost dashboard, and establish a baseline;
- Weeks 2–3: ship output length constraints and prefix caching, usually the highest-value step;
- Week 4: introduce model routing and compare quality on 10% of traffic via canary release;
- Month 2: move stable offline scenarios to batch processing and quantized deployment, and evaluate the feasibility of distillation;
- Ongoing: establish a monthly cost review, using “cost per thousand requests” and “quality score” as dual metrics.
In short, reducing inference cost is not about finding a single “cheaper model”, but a systems engineering effort spanning routing, caching, quantization, scheduling, output governance, and observability. Align the measures and connect the data, and the cost curve will naturally move into a controllable range.
