LLM API Selection: Evaluating Total Cost Beyond Unit Prices
This article describes an engineering method for evaluating LLM APIs beyond list prices. It explains why unit price alone does not determine cost, how to build a cost model that accounts for input-output ratios, failed calls, retries, and manual rework, and how to calculate the cost per successful task. It also covers how to build a task-level evaluation set and choose metrics such as accuracy and format compliance, so teams can compare models for selection, budget approval, and version upgrades.
Introduction: Why Model Selection Often Goes Off Track
After a team integrates an LLM API, the discussion usually centers on two questions: Is it cheap? Is the model smart enough? Both questions matter, but neither one is complete. A price is only a list price, and leaderboard scores reflect average performance on public datasets. What really determines a project’s cost and user experience is the total cost of completing one business task, along with how stably the model performs on your own data.
This article presents an engineering-oriented evaluation method for three scenarios: model selection, budget approval, and version upgrades.
1. Why Unit Price Alone Cannot Determine the Choice
Most APIs bill input tokens and output tokens separately, and the two rates are usually different. Output tokens typically cost more than input tokens because the model generates content one token at a time. For the same call, the ratio of input to output in a workload can make a large difference to the bill.
Beyond the asymmetry between input and output, consider the following factors:
- Input-output ratio: Input cost dominates long-document summarization tasks. Output cost dominates content generation tasks.
- Billing rules: Some services price cached input or asynchronous batch calls differently. Refer to the provider’s published pricing for the exact rules.
- Rate limits and quotas: Free tiers, rate limits, and overage fees affect real availability during peak hours and total spending.
- Failures and retries: Failed calls are still billed, and retries multiply the actual cost.
- Manual correction: When model output requires human rework, labor cost is usually far higher than token cost and should be included in the calculation.
2. Building a Cost Model
1. Cost per Request
The cost of a single request can be expressed as:
C = T_in / 10^6 × P_in + T_out / 10^6 × P_out
Here, T_in and T_out are the numbers of input and output tokens, and P_in and P_out are the input and output prices per million tokens.
The example below uses assumed values. Suppose P_in is CNY 10 per million tokens and P_out is CNY 40 per million tokens. A request with 2,000 input tokens and 800 output tokens costs:
- Input cost: 2,000 / 10^6 × 10 = CNY 0.02
- Output cost: 800 / 10^6 × 40 = CNY 0.032
- Cost per request: CNY 0.052
These prices are hypothetical values for illustration only. They do not represent the actual price of any service.
2. Cost per Successful Task
The business cares about the cost of completing a task, not the cost of a single call. If the task success rate of a single call is s, the average cost of each successful task is:
C_task = C / s
For example, at a 60% pass rate, C_task = 0.052 / 0.6 ≈ CNY 0.087. Even if one option has a lower per-call price, its cost per successful task can still be higher if its pass rate drops significantly.
Sample code:
function estimate_call_cost(input_tokens, output_tokens, input_price, output_price):cost = input_tokens / 1000000 * input_pricecost = cost + output_tokens / 1000000 * output_pricereturn costfunction estimate_task_cost(call_cost, pass_rate):if pass_rate <= 0:raise errorreturn call_cost / pass_rate
3. Replacing General Leaderboards with Task-Level Evaluation
General leaderboards measure average capability on public datasets, which may differ considerably from a specific business scenario. A more reliable approach is to build your own evaluation set and judge models with your business data.
1. Building an Evaluation Set
- Sample source: Draw samples from real business logs. Typically, 200 to 500 samples are enough for a preliminary judgment.
- Sample structure: Cover typical requests, edge cases (missing fields, vague wording, overly long inputs), and error-prone cases (easily confused concepts or formatting requirements).
- Criteria definition: Specify the expected result or scoring rule for each sample. For open-ended generation, detailed scoring rules are more consistent than a general “is it good?” judgment.
- Version control: Tag the evaluation set with a version number and periodically add new online data so the set does not drift away from the real distribution.
2. Choosing Evaluation Metrics
- Accuracy: The share of results that match the reference answer. This metric suits classification, extraction, and judgment tasks.
- Format compliance rate: Whether the output can be parsed correctly by downstream programs. In systems that integrate with code, this metric often matters more than semantic quality.
- Factual consistency: Whether the generated content is consistent with the provided source material.
