LLM API Selection Guide: How to Weigh Unit Price Against Real Value

    This guide explains why the lowest per-token price does not always produce the lowest cost per completed task. It covers how LLM API billing is structured, how to build a task-based evaluation set, how to calculate effective cost per passed task, and common selection mistakes. It also outlines practical measures for routing, caching, output control, and cost monitoring.

    1. Unit Price Is Not the Same as Cost

    When choosing an LLM, many teams start with the pricing table. Unit price is an important input, but it only describes one component of a single call. The real cost has three parts: the billable usage of each call, the number of calls needed to complete one business task, and the cost of manual review and rework when the output is unacceptable.

    For example, a model may have a low price per million input tokens. However, if it needs a longer prompt, more correction rounds, or manual backup because its output quality is unstable on the same task, the total cost per task can exceed that of a model with a higher unit price. Evaluation should therefore start from the total cost of completing one business task, not from the price per token.

    In practice, you can build a decision framework around five dimensions:

    • Unit price: the price per million input tokens and per million output tokens;
    • Usage: average input length, average output length, and average daily call volume;
    • Quality: task pass rate, first-attempt pass rate, and factual error rate;
    • Latency: average response time and tail latency (for example, P95 and P99);
    • Hidden costs: retry count, manual review hours, and extra overhead from cache misses.

    2. Breaking Down the Billing Model

    2.1 Asymmetry Between Input and Output

    Most pay-as-you-go model services charge for both input tokens and output tokens, and the two usually have different prices. Output tokens are often more expensive because the model generates content one token at a time, which requires more computation. As a result, controlling output length usually has a more direct effect on cost than reducing input. For example, asking the model to return only JSON fields instead of a long explanation can significantly reduce output usage.

    2.2 Context Length and Repeated Transmission

    In multi-turn conversations and retrieval-augmented generation (RAG) scenarios, each call may carry a large amount of prior content. If the system includes the full conversation history and long documents in the context on every turn, the input cost keeps rising as the number of turns grows. Common optimization methods include:

    • Creating rolling summaries of conversation history and keeping only key conclusions and user constraints;
    • Returning only the passages relevant to the question during retrieval, instead of passing entire documents;
    • Enabling server-side caching for stable system prompts, provided the service supports it and the billing rules allow it.

    2.3 Estimating the Cost of a Single Call

    The code below estimates the cost of a single call based on token usage. The unit prices are only example assumptions. In practice, replace them with the official prices of the service you use.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class PricingConfig:
    4. input_price_per_m: float # Price per million input tokens (example unit: CNY)
    5. output_price_per_m: float # Price per million output tokens (example unit: CNY)
    6. def estimate_cost_per_call(
    7. input_tokens: int,
    8. output_tokens: int,
    9. pricing: PricingConfig,
    10. ) -> float:
    11. """Estimate the cost of a single call from input and output token counts."""
    12. input_cost = input_tokens / 1_000_000 * pricing.input_price_per_m
    13. output_cost = output_tokens / 1_000_000 * pricing.output_price_per_m
    14. return input_cost + output_cost

    This code only calculates the direct cost of a single call. Next, consider how many calls a task needs on average and how many tasks pass on the first attempt.

    3. Evaluating with Real Tasks

    Model specifications, such as context window size, supported input modalities, and advertised reasoning capability, only indicate what a model might be able to do in theory. Model selection should rely on real tasks from your business and be decided by data.

    3.1 Building an Evaluation Set

    You can build an evaluation set by following these steps:

    1. Classify samples by business scenario, such as information extraction, code generation, customer support Q&A, and long-text summarization;
    2. Prepare dozens to hundreds of samples per category, covering common inputs and edge cases;
    3. Define an objective acceptance standard for each sample, such as field completeness rate, unit test pass rate, or semantic consistency with a reference answer;
    4. For results that cannot be judged automatically, arrange manual spot checks and record how consistent the human judgments are.

    The evaluation set should come from real business logs whenever possible and be updated regularly. An evaluation set made only from ideal, hand-written samples tends to overestimate how well the model will perform in production.

    3.2 Example Evaluation Workflow

    The code below shows a general evaluation loop. You implement call_model and judge according to your own interface and judging rules.

    1. from typing import Callable
    2. def evaluate_model(
    3. samples: list[dict],
    4. call_model: Callable[[str], dict],
    5. judge: Callable[[dict, str], bool],
    6. ) -> dict:
    7. passed = 0
    8. total_input = 0
    9. total_output = 0
    10. for sample in samples:
    11. resp = call_model(sample["prompt"]) # Returns a dict containing text, input_tokens, and output_tokens
    12. total_input += resp["input_tokens"]
    13. total_output += resp["output_tokens"]
    14. if judge(sample, resp["text"]):
    15. passed += 1
    16. return {
    17. "passed": passed,
    18. "pass_rate": passed / len(samples),
    19. "total_input_tokens": total_input,
    20. "total_output_tokens": total_output,
    21. }

    After each run, record the results separately by model, task type, and version number. This makes it easier to compare models and analyze regressions later.

    4. Effective Cost: The Core Metric for Value

    The price of a single call cannot directly show value for money. A more useful metric is the effective cost per passed task:

    Effective cost = Total call cost ÷ Number of passed tasks

    Consider a hypothetical example. Model A costs 0.02 CNY per call and passes 60% of tasks. Model B costs 0.03 CNY per call and passes 95% of tasks. Their effective costs are:

    • Model A: 0.02 ÷ 0.60 ≈ 0.033 CNY per task
    • Model B: 0.03 ÷ 0.95 ≈ 0.032 CNY per task

    In this example, Model B has a unit price 50% higher, yet it is slightly cheaper per passed task because its higher pass rate reduces retries and manual rework. Whether this conclusion holds depends on your actual pass rate and cost data, which you must obtain through evaluation.

    Besides effective cost, also track the following metrics:

    • First-attempt pass rate: the share of tasks that pass without retries, which reflects model stability;
    • Average retry count: retries directly multiply call cost;
    • Tail latency: P95 or P99 latency that exceeds your targets can affect user experience, even when the average looks good;
    • Version drift: after a model version behind the same interface is updated, its quality and usage may change, so re-evaluate it regularly.

    5. Common Mistakes

    Looking only at unit price. Unit price is one variable, not a conclusion. Always calculate total cost together with pass rate and call count.

    Using a few demonstrations instead of statistical results. Hand-picked successful examples do not represent overall performance. With small sample sizes, the conclusions have low confidence.

    Not limiting output length. Without an output cap or format constraints, the model may generate a large amount of irrelevant content, and the cost rises accordingly.

    Using one model for every task. Sending simple classification tasks to a highly capable large model is often wasteful. Choose models in tiers based on task difficulty.

    Ignoring version changes. After a provider updates a model, output style and usage may change. Systems without regression tests have difficulty detecting these changes promptly.

    6. Practical Implementation: Tiered Routing and Cost Governance

    6.1 Routing by Complexity

    Routing requests by task type and complexity is a common way to reduce overall cost. The simplified routing example below uses placeholder model names:

    1. def route_model(task_type: str, complexity: int) -> str:
    2. """Select a model tier based on task type and complexity (1 to 5)."""
    3. if task_type in {"classification", "extraction"} and complexity <= 2:
    4. return "small_model"
    5. if complexity >= 4:
    6. return "large_model"
    7. return "medium_model"

    Routing rules should be based on evaluation data rather than on intuition alone. After each rule goes live, check whether the pass rate for the affected tasks has dropped.

    6.2 Caching and Output Control

    • For identical or highly similar requests, cache results and set a reasonable expiration time;
    • Set a max_tokens limit for each task type and require structured output to reduce unnecessary text;
    • Compress long conversations through summarization, keeping key constraints and conclusions.

    6.3 Usage Monitoring and Budget Alerts

    Cost governance depends on observability. Track token usage and call counts by project, feature module, and model version, and set alert thresholds for daily and monthly budgets. Logging and monitoring or alerting services can fulfill this role. When the cost per task for a feature suddenly rises, the team can quickly determine whether the cause is longer prompts, uncontrolled output, or an abnormal retry rate.

    7. Checklist

    • Evaluation sets are built from real business tasks and updated regularly;
    • Effective cost per passed task is calculated, not just unit price;
    • First-attempt pass rate, retry count, and P95 latency are recorded;
    • Output length limits and format constraints are set for each task type;
    • Tiered routing rules are in place, and their effect on pass rate is verified;
    • Usage monitoring and budget alerts are configured;
    • Regression evaluation is scheduled after each model version update.

    The goal of model selection is to complete business tasks reliably at an acceptable cost. With a consistent evaluation method and cost metrics, teams can make model decisions that others can verify.