Evaluating LLM Pricing: Unit Price, Caching, and Real Usage Conversion
Understanding LLM pricing requires more than just looking at the unit price per million tokens. This article explores how to evaluate model cost-effectiveness by analyzing common billing dimensions, including input, output, and cached tokens. It provides a practical approach to calculating per-task costs, comparing pay-as-you-go with subscription plans, and using a benchmark task set to measure the actual cost per successful task. Additionally, it offers engineering strategies to optimize token usage and reduce overall expenses.
1. Higher Unit Prices Do Not Mean Lower Cost-Effectiveness
Model services are typically priced per million tokens. The unit price only reflects the standard rate for a single computation and does not directly indicate how much work can be done within a given budget. To determine whether a model is cost-effective, you need to evaluate three metrics simultaneously: the number of tokens consumed per task, the task success rate, and the cost of manual rework. A lower-priced model might incur higher total costs if it requires multiple retries. Conversely, a higher-priced model might result in lower total costs if it completes the task in a single attempt.
2. Understanding Common Billing Dimensions
Mainstream model services generally charge based on the following dimensions:
- Input tokens: Includes the entire context, such as system prompts, conversation history, and retrieved documents.
- Output tokens: The content generated by the model, usually priced higher than input tokens.
- Cache hit tokens: When the request prefix matches a recent request, the server can reuse previously computed results. These are priced significantly lower than uncached input tokens.
- Reasoning-related tokens: Some models generate internal reasoning processes. This portion of the output may be billed separately and should be verified in the invoice.
Pricing ratios vary significantly across different providers. Before selecting a model, always refer to the official public pricing table rather than estimating based on past experience.
3. Converting Unit Price to Per-Task Cost
To convert the unit price into task cost, use the following formula:
Per-task cost = (Input tokens − Cache hit tokens) × Uncached input unit price + Cache hit tokens × Cache hit unit price + Output tokens × Output unit price
Since unit prices are quoted per million tokens, the calculation result must be divided by 1,000,000.
Token consumption for the same task can vary greatly across different models. For example, to fix a piece of code, one model might output a complete patch in one go, while another might require multiple rounds of questions and modifications. Therefore, you should calculate the average consumption based on real business samples rather than just looking at the pricing table.
4. Comparing Pay-As-You-Go and Subscription Plans
Subscription plans usually offer a fixed fee with a certain quota. When comparing, pay attention to the following four points:
- Quota unit clarity: Some are calculated by request count, some by tokens, and some by duration. These need to be unified into a common metric.
- Quota refresh cycle: Daily, monthly, or rolling window refreshes affect availability during peak periods.
- Concurrency and rate limiting: Even with sufficient quota, rate limits can prevent batch tasks from completing.
- Whether caching is counted against the quota: This significantly alters the actual number of tasks that can be completed.
To calculate the equivalent unit price, divide the subscription fee by the number of tasks actually completed in your business environment. This figure is more valuable for reference than the advertised quota numbers.
5. Estimating Single Request Cost with Code
The following function estimates the cost of a single request. The prices in the example are placeholder values and not actual prices of any service. Replace them with values from the official pricing table when using it.
def estimate_request_cost(input_tokens: int,cached_tokens: int,output_tokens: int,price_input_per_m: float,price_cache_per_m: float,price_output_per_m: float,) -> float:"""Returns the estimated cost of a single request, in the same unit as the pricing."""if cached_tokens > input_tokens:raise ValueError("Cached tokens cannot exceed input tokens")uncached = input_tokens - cached_tokenscost = (uncached * price_input_per_m+ cached_tokens * price_cache_per_m+ output_tokens * price_output_per_m) / 1_000_000return cost# Example parameters (placeholder values)cost = estimate_request_cost(input_tokens=12_000,cached_tokens=10_000,output_tokens=1_500,price_input_per_m=10.0,price_cache_per_m=1.0,price_output_per_m=40.0,)print(f"Estimated cost per request: {cost:.6f}")
By summing the costs of all requests within a task, you can determine the per-task cost.
6. Evaluating Models with Benchmark Task Sets
It is recommended to follow this evaluation process:
- Extract a batch of representative tasks from real business scenarios, covering simple, medium, and complex categories. The sample size should be large enough to reflect the distribution, typically ranging from tens to hundreds.
- For each candidate model, record the input tokens, output tokens, cache hits, time consumed, and whether it passed the acceptance criteria for each task.
- Calculate the average cost per successful task, which is the total cost divided by the number of passed tasks.
- Factor in the cost of manual modifications and rework time into the total cost.
Using “cost per successful task” as the core metric prevents the bias of only looking at unit prices.
7. Engineering Practices to Reduce Costs
- Stable prefixes: Place system prompts and fixed documents at the beginning of the request and dynamic content at the end to improve cache hit rates.
- Control context length: Only pass in historical records and retrieval fragments relevant to the current question to avoid irrelevant content consuming input tokens.
- Tiered routing: Assign simple tasks like classification and format conversion to lower-priced models, and reserve complex reasoning tasks for more capable models.
- Limit output length: Use clear output format requirements and the maximum output token parameter to prevent overly verbose responses.
- Budgeting and alerting: Set daily and monthly budgets per project or user, and trigger alerts immediately when abnormal consumption occurs.
8. Conclusion
The value of model pricing must be judged within the context of specific business scenarios. Teams should first understand the billing dimensions, then calculate per-task cost and cost per successful task using real tasks, and finally optimize usage through cache design, model routing, and budget control. Only by converting the listed price into actual output can you fairly compare the cost-effectiveness of different solutions.
