How to Evaluate LLM API Pricing Structures and Costs
A practical guide to modeling LLM API costs beyond headline token prices. It explains input, output, and cached-token billing, provides a cost formula and Python estimator, identifies six cost drivers, and outlines load testing, monitoring, optimization, and vendor evaluation practices.
When evaluating a general-purpose LLM service, developers are often drawn to headline prices such as “X per million input tokens and Y per million output tokens.” Looking only at unit prices, however, can lead to a serious misjudgment of real cost. LLM API charges are not simply “number of calls × unit price.” They are determined by input tokens, output tokens, cached-hit tokens, retry count, context length, output length, and business call patterns. To objectively assess whether a service is worth using, you should break down the pricing structure, build a cost model, and then combine that model with quality, latency, stability, and observability.
1. Break Down the Billing Items: Input, Output, and Cache Hits Are Not the Same
General-purpose LLM APIs usually bill by token. Common billing items include input tokens, output tokens, and cached-hit input tokens. Input tokens are the prompts, context, examples, retrieved content, and other material sent on the request side. Output tokens are the content generated and returned by the model. A cache hit usually means that when the request prefix matches previously cached content, existing computation results can be reused and billed at a lower unit price. Understanding the differences among these three items is the first step in cost evaluation.
Output tokens are often more expensive than input tokens. The reason is not hard to understand: the input stage can be processed in parallel, while the output stage usually requires token-by-token decoding, making generation more sensitive to compute and latency. Therefore, in most businesses, output length has a much greater impact on total cost than input length. If a service’s output price is several times its input price, then when output length exceeds input length, output charges are likely to become the main cost item.
Cache hits are another key variable. Cached-hit prices are usually lower than ordinary input prices, but they apply only to reusable prefix content, such as fixed system prompts, stable tool descriptions, and repeated document fragments. A cache hit does not mean “all input gets a discount”; it means “only the reusable portion may get a discount.” Therefore, when evaluating the value of caching, you should not look only at the cache unit price. You also need to examine the proportion of reusable prefixes in business requests.
2. Build a Cost Model: Turn Unit Prices into a Calculable Formula
Let the ordinary input price be P_in, the output price be P_out, and the cached-hit price be P_cache, all expressed per million tokens in the same currency. For a single request, let total input tokens be T_in, of which cached-hit tokens are T_cache and uncached input tokens are T_in - T_cache, and let output tokens be T_out. The cost can be expressed as:
Cost = ((T_in - T_cache) / 1,000,000) × P_in+ (T_cache / 1,000,000) × P_cache+ (T_out / 1,000,000) × P_out
This formula looks simple, but it helps avoid two common mistakes. First, cached-hit tokens must not be billed again as ordinary input tokens. Second, output tokens must be calculated separately and cannot be estimated only from input scale. Below is a Python estimation example that does not depend on any third-party service. The parameters are illustrative only and do not represent any vendor’s quote:
def estimate_cost(input_tokens, output_tokens, cached_input_tokens,price_in, price_out, price_cache):assert 0 <= cached_input_tokens <= input_tokensuncached_input = input_tokens - cached_input_tokensreturn (uncached_input / 1_000_000 * price_in+ cached_input_tokens / 1_000_000 * price_cache+ output_tokens / 1_000_000 * price_out)# The following parameters are only for demonstrating the calculation logic,# not a quote from any service.price_in = 1.0price_out = 3.5price_cache = 0.25cost = estimate_cost(input_tokens=2000,output_tokens=800,cached_input_tokens=1200,price_in=price_in,price_out=price_out,price_cache=price_cache)print(round(cost, 6))
During model evaluation, you can also calculate two derived metrics. The first is the “effective input price”: effective input price = cache hit rate × P_cache + (1 - cache hit rate) × P_in. This converts the cache hit rate into actual input cost. The second is the “output cost share”: output cost share = output cost / total cost. If the output price is several times the input price and the output length is close to or greater than the input length, the output cost share may be very high. For example, if the output price is 3.5 times the input price and the output length is twice the input length, output charges account for about 87.5% of total cost. This kind of sensitivity analysis is more valuable for decision-making than simply comparing input unit prices.
3. Six Variables to Watch When Evaluating Cost
First, the output/input ratio. This varies greatly by business. Classification and extraction tasks produce very short outputs, question answering and summarization produce medium outputs, and code generation and long-form writing produce long outputs. The higher the output/input ratio, the more you need to pay attention to output unit price and maximum output limits.
Second, the cache hit rate. Multi-turn conversations, fixed system prompts, and knowledge-base question answering may have high prefix reuse rates, but cache hit rates must be measured from real requests rather than assumed. During evaluation, track both the “share of cacheable tokens” and the “share of tokens that actually hit the cache.”
Third, request frequency and concurrency. A low unit price with a huge call volume can still result in significant total cost. A high unit price with low call volume may deliver better quality and less rework. You should calculate “cost per business task,” such as cost per document processed, cost per thousand questions answered, or cost per session.
Fourth, retries and failure rate. Timeouts, rate limiting, format errors, and unacceptable content can all lead to retries, and retries consume input and sometimes output tokens again. Retry rates should be included in the cost model rather than looking only at the unit price of successful requests.
Fifth, context inflation. In multi-turn conversations, if every turn carries the full history, input tokens accumulate quickly. Even if the input unit price is low, long context can significantly raise cost and affect latency.
Sixth, quality pass rate. A low-cost service that requires extensive manual correction can have a higher actual total cost of ownership. Build a quality evaluation set, measure first-pass rate, format compliance rate, factual consistency, and other metrics, and then perform a Pareto analysis against cost.
4. Load Test with a Real Traffic Profile, Not Just Sample Requests
When evaluating a pricing structure, it is advisable to sample requests from production logs or simulated traffic and measure the distributions of input tokens and output tokens, the share of cacheable prefixes, the number of multi-turn rounds, retry rates, and other factors. Then construct a load-test set weighted by business scenarios and calculate average cost, P95 cost, and cost per unit task. Do not test unit price with only a single short question, because short requests underestimate the cost of long context and long outputs.
At the monitoring layer, record at least the following fields: request ID, input tokens, cached-hit tokens, output tokens, model tier, latency, retry count, estimated cost, and business task ID. This makes it possible to attribute cost to specific business scenarios instead of looking only at the total bill. Cost optimization should also be based on monitoring data: first identify high-cost request types, then take measures such as compressing prompts, limiting output, improving cache hit rates, and tiered routing.
5. Optimization Practices: Move from “Lower Unit Price” to “Lower Cost per Business Task”
First, govern prompts and context. Remove redundant instructions, merge duplicate examples, and use summarization, segmentation, or retrieval augmentation for long documents to avoid irrelevant content entering the context. Second, control output length. Reduce unnecessary generation through structured output, field constraints, maximum output token limits, and stop conditions. Third, design cacheable prefixes. Put stable system prompts, tool descriptions, and fixed templates at the front, and place changing content later to improve reusability. Fourth, use tiered routing. Use lower-cost model tiers for simple tasks and escalate to more capable models for complex tasks, provided that quality evaluation passes. Fifth, implement retry backoff and timeout control to prevent failed requests from amplifying cost. Sixth, build cost dashboards and budget alerts, and include cost metrics in launch reviews.
6. Vendor Selection Checklist
For a comprehensive evaluation, consider scoring against the following checklist: whether billing items are transparent and whether input, output, and cache rules are explainable; cost per unit task under a real traffic profile; whether quality evaluation meets requirements; whether latency and throughput meet business needs; whether rate limiting, retries, and stability are controllable; whether logs and usage statistics make cost attribution easy; and whether data compliance and security requirements are met. Only by comparing the cost model with quality, latency, and stability in the same table can you avoid being misled by a single unit price.
The conclusion is that evaluating an LLM API’s pricing structure should not focus only on input price or output price. It should focus on total cost under the real business token distribution. Output length, cache hit rate, and retry rate often determine the bill more than headline unit prices. Developers should build a formula-based cost model, load test with real traffic, continuously monitor cost per business task, and then combine quality and stability in vendor selection. In this way, “looks cheap on price” can become “genuinely controllable in business terms.”
