How to Calculate Total LLM Cost: A Caching and A/B Testing Guide
This article presents a practical workflow for evaluating large language model costs beyond list prices. It covers cache billing rules, hidden reasoning tokens, time-based pricing, cost per accepted task, A/B testing setup, task-based model and caching choices, front-end generation testing caveats, how to read capability-cost charts, and rollout steps. The examples use illustrative prices; actual figures should be checked against each vendor’s official billing documentation.
Selecting an LLM is no longer just a question of whether to use one. Development teams now need to decide which vendor and model to use, and how to control cost. Recently, multiple vendors have released new versions of lightweight models and increased price promotions. The list price is only part of the bill. This article provides an evaluation process that teams can execute directly. The example prices in this article are assumed values; for actual numbers, refer to each vendor’s official billing documentation.
1. Break Down the Bill: What Lies Beyond the List Price
A model’s list price is usually split into input price and output price, with different unit prices for each. After obtaining the list price, teams also need to verify the following three items.
First, cache billing rules. Input tokens that hit the cache are generally billed at a lower unit price, but cache write rules, storage duration, and minimum cache length vary by vendor.
Second, whether reasoning tokens are billed. Some models perform multiple rounds of internal self-correction. This intermediate reasoning content may be billed as output tokens even if it is not shown to users. Whether it is billed depends on the billing documentation for the specific model and version.
Third, time-of-day pricing. Some cloud providers offer discounts at night. For online businesses that need to respond around the clock, this discount is hard to use directly. It is usually better suited to non-real-time tasks such as batch cleaning and offline labeling.
The following assumed example illustrates the impact of hidden reasoning tokens. Assume a model charges CNY 1 per million input tokens and CNY 2 per million output tokens. A request contains 2,000 input tokens, 500 visible output tokens, and another 1,500 reasoning tokens.
- If reasoning tokens are billed: CNY 0.002 (input) plus CNY 0.004 (output, 2,000 tokens total), for a total of CNY 0.006.
- If reasoning tokens are not billed: CNY 0.002 (input) plus CNY 0.001 (output), for a total of CNY 0.003.
In this example, hidden reasoning tokens double the cost per request. This effect is linear and does not automatically amplify with request volume. What really amplifies cost is concurrency and the number of reasoning rounds per request. When both grow at the same time, total cost grows faster than the number of requests, so actual bills should be used to verify the impact.
2. Metric: Cost per Accepted Task
Comparing only the cost per call can easily ignore quality differences. A more reasonable metric is cost per accepted task, calculated as follows.
Cost per accepted task = Total cost ÷ Number of tasks that pass quality acceptance
For example, a batch processes 1,000 requests at a total cost of CNY 20. Of these, 900 pass acceptance. The cost per accepted task is 20 ÷ 900, or approximately CNY 0.022.
Now compare two candidate models. Model A costs CNY 0.006 per call and has a 92% acceptance pass rate. Model B costs CNY 0.004 per call and has an 85% acceptance pass rate.
- Model A: 0.006 ÷ 0.92, approximately CNY 0.0065.
- Model B: 0.004 ÷ 0.85, approximately CNY 0.0047.
Although Model B has a lower pass rate, its cost per accepted task is lower. If quality differences lead to higher manual review costs, those review costs should also be included in total cost before comparing the models.
3. Minimum A/B Testing Checklist
Compared with paper evaluations, A/B testing in real business scenarios better reflects the performance of long-tail requests. Prepare the following six items before execution.
- Traffic splitting. Use hash-based assignment by request or user ID so that the same user always enters the same group and does not experience back-and-forth changes. The task type distribution in both groups must remain consistent.
- Sample size. Estimate based on the difference you want to detect. For example, to distinguish between 90% and 85% acceptance pass rates at a two-sided significance level of 0.05 and 80% power, each group needs about 700 samples. If the difference is smaller, the sample size will increase significantly.
- Test period. Cover at least one full business cycle, such as 7 days, so that both peak and off-peak periods are included.
- Quality definition. Write acceptance rules in advance. For code tasks, the unit test pass rate can be used. For content tasks, the compliance review pass rate can be used. At the same time, sample a certain percentage for manual review and record the consistency of review results.
- Monitoring metrics. Record total cost, cache hit rate, P95 latency, and error retry rate. Changes in latency and retry rate often expose problems earlier than changes in cost.
- Risk control. Online traffic splitting affects real users. It is recommended to start with shadow traffic, meaning requests are copied to the candidate model but results are not returned, or to test first with internal users and non-critical tasks. Also set up a one-click rollback switch.
4. Choose Models and Caching Strategies by Task Type
Different tasks have different sensitivity to cost and quality. The table below provides a set of starting points that can be applied directly. Specific thresholds need to be adjusted according to each business’s baseline.
| Task Type | Typical Examples | Priority Metric | Caching Strategy | Quality Requirement | Recommended Approach |
|---|---|---|---|---|---|
| High-frequency, low-complexity | Label classification, entity extraction | Cost | Fix system prompts to improve prefix hit rate | Meet the business accuracy baseline | Choose the lowest-cost model that meets the baseline, and pair it with batch processing |
| Medium-frequency, medium-complexity | Content polishing, code generation | Cost per accepted task | Reuse template fragments and cache common context | Rank by pass rate under acceptance rules | Use A/B results to calculate cost per accepted task and choose the lowest |
| Low-frequency, high-complexity | Complex reasoning, long-document analysis | Quality | Cache long documents in segments and reuse parsed results | Error cost is high; set up manual review | Use a lightweight model for pre-routing and send difficult cases to a larger model |
Pre-routing works as follows: a lightweight model first judges request difficulty. Simple requests are returned directly, while complex requests are forwarded to a larger model. This can reduce overall cost, but routing itself can also make mistakes, so routing accuracy needs to be accepted separately.
5. Testing Front-End Generation Capabilities
A developer used a new model to rebuild a website homepage, with the goal of showing more information modules while keeping the interface clean. In a trial with six rounds of prompt tuning, the model generated fairly standard HTML and CSS structures with semantically clear class names. Among the six options, three used card-grid layouts and three used data-dense list layouts. No overlapping elements or responsive failures appeared. The model also retained a contrast requirement given at the beginning of the conversation, namely WCAG AA, across multiple turns.
These results are useful as a reference, but the sample covers only one person, one page, and six rounds of dialogue, which is not enough for a production decision. To determine whether a model is suitable for front-end generation, it is advisable to add the following.
- A fixed set of test prompts covering different page types.
- A unified scoring sheet covering layout quality, accessibility, and responsive behavior.
- Automated checks, such as using a contrast detection tool to check whether colors meet WCAG AA.
- Failure case records that count the proportion of outputs requiring manual modification and the reasons.
There are also community examples showing models assisting with video editing or interface design. Because these examples lack reproducible evaluation conditions, this article does not draw conclusions about those capabilities.
6. Reading Third-Party Capability-Cost Charts Correctly
Third-party evaluation organizations often use capability-cost scatter plots to compare models. The horizontal axis is usually cost per task, and the vertical axis is a capability score. When reading such charts, first confirm the following information: the evaluator and report date, the cost calculation methodology (input/output ratio, cache assumptions, and whether reasoning tokens are included), and the test set used for capability scores.
Models near the upper-left corner usually offer better value for money. However, rankings can change under different calculation methodologies. If two models have similar capability scores but a large cost gap, the capability difference can be translated into business impact, such as the manual correction cost per accepted task, before deciding whether the extra budget is worth it.
7. Implementation Steps
- According to official billing documentation, calculate the cost per call, including reasoning tokens.
- Use A/B testing to collect quality acceptance results and calculate cost per accepted task.
- Use the decision table to choose a model and caching strategy for each task type.
- Retest periodically, because model versions and prices change quickly.
The model is only responsible for generating tokens. Whether a call is worthwhile depends on how much is actually spent for each task that passes acceptance.
