LLM Selection: Evaluating Unit Price, Performance, and Total Cost
This article explains why token unit prices alone do not determine LLM usage cost, how input, output, context length, retries, and caching affect total spend, and how to compare models using a consistent evaluation set and cost per valid result. It also provides a monthly cost estimation script, a selection workflow, common pitfalls, and practical recommendations for ongoing model evaluation.
1. Why Unit Price Does Not Equal Cost
Model services typically charge by metered units for input and output. This metered unit is commonly called a token, the smallest segment into which text is split during model processing. Many people see a lower unit price and assume that usage cost will fall accordingly. That judgment considers only one number on the price list and ignores other sources of actual spend.
The total cost of a single call is roughly composed of three parts: input billing, output billing, and the additional number of calls required by task design. If the same task requires multiple retries on a low-unit-price model, or requires longer prompts to produce usable results, its total cost may not be lower.
2. Breaking Down the Cost Model
2.1 Different Weights for Input and Output
The input portion includes system instructions, conversation history, and retrieved reference materials. The output portion is the content generated by the model. Most services charge a higher unit price for output than for input. Therefore, tasks that generate long text are more sensitive to output cost, while retrieval-augmented tasks are more sensitive to input cost.
2.2 Hidden Overhead of Context Length
A longer context window allows a single request to carry more information, but each request also counts more content as input. If an application sends the full history to the model on every turn, the longer the conversation, the higher the cost per turn. Common approaches include summarizing history, keeping only the most recent turns, or retrieving relevant segments by semantic search before sending them.
2.3 Call Volume and Caching
Batch tasks, retry logic, and multi-step workflows all amplify call volume. For repeatedly occurring prompt prefixes, some services provide caching or reuse mechanisms that can reduce duplicate billing. Specific rules should be based on the provider’s documentation and should not be assumed from experience.
3. Evaluating Performance on a Common Benchmark
Price comparison must be built on the premise of consistent effectiveness. The following steps are recommended for constructing an evaluation set:
- Extract 100 to 300 representative samples from real business scenarios, covering common questions and edge cases.
- Define a determinable standard answer or scoring rule for each sample, such as field extraction accuracy, the proportion of code that passes unit tests, or the coverage of key points in a summary.
- Fix the prompt template, sampling temperature, and output format so that different models are evaluated under the same conditions.
- Record the input volume, output volume, latency, and failure rate of each request.
- Aggregate the cost per valid result, that is, total spend divided by the number of samples that pass evaluation.
Cost per valid result reflects the real selection outcome better than the unit price of a single call. A model with a higher unit price but a high first-pass rate may be more cost-effective than a lower-priced model.
4. Cost Estimation Example
The following script estimates monthly cost before launch. The unit prices in it should be replaced with the actual quotes of the service being used; the example values are only for demonstrating the calculation logic.
def estimate_monthly_cost(daily_requests: int,avg_input_tokens: int,avg_output_tokens: int,input_price_per_m: float,output_price_per_m: float,retry_rate: float = 0.05,days: int = 30,) -> float:"""Estimate monthly cost using per-million-token prices; keep units consistent with the quote."""effective_requests = daily_requests * (1 + retry_rate)input_cost = effective_requests * avg_input_tokens / 1_000_000 * input_price_per_moutput_cost = effective_requests * avg_output_tokens / 1_000_000 * output_price_per_mreturn (input_cost + output_cost) * days# Example: unit prices are placeholder valuescost = estimate_monthly_cost(daily_requests=5000,avg_input_tokens=1200,avg_output_tokens=400,input_price_per_m=10.0,output_price_per_m=30.0,)print(f"Estimated monthly cost: {cost:.2f}")
The value of the script is that it makes variables such as retry rate and the input-output ratio explicit. Teams can adjust assumptions item by item and observe which one has the greatest impact on total cost. Usually, output length and call volume are the two variables most worth optimizing.
5. Model Selection Workflow
- Clarify the task type. Classification, information extraction, question answering, code generation, and long-text generation place different demands on model capabilities and should be evaluated separately.
- Set a quality threshold. Use the evaluation set to determine the minimum acceptable pass rate.
- Among candidate models that meet the threshold, compare cost per valid result.
- Check latency and stability. Response time and error rates during peak periods directly affect user experience.
- Design a fallback strategy. When the primary model fails or times out, switch to a backup model or degrade to rule-based processing.
- Launch with a small amount of traffic in a gradual rollout, continuously monitor quality and cost, and review once a month.
6. Common Pitfalls
- Looking only at unit price and ignoring first-pass rate.
- Replacing systematic evaluation with a small number of manual trials, which introduces large sample bias and unreliable conclusions.
- Ignoring input expansion caused by conversation history.
- Treating the provider’s advertised performance metrics directly as business results.
- Lacking budget alerts, so costs suddenly exceed the budget after call volume grows.
7. Practical Recommendations
Model selection is an ongoing process. After a new model is released, retest it with the same evaluation set before deciding whether to migrate. Before migration, keep the old version’s configuration so that a quick rollback is possible if problems occur. Store prompts, evaluation results, and cost data as team assets so that each future selection can be compared against existing data.
