Low-Cost LLM Inference: From Token Billing to Task-Level Cost Optimization
As LLM applications shift from “can it generate?” to “can it generate reliably, quickly, and at low cost?”, this article explains how token billing, cache hits, retries, routing, and monitoring determine the true cost of a complete task. It provides formulas, worked examples, and engineering practices for estimating, monitoring, and reducing inference costs while keeping quality and reliability in view.
In recent years, competition in LLM applications has gradually moved from “whether the model can generate” to “whether it can generate reliably, quickly, and at low cost.” For scenarios such as enterprise customer service, content moderation, coding assistance, data extraction, and intelligent retrieval, the unit price of a model is not the only metric. The real concern is the comprehensive cost of completing one full task.
Pricing examples published for some newer lightweight inference models show that input token prices can be as low as about CNY 0.5 per million tokens, while output token prices are about CNY 2 per million tokens. When a request hits the cache, billing for repeated context may fall further to about CNY 0.02 per million tokens. With reasonable control over context and output length, the average cost of a complete task may be only a few tenths of a yuan.
However, “completing a task for a few tenths of a yuan” does not mean every request runs at the same cost. The final cost depends on input size, output size, cache hit rate, whether multi-turn context is included, and whether the task requires multiple model calls. Understanding these factors is necessary to turn advertised unit prices into an implementable engineering budget.
1. How Token Billing Affects Task Cost
LLMs generally bill input tokens and output tokens separately. The following general formula can be used to estimate the cost of one request:
Cost per request =input tokens ÷ 1,000,000 × input unit price+output tokens ÷ 1,000,000 × output unit price
Assume a task contains 80,000 input tokens and 50,000 output tokens. With input at CNY 0.5 per million tokens and output at CNY 2 per million tokens:
Input cost = 80,000 ÷ 1,000,000 × 0.5 = CNY 0.04Output cost = 50,000 ÷ 1,000,000 × 2 = CNY 0.10Total cost = CNY 0.14
If the task also includes multi-turn calls, tool result pass-back, or additional context concatenation, the total cost may continue to rise. Therefore, looking only at the model unit price is not enough; estimates should be based on actual business traffic and average token consumption.
In real projects, it is advisable to track at least the following four metrics:
- Average input tokens;
- Average output tokens;
- Number of model calls per task;
- Share of requests by task type.
For example, a simple classification task may require only a few hundred tokens, while long-document analysis may require tens of thousands. Mixing all requests into one calculation can easily hide the cost pressure caused by high-consumption tasks.
2. Why Caching Can Significantly Reduce Costs
Many applications repeatedly send identical or highly similar content, such as system prompts, enterprise knowledge base descriptions, business rules, fixed-format requirements, and historical conversation summaries. This content is retransmitted in every request, which not only increases latency but also raises input token costs.
The core idea of caching is to identify repeated context in requests and apply lower billing to parts that have already been processed. According to the pricing example above, input cost after a cache hit may drop to about CNY 0.02 per million tokens, significantly below the normal input price.
Caching is especially suitable for the following scenarios:
- Intelligent customer service with long fixed system prompts;
- Moderation systems that load the same set of business rules on every request;
- Multiple question-answer rounds over the same long document;
- Multi-turn code analysis that repeatedly references project background;
- Batch processing that shares the same instructions and format constraints.
However, caching does not mean that all repeated text will necessarily hit the cache. Engineering implementations usually need to consider context order, whether content has changed, cache validity period, and whether request structure is consistent. If preceding content changes frequently, or if the system prompt is interrupted by dynamic fields, cache benefits may decline.
Therefore, it is recommended to split request content into three layers:
Fixed layer: role definition, general rules, output formatSemi-fixed layer: business knowledge, document content, process constraintsDynamic layer: user question, real-time data, current task parameters
Placing fixed content at the front of the request and keeping its format as stable as possible helps improve cache utilization. Dynamic information should be placed later so that a small change does not prevent the entire context from being reused.
3. Why Average Task Cost Cannot Be Based on Model Price Alone
Raw price comparisons are often attractive, but enterprises really care about “the cost per valid result.” If a low-cost model needs to be called three times repeatedly to reach acceptable quality, its actual cost may not be low.
The following formula can be used for a more complete calculation:
Valid task cost =model call cost+retry cost+result validation cost+retrieval and tool call cost+infrastructure operating cost
Retry cost is often overlooked. When model output has a format error, is incomplete, violates business rules, or fails validation, the system may need to retry automatically. If the retry rate reaches 10% to 20%, the overall cost will be significantly higher than the theoretical single-call price.
In addition, long-chain intelligent applications usually are not simple “question-and-answer” systems. They may include:
- Intent recognition;
- Document retrieval;
- Content reranking;
- Main model generation;
- Structured validation;
- Failure retry;
- Writing results to a database or messaging system.
Therefore, models should be evaluated at the level of the complete business workflow, not just by testing a single simple question-and-answer interaction.
4. Which Tasks Are Suitable for Low-Cost Models
Low-cost models do not mean they are suitable for every complex scenario. For tasks with clear boundaries, explicit formats, and relatively high tolerance for errors, lightweight models are often more cost-effective.
Tasks that are relatively suitable include:
- Text classification and label generation;
- Keyword extraction;
- Information extraction in fixed formats;
- FAQ answering;
- Simple summarization and rewriting;
- Ticket routing;
- Preliminary log analysis;
- Batch content preprocessing;
- Structured field completion.
For tasks that require rigorous reasoning, complex planning, high-risk decisions, or professional fact verification, human review, rule validation, or a more capable model for secondary processing should be added.
A common engineering strategy is “tiered routing”:
Low-complexity requests → low-cost modelMedium-complexity requests → standard modelHigh-risk or complex requests → high-capability model + human or rule review
This controls overall cost while avoiding the use of high-cost models for all traffic just because of a small number of complex requests.
5. How to Build an Actionable Cost Monitoring System
In production environments, it is advisable to record complete usage information for every model call, including:
- Request ID;
- Business scenario;
- Model category;
- Input tokens;
- Output tokens;
- Whether the cache was hit;
- Call latency;
- Whether a retry occurred;
- Whether quality validation was ultimately passed;
- Estimated cost per call.
On this basis, cost reports can be built by day, department, application, and task type. For example, the total cost of a customer service application can be broken down as follows:
Total customer service cost =number of sessions × average calls per session× average cost per call
Quality metrics can also be added:
Cost per valid result =total model cost ÷ number of valid results that pass quality validation
This metric is more useful than the raw price per million tokens because it accounts for model capability, retry rate, and result usability at the same time.
6. Practical Methods for Reducing Token Consumption
First, compress historical conversations. There is no need to pass all historical messages to the model in full. Summaries can be generated periodically, keeping only information relevant to the current task.
Second, reduce ineffective instructions. System prompts should be clear but not verbose, and the same rule should not be explained repeatedly.
Third, control output format. For extraction tasks, explicitly require fixed fields to prevent the model from generating extra explanations.
Fourth, use segmented processing. For very long documents, do not insert all content at once. Extract information in chunks first, then summarize.
Fifth, distinguish necessary information from background information. Business rules, real-time data, and user questions should be prioritized, while low-relevance content can be removed or downgraded.
Sixth, set maximum output length reasonably. An excessively high output limit increases cost and may also lead to redundant results.
7. Low Cost Does Not Mean Stability Can Be Ignored
Low price is only one selection factor. Enterprises should also pay attention to response latency, concurrency capacity, rate-limiting strategy, service availability, data security, and output consistency. For batch tasks, overall throughput can be improved through queue-based peak shaving and concurrency control. For online requests, timeouts, degradation, and fallback paths need to be set.
At the same time, an offline evaluation set must be established, covering at least the following metrics:
- Task completion rate;
- Structured format accuracy;
- Factual consistency;
- Refusal and exception rate;
- Average latency;
- Retry rate;
- Cost per valid result.
Only when price, quality, and stability all meet requirements does a model truly have production application value.
Overall, lower token unit prices and cache billing mechanisms provide a better economic foundation for deploying intelligent applications at scale. However, cost optimization is not simply about choosing the lowest price. It requires coordinated work across context design, cache reuse, task routing, output constraints, and quality monitoring. For developers, the most valuable capability is to break a model call into an observable, calculable, and optimizable engineering process, so that every inference becomes more efficient while maintaining quality.
