LLM API Selection: Cost Formula and Evaluation Routing
This article outlines a practical framework for LLM API selection: define the task, budget, and quality bar; calculate cost per valid business output; compare token pricing consistently; and build a domain-specific evaluation set with sampling, sample-size planning, scoring rubrics, and blind review.
1. Clarify Three Things Before Selection
Selection should answer three questions: what type of task the business involves, what the budget is per call, and what quality standard must be met. Without clarity on these three points, no price table or leaderboard can directly provide the answer.
This article is intended for developers and selection leads responsible for technical solutions. The methods described here apply to text-heavy scenarios such as online Q&A, document extraction, code assistance, and intelligent customer service. Multimodal tasks involving images and audio require separate evaluation design.
Use one metric consistently for evaluation: cost per unit of business output.
Cost per unit of business output = total monthly model invocation cost ÷ number of valid monthly business outputs
Valid business output refers to results that pass acceptance criteria, such as approved ticket replies or contract records with correctly extracted fields. If only invocation counts are tracked, a cheap model with a high error rate may appear economical, but incorrect results still require manual rework, making the actual cost higher.
2. How to Compare API Pricing
Vendors typically price per million tokens and often price input and output separately. Some vendors also offer a lower unit price for input tokens that hit the cache. When comparing, these items need to be unified under the same formula:
Cost per call = input tokens × input unit price + output tokens × output unit price + cache-hit tokens × cache-hit unit price
Token counts should be calculated using the tokenizer provided by the target model. Different vendors produce different tokenization results, and the same piece of text may differ significantly in token count.
The price of the same model may vary by version, region, and invocation method. Therefore, the price table should note the query date and use the vendor’s official website price on that date as the reference. It is recommended to record candidate models in the following table:
| Model | Input price (CNY per million tokens) | Output price (CNY per million tokens) | Cache-hit price (CNY per million tokens) | Context limit (tokens) | Price query date |
|---|---|---|---|---|---|
| Candidate A | To be filled | To be filled | To be filled | To be filled | To be filled |
| Candidate B | To be filled | To be filled | To be filled | To be filled | To be filled |
For many vendors, the output unit price is higher than the input unit price, so for tasks with longer outputs, the cost share will rise noticeably. Input and output should be counted separately during calculation.
Parameter count is only one factor in pricing. Hardware utilization, batching strategy, quantization method, and whether a mixture-of-experts (MoE) architecture is used, where only part of the parameters are activated per inference, all affect price. Therefore, do not infer price from “larger parameters mean more expensive.” Use the measured cost per unit of business output as the basis.
3. How to Build Your Own Evaluation Set
Public leaderboards are suitable for initial screening of candidate models. MMLU evaluates multiple-choice questions across multidisciplinary knowledge, GPQA evaluates graduate-level science Q&A, and SWE-bench evaluates the ability to fix issues in real code repositories. These scores can narrow the candidate range, but they cannot represent your business. Benchmark items may already appear in training data, and when score gaps are small, direct comparison is especially unreliable.
A business evaluation set can be built using the following steps:
- Sampling: Perform stratified sampling by task type from online logs. Remove samples containing personal privacy information and de-identify them.
- Determine sample size: At least 200 items per task type. Using the normal approximation to the binomial distribution, when the success rate is near 50%, the 95% confidence interval for 200 samples is approximately ±7 percentage points. To narrow it to approximately ±3.5 percentage points, about 800 items are needed per category.
- Write a scoring rubric: Define scoring criteria for each task, with each item scored from 0 to 2 points, and provide examples for each score level. For example, an extraction task can be split into three items: “field completeness,” “field value correctness,” and “format compliance.”
- Blind scoring: Reviewers do not see model names.
