Why LLM API Pricing Varies: Cost per Successful Task
Many teams compare LLM APIs by per-million-token input and output prices, but the real bill depends on token volume, cache hits, retries, tool calls, and human review. This article explains why some models cost more to run, how cache billing changes the calculation, and how to estimate cost per successful task. It uses an illustrative code-repair example to show why a model with a higher unit price can still be cheaper per completed task, and it offers practical guidance on evaluation, logging, routing, and cache-friendly prompts.
Why LLM API Pricing Varies: Cost per Successful Task
First, Avoid the Misconception: Unit Price Is Only One Input to the Bill
When evaluating LLM APIs, many teams start with a comparison table. They compare the input and output price per million tokens line by line, then choose the cheapest option. That approach works for standardized goods, but it can easily mislead when applied to LLMs.
The bill is determined by three things together: how many tokens were used, how many of those tokens hit the cache, and how many times the task succeeded. A model with a higher unit price may produce a lower total bill under some workloads. A model with a low nominal unit price may become more expensive in long-chain tasks because of repeated retries and manual rework.
This article discusses cost structure, cache billing, task-level estimation, and tiered model selection. The prices and success rates used here are illustrative values for demonstrating the calculation method. They do not represent any vendor’s actual pricing. When selecting a model, use each vendor’s current price list and your own measured data.
Cost Structure: Why Some Models Are Naturally More Expensive
1. Long Context Puts Pressure on Memory and Compute
When a model processes long context, it needs to store the KV cache in memory, and attention computation grows with sequence length. The longer the context, the more memory and bandwidth a single request consumes, and the fewer requests the same GPU can serve concurrently. As a result, models that support million-token context usually have a higher inference cost per token. This has a clear engineering basis.
Inference providers commonly use several techniques to reduce this cost:
- KV cache quantization, which reduces the memory footprint per token;
- PagedAttention-style paged memory management, which reduces memory fragmentation;
- Prefix sharing, which lets multiple requests reuse the same already-computed KV cache;
- Hybrid architectures that combine linear attention and standard attention to reduce the computational overhead of long sequences.
Some vendors claim that their architectural optimizations deliver significant efficiency gains in long-context scenarios. Such claims need to be validated against your own workload, because the actual benefit depends on context length, request concurrency, and cache hit behavior.
2. Post-Training Investment Feeds into Pricing
Capabilities such as math, code, and complex reasoning often depend on post-training pipelines that include large-scale reinforcement learning, process supervision, and synthetic data filtering. These stages consume substantial compute and human effort. Models aimed at complex tasks often carry larger post-training investment, and their pricing is correspondingly higher. A higher price indicates that the supplier has invested in capability, but it does not automatically mean the model has poor cost-effectiveness for your task.
Billing Mechanics: The Cache Price Is Often the Missing Column
Many comparison tables have only two columns: input price and output price. They miss the input price when the cache is hit. Many inference services now provide context caching. If the prefix of a request—such as the system prompt, a long document, or code repository context—is repeated from previous requests, the repeated part can be billed at a lower unit price than regular input. The exact discount and billing rules vary by vendor and should be checked in the relevant price documentation.
The message structure for agent-style tasks typically looks like this:
messages = [{"role": "system", "content": SYSTEM_PROMPT}, # Thousands of tokens, mostly identical on every request{"role": "user", "content": CODEBASE_CONTEXT}, # Tens of thousands of tokens, mostly unchanged within a long session{"role": "user", "content": CURRENT_TASK}, # The incremental part that changes each turn]
The system prompt and codebase context form a stable prefix, which can repeatedly hit the cache during multi-turn interactions. The more stable and longer the prefix, the higher the hit rate usually is. If the task is short-text processing with a completely different input each time, the prefix has almost no repetition, so caching helps little. In that case, the difference in unit price itself matters more.
The weighted average input cost can be estimated as follows, with prices per million tokens:
Actual input cost = input tokens × [hit rate × cache price + (1 − hit rate) × regular price] ÷ 1,000,000
The hit rate is not a fixed parameter. It is affected by the following factors:
- Whether the prefix is byte-for-byte identical; even a difference in a single space may prevent a cache hit;
- The cache retention time (TTL); the cache expires if there are no requests for a long period;
- The vendor’s minimum cacheable length requirement;
- Whether the first cache write is charged extra.
It is recommended to measure the real hit rate directly in a canary or gray-release environment rather than relying only on an ideal estimate.
Task-Level Estimation: Calculate Cost per Successful Completion
When teams account for business costs, they should calculate total cost per task. The comprehensive cost of a single attempt includes four items:
Comprehensive cost per attempt = actual input cost + actual output cost + tool-call cost + human review cost
Expected cost per successful task = comprehensive cost per attempt ÷ task success rate
This formula assumes that each attempt is independent and that, after a failure, the whole task is rerun until it succeeds. Under this assumption, the expected number of attempts equals 1 ÷ success rate. The retry cost is already included in the division result and should not be added separately. If a failure only requires rerunning the incorrect step, the cost of rerunning that part needs to be estimated separately.
The following example uses a code-repair task of moderate complexity. Assume that each attempt uses an average of 200,000 input tokens and 10,000 output tokens, the cache hit rate is 80%, and the tool-call cost is CNY 0.02 per attempt. The parameters for the two models are as follows, with prices in CNY:
| Parameter | Model A | Model B |
|---|---|---|
| Regular input price (CNY per million tokens) | 2 | 6 |
| Cache price (CNY per million tokens) | 0.4 | 1.2 |
| Output price (CNY per million tokens) | 8 | 24 |
| Task success rate | 60% | 90% |
| Human review cost (CNY per attempt) | 0.8 | 0.1 |
Calculated according to the formulas, the results are as follows:
| Calculation item | Model A | Model B |
|---|---|---|
| Actual input cost (CNY) | 0.144 | 0.432 |
| Actual output cost (CNY) | 0.080 | 0.240 |
| Tool-call cost (CNY) | 0.020 | 0.020 |
| Human review cost (CNY) | 0.800 | 0.100 |
| Comprehensive cost per attempt (CNY) | 1.044 | 0.792 |
| Average attempts (1 ÷ success rate) | 1.67 | 1.11 |
| Expected cost per successful task (CNY) | 1.74 | 0.88 |
Model B’s unit price is three times that of Model A, but its expected cost per successful task is only about half of Model A’s. This conclusion depends on the assumption about human review cost. If the human review cost for both models is set to CNY 0.1, Model A’s cost per successful task drops to CNY 0.57, which is lower than Model B’s CNY 0.88. This shows that small changes in success rate and human review cost can change the selection conclusion. Comparing unit prices alone cannot determine which model is more cost-effective.
When the success rates of two models are close, the cost per successful task is mainly determined by unit price and token volume. In that case, the lower-unit-price model is usually more cost-effective. Success rates need to be measured with your own evaluation set. If the sample is too small, the error in the success rate will be large. It is advisable to prepare at least several hundred real tasks.
Tiered Selection and Implementation Recommendations
Build an evaluation set with your own tasks. Public benchmarks can be used for initial screening, but the distribution of business data, prompt structure, and context length determine actual cost and success rate. Public price lists and public evaluation results should both be treated as initial screening inputs, not as direct procurement conclusions.
Log the full bill, not just unit price. Run enough real tasks in a canary environment, and track cache hit rate, average number of attempts, number of tool calls, and frequency of human intervention.
Route by task difficulty. Send simple tasks to low-cost models and escalate complex tasks to higher-capability models. A model routing layer can separate these two types of workload and usually achieves a better balance between cost and quality.
Design cache-friendly prompts. Put stable content first and dynamic content later, and keep the prefix byte-for-byte consistent to improve the cache hit rate.
Note the scope of this article. This article discusses only API calls billed by token. It does not cover annual packages, private deployment, or business discounts. In large procurement deals, these factors may change the conclusion.
In summary, the real cost of an LLM API is determined jointly by cost structure, billing mechanics, and product positioning. Using “how much it costs to successfully complete one task” as the comparison metric is closer to the real bill than looking only at the price list. For long-chain tasks with high tolerance costs for failure, paying a premium for a higher success rate may be worthwhile. Whether it is worthwhile needs to be validated with your own data.
