How to Evaluate LLM APIs: A Systematic Approach to Cost and Capability

    Choosing an LLM API based on sticker price alone leads to bad decisions. This article explains why per-token pricing doesn't equal real cost, introduces four evaluation dimensions (capability, cost, latency, stability), shows how to build a business-aligned benchmark, and provides Python code for calculating cost per valid result. It also covers Pareto-frontier tradeoffs, tiered model routing, common pitfalls, and production rollout practices like canary releases and monitoring.

    1. Unit Price Does Not Equal Cost

    LLM APIs are typically billed per token, with separate rates for input and output tokens—output is usually more expensive. The cost of a single call depends on three factors: input token count, output token count, and the corresponding unit prices. When comparing two models, you must factor in the actual token consumption of your business tasks; price tables alone cannot support a reliable conclusion.

    A lower unit price does not necessarily mean lower total cost, for three main reasons.

    First, the same task can consume very different numbers of tokens across models. Some models respond concisely, while others generate longer explanations or reasoning steps. A verbose model with a cheap unit price may end up costing more than a pricier model with tighter output.

    Second, failed calls and retries are billed repeatedly. Format validation failures, timeout-triggered retries, and results that require manual rework all inflate actual spending.

    Third, some platforms apply different pricing rules for long contexts, cache hits, or batch calls. Pricing terms should always be checked against the platform’s official documentation, and each rule should be included in your cost accounting.

    2. Four Evaluation Dimensions

    When assessing whether a model fits a specific business scenario, consider at least these four dimensions.

    1. Capability. Focus on accuracy on your business tasks, instruction following, compliance rate of structured output (such as JSON), and stability of information extraction from long documents. Public leaderboard scores are only a reference; they cannot replace testing on your own scenarios.
    2. Cost. Track both the average cost per task and the cost per valid result. The latter is calculated as total cost divided by the number of results that pass quality acceptance. A cheap model with a 60% pass rate may have a higher effective cost than an expensive model with a 90% pass rate.
    3. Latency. Distinguish between time to first token and total response time. Interactive applications (chat assistants, code completion) are sensitive to first-token latency, while offline batch workloads care more about throughput and volume processed per unit of time.
    4. Stability. Record rate-limit thresholds, error code distribution, and timeout frequency, and watch whether output behavior changes after model version updates. Production systems should treat behavioral drift as a monitored risk category.

    3. Build a Benchmark Close to Your Business

    The benchmark is the foundation of any credible selection decision. The recommended steps are:

    Step 1: Sample from real business logs. Samples should cover high-frequency requests, long-tail requests, and known hard cases. Avoid picking only examples the model handles easily.

    Step 2: Stratify by difficulty. Divide samples into easy, medium, and hard tiers, and compute the pass rate for each tier separately. This reveals where a model starts to fail and makes tiered routing easier later.

    Step 3: Define clear scoring criteria. Anything verifiable by rules (format, field completeness, key numeric values) should be judged programmatically. Content that cannot be rule-checked should be labeled independently by two annotators, with inter-annotator agreement calculated.

    Step 4: Run blind evaluations. Reviewers should not know which model produced a result, to reduce subjective bias.

    Step 5: Control sample size. With only twenty or thirty samples, variance in pass rates can exceed the real gap between models. In practice, each difficulty tier should contain at least several hundred samples for the comparison to carry statistical meaning.

    4. Calculate Cost per Valid Result

    The following example shows how to combine token usage, retry rate, and pass rate into a single comparable metric. The unit prices are placeholders—replace them with actual platform prices and keep units consistent.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class PriceConfig:
    4. input_per_million: float # unit price per million input tokens
    5. output_per_million: float # unit price per million output tokens
    6. def cost_per_call(input_tokens: int, output_tokens: int,
    7. price: PriceConfig, retry_rate: float = 0.0) -> float:
    8. """Expected cost per task, scaled up proportionally by retries."""
    9. base = (input_tokens * price.input_per_million
    10. + output_tokens * price.output_per_million) / 1_000_000
    11. return base * (1 + retry_rate)
    12. def cost_per_valid_result(avg_cost: float, pass_rate: float) -> float:
    13. """Cost per valid result. Returns infinity when pass rate is 0, meaning the model is unusable."""
    14. if pass_rate <= 0:
    15. return float("inf")
    16. return avg_cost / pass_rate
    17. # Example: compare using average token counts and pass rates from benchmark runs
    18. price_a = PriceConfig(input_per_million=1.0, output_per_million=4.0)
    19. cost_a = cost_per_call(input_tokens=1200, output_tokens=600,
    20. price=price_a, retry_rate=0.08)
    21. print(cost_per_valid_result(cost_a, pass_rate=0.92))

    Two cautions when using this metric. First, average token counts should come from actual benchmark runs, not estimates. Second, the pass rate and the cost must be measured on the same set of samples; otherwise the comparison is meaningless.

    5. Balancing Quality and Cost

    Model selection is not about finding a single optimum but about choosing the right tradeoff under constraints. You can plot each candidate model on a two-dimensional plane of (cost per valid result, pass rate). Models on the “low cost, high pass rate” side form the Pareto frontier, and every model on that frontier has its own justification.

    A common production practice is tiered model usage: route simple requests to a cheaper model and complex or high-risk requests to a more capable one. Routing rules can be based on input length, task type, or historical failure records. Routing itself adds overhead, which should be included in the evaluation.

    6. Common Pitfalls

    Pitfall 1: Relying only on public leaderboards. Benchmark questions rarely match your business data distribution. Conclusions must be validated with your own evaluation set.

    Pitfall 2: Ignoring output length. Output tokens are usually more expensive than input tokens, and models may answer verbosely on irrelevant content. State length requirements explicitly in prompts and include output length in your metrics.

    Pitfall 3: Ignoring retries and manual rework. Counting only API bills underestimates the true labor and financial cost.

    Pitfall 4: Treating evaluation as one-time. Model versions, prompts, and business data all change. Run regression tests regularly.

    7. Rollout Recommendations

    1. Do canary releases before full launch. Route a small fraction of traffic to the new model first, compare key metrics, then gradually increase the share.
    2. Keep a fallback plan. Automatically switch to a backup model during rate limiting or service failures, and log every switch event.
    3. Build a monitoring dashboard. Continuously track cost per valid result, pass rate, latency percentiles, and error code distribution. Trigger a re-evaluation when metrics drift noticeably.
    4. Version-control prompts and the evaluation set. Every model or prompt change should be reproducible against historical conclusions, making troubleshooting easier.

    In summary, LLM API selection should be centered on your business tasks: use cost per valid result instead of unit price, and rely on scenario-representative evaluation plus continuous monitoring to ensure the decision remains valid as models iterate.