How to Evaluate the True Cost and Efficiency of LLM APIs
List prices for LLM APIs are usually quoted per million tokens, but similar prices do not necessarily mean similar actual spending. This article explains how to break down billing dimensions, measure token efficiency, compare subscription plans with pay-as-you-go pricing, control costs in long-horizon agent tasks, and build a repeatable evaluation process based on the cost per successful task.
1. Why List Prices Cannot Be Compared Directly
Different LLM services usually price usage per million tokens, but a similar list price does not mean a similar actual cost. The final cost of a task depends on three things: how many input tokens are sent per call, how many of those input tokens hit the cache, and how many output tokens the model generates.
Therefore, when comparing model costs, first express the total cost in a calculable form:
Total cost = uncached input tokens × input unit price + cached input tokens × cached input unit price + output tokens × output unit price
Once you have the actual usage and unit prices for each item, you can compare the cost of two options on the same task instead of relying on an intuitive impression of the list price.
2. Break Down the Billing Dimensions
1. Input and Output Prices
Most services price output tokens higher than input tokens. This means that generating lengthy answers, producing large blocks of code, or emitting large amounts of intermediate content during reasoning will significantly increase costs. For scenarios that frequently generate long text, the weight of the output price is often greater than that of the input price.
2. Cached Input
In multi-turn conversations and agent loops, system prompts, tool definitions, conversation history, and file contents that have already been read are sent repeatedly. If the service can identify these repeated prefixes and reuse the computation results, this part of the input is billed at the cached input price.
The cached input price may be higher or lower than the regular input price; check the provider’s pricing page for the specific terms. The key factor is the cache hit rate. The higher the hit rate, the closer the actual cost of long-context tasks will be to the cached input price.
3. Time-Based and Promotional Pricing
Some services differentiate prices by time period, such as peak and off-peak prices. Promotions and discounts also often have effective times and applicable scopes. When estimating costs, calculate based on the time period in which the task actually occurs and the price table effective at that time; do not simply apply the unit price from a single point in time.
3. Measure Model Performance with Token Efficiency
For the same task, different models may consume very different numbers of tokens to complete it. Factors that cause these differences include:
- The degree of redundancy in the reasoning process;
- Whether the tool-calling format is compact;
- Whether the answer directly addresses the key points or requires multiple rounds of clarification;
- Whether changes can be completed in one pass or require repeated file reading and rewriting.
To evaluate token efficiency, use a fixed task set. The recommended steps are:
- Select representative tasks that cover file reading and writing, code modification, running tests, and multi-round fixes.
- Run the candidate models under the same system prompt, tool configuration, and input conditions.
- Record the input tokens, cached tokens, and output tokens for each call, and aggregate them by task.
- Compare the total token count with the final completion quality.
The following code example shows how to estimate cost based on usage and unit prices. The unit prices are placeholder parameters; replace them with actual prices when using the code.
from dataclasses import dataclass@dataclass(frozen=True)class Pricing:"""Unit prices, in cost per million tokens (currency unit is arbitrary)."""input_per_m: floatcached_input_per_m: floatoutput_per_m: float@dataclass(frozen=True)class Usage:"""Token usage for a task or a single call."""input_tokens: intcached_tokens: intoutput_tokens: intdef estimate_cost(usage: Usage, price: Pricing) -> float:"""Estimate cost. Cached tokens cannot exceed total input tokens."""if usage.cached_tokens > usage.input_tokens:raise ValueError("cached_tokens cannot exceed input_tokens")uncached = usage.input_tokens - usage.cached_tokenscost = (uncached * price.input_per_m+ usage.cached_tokens * price.cached_input_per_m+ usage.output_tokens * price.output_per_m)return cost / 1_000_000def cost_per_success(total_cost: float, successful_tasks: int) -> float:"""Calculate unit cost by successful tasks, instead of looking only at per-call cost."""if successful_tasks == 0:return float("inf")return total_cost / successful_tasks
When using this set of functions, run the same task set separately for each candidate model, aggregate usage to calculate the total cost, and then divide by the number of successfully completed tasks.
4. Comparing Subscription Plans and Pay-as-You-Go
Subscription plans usually include a fixed fee and a certain quota, while pay-as-you-go pricing grows linearly with usage. When comparing the two, pay attention to the following points.
1. Convert to an Effective Unit Price
Divide the plan price by the amount of tokens it can actually provide in real usage to obtain the effective unit price. If the plan quota is converted based on request count, concurrency, or some internal multiplier, first convert it to a unified token basis before comparing it with the pay-as-you-go unit price.
2. Distinguish Full Utilization from Idle Utilization
The effective unit price of a plan depends on utilization. When usage is consistently close to the upper limit, the unit price is lower, and the plan is more cost-effective. When usage is only a small fraction of the limit, the fixed fee is not spread sufficiently, and pay-as-you-go is usually cheaper.
3. Estimate Your Own Usage Pattern
You can estimate based on the past month’s average daily usage, peak usage, and task distribution. If usage is far below the plan limit most of the time, pay-as-you-go is more suitable; only if the plan is continuously near full capacity every day is it more likely to have an advantage.
5. Cost Control for Long-Horizon Agent Tasks
Long-horizon tasks continuously accumulate context, and cost grows with each turn. The following practices can effectively control token consumption.
- Compress history: Periodically summarize older conversations and tool outputs into short summaries, keeping only the information needed for subsequent steps.
- Read files on demand: First use retrieval or a directory index to locate relevant snippets, avoiding repeatedly placing entire large files into the context.
- Trim tool outputs: Return only key fields and error information, removing verbose logs and duplicate content.
- Keep a stable prefix: Place unchanged content such as system prompts and tool definitions at the front, and put dynamic content later to improve the cache hit rate.
- Set budget alerts: Record token usage by task, and pause and notify when a threshold is exceeded.
In addition, long tasks need checkpoint/resume and failure retry capabilities. If a task is interrupted midway, the tokens already consumed usually cannot be recovered, and restarting will cause duplicate billing. Persisting intermediate state can reduce this kind of loss.
6. Build a Sustainable Evaluation Process
Cost evaluation should not be a one-time exercise. Model versions, pricing rules, and service load all change, so it is advisable to establish a fixed process:
- Maintain a task set that covers major business scenarios and update it regularly.
- For each evaluation, run the candidate models under the same conditions and record both token usage and task quality.
- Use “cost per successful task” as the core metric, rather than looking only at unit price or per-call cost.
- Include quality factors in the calculation. If a model has a low first-pass success rate and requires more retries, its actual cost may be higher.
- Retest quarterly or after price adjustments, and update selection conclusions in a timely manner.
7. Conclusion
To judge whether an LLM service is cost-effective, the core question is the total cost of completing a specific task, not any single unit price. Billing structure, cache hit rate, token efficiency, plan utilization, and task success rate together determine the final cost. Only by incorporating these metrics into a unified estimation framework and continuously validating them with real tasks can you obtain a reliable basis for model selection.
