LLM Service Selection: How to Evaluate Performance and Cost Trade-offs

    This article explains how to choose an LLM service by weighing performance against cost. It covers three questions: whether a model can complete a business task, what each successfully completed task costs, and whether costs stay manageable at scale. It explains why leaderboard scores and unit prices alone are not enough, how input, output, and cached tokens affect billing, and how context limits and hidden reasoning costs change the total. The article includes a formula for cost per successful task with example code, a seven-step selection process, and implementation tips.

    1. Background: Capabilities and Cost Structures Evolve Together

    Over the past year, LLM services have continued to improve. Long-context understanding, file parsing, content generation, and data analysis are gradually entering everyday development workflows. Coding assistants and automated agents have also started handling multi-step tasks.

    As capabilities grow, pricing has become more granular. The early model of billing per call or with a fixed subscription has been replaced by per-token pricing. A bill usually includes several unit prices, such as input, output, and cached input tokens. Some services also tie context length to subscription tiers.

    This structure creates two practical problems. First, the same workload can cost several times more per month on different services, and list prices alone do not show the actual spending. Second, more capable models tend to produce longer outputs and more reasoning steps, so costs can grow faster than call volume. If selection only compares unit prices or leaderboard rankings, the results can easily drift away from budget and business goals.

    Therefore, selection needs to answer three questions: Can the model complete the business task? How much does it cost to complete one task? Remains cost controllable at scale? The following sections address each question in turn.

    2. Breaking Down the Evaluation Dimensions

    2.1 Capability: Public Leaderboards Cannot Replace Business Evaluation

    Public leaderboards measure general capabilities across tasks such as knowledge Q&A, math reasoning, and code generation. They help teams narrow down the candidate list, but they cannot show directly how a model will perform in a specific business. For example, a model that scores highly on general programming problems may not reliably fix defects in your codebase, or call your internal APIs correctly.

    Business evaluation should use samples drawn from real tasks. Prepare a representative set of samples, and give each one an input, an expected result, and pass criteria. For agentic programming tasks, you can track the following metrics:

    • Task success rate: the share of tasks completed within a set number of turns.
    • Average tool calls: reflects planning efficiency.
    • Average repair rounds: reflects the model’s ability to self-correct after errors.
    • Manual review pass rate: reflects how usable the output is in a real environment.

    2.2 Pricing: Input, Output, and Cache Hits

    Most services break costs into three parts: uncached input tokens, cached input tokens, and output tokens. Their unit prices often differ significantly. Cache-hit prices are usually much lower than regular input prices, while output prices are usually the highest.

    The cache hit rate depends on how requests are structured. If every request starts with the same prefix, such as the system prompt, tool definitions, and fixed background material, the server can more easily reuse content it has already processed. In contrast, inserting timestamps, random IDs, or user-specific information that changes with each request into the prefix lowers the hit rate noticeably. Teams can log the cache-hit fields for each request at the gateway layer, then aggregate hit rates by day as a metric for ongoing optimization.

    2.3 Context: Long Context Is Not Free

    Long-context capability helps process large documents or multi-file codebases in one pass, but it directly increases the number of input tokens. More importantly, some services tie context limits to subscription tiers. Before selecting a service, confirm the following:

    • Whether the limit applies per request, per account, or per time window.
    • What happens when the limit is exceeded: truncation, an error, or an automatic switch to another option.
    • Whether different tiers have different concurrency or rate limits.

    In practice, you do not need to use the maximum context on every request. A better approach is to retrieve or summarize first, send only the most relevant passages to the model, and expand the scope only if the result requires it.

    2.4 Hidden Costs: Reasoning and Output Length

    Some models perform lengthy internal reasoning before they answer. This reasoning is usually billed as output tokens, so longer reasoning raises both cost and latency. When evaluating, avoid looking only at the per-token price of a single call. Instead, calculate the total cost of completing one valid task:

    Cost per successful task = total spending over a period ÷ number of successfully completed tasks

    The comparison is meaningful only when the denominator counts successful tasks. Otherwise, a model with a low unit price but a high failure rate may actually cost more.

    3. Cost Model and Example Code

    The code below shows how to break a bill into a formula that you can recalculate. The unit prices are illustrative assumptions that explain the calculation method. Replace them with the prices published by your provider before use.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class PriceTable:
    4. input_per_m: float # Price per million uncached input tokens (CNY)
    5. cached_per_m: float # Price per million cached input tokens (CNY)
    6. output_per_m: float # Price per million output tokens (CNY)
    7. @dataclass
    8. class Usage:
    9. input_tokens: int # Total input tokens, including cached tokens
    10. cached_tokens: int # Number of cached input tokens
    11. output_tokens: int # Number of output tokens
    12. successes: int # Number of successfully completed tasks
    13. def period_cost(price: PriceTable, usage: Usage) -> float:
    14. uncached = usage.input_tokens - usage.cached_tokens
    15. total = (
    16. uncached * price.input_per_m
    17. + usage.cached_tokens * price.cached_per_m
    18. + usage.output_tokens * price.output_per_m
    19. )
    20. return total / 1_000_000
    21. def cost_per_success(price: PriceTable, usage: Usage) -> float:
    22. return period_cost(price, usage) / max(usage.successes, 1)

    The example below uses illustrative prices of 10 CNY per million uncached input tokens, 1 CNY per million cached input tokens, and 20 CNY per million output tokens. Assume a month with 100 million input tokens in total, of which 80 million are cache hits, and 5 million output tokens.

    • With caching: 20 million uncached tokens cost 200 CNY, 80 million cached tokens cost 80 CNY, and 5 million output tokens cost 100 CNY. The total is 380 CNY.
    • Without caching: all 100 million input tokens at the uncached rate cost 1,000 CNY, plus 100 CNY for output. The total is 1,100 CNY.

    Under these assumptions, cache hits reduce the monthly cost by about 65%. The actual benefit depends on the hit rate and the price gap, so teams should recalculate with their own usage data.

    4. Selection Process and Implementation Advice

    Follow these steps to run the selection:

    1. Build a task inventory. Grade tasks by business value and complexity. Identify which tasks need strong reasoning and which only need fast responses.
    2. Build an evaluation set. Prepare a sufficient number of samples for each task type, and define automated or manual pass criteria.
    3. Measure success rate and latency. Run the candidate models on the same samples, and record the success rate, time to first token, and full response time.
    4. Calculate cost per successful task. Use the formula in Section 3 to match billing data with the number of successful tasks.
    5. Verify context boundaries. Test truncation behavior, error codes, and response quality with samples close to the context limit.
    6. Set budget guardrails. Configure usage thresholds, daily caps, and alerts for abnormal growth in your monitoring system. These prevent cost overruns caused by sudden traffic spikes.
    7. Route requests by tier. Send simple tasks to lower-cost models and escalate complex tasks to more capable models. Base routing rules on task type or an upstream classification result, not on manual decisions for each request.

    For implementation, consider these practices:

    • Wrap model calls behind a unified client interface, so business code does not depend on a provider’s proprietary fields. This makes future switches easier.
    • Write request logs to a logging service with at least input tokens, cached tokens, output tokens, latency, and task result. Review them weekly.
    • Keep the prompt prefix structure fixed, and sort tool definitions in a stable order to improve cache hit rates.
    • Split long documents and retrieve relevant segments first, then send only that content to the model to reduce input size.

    5. Risks and Considerations

    Prices and subscription rules change, so selection conclusions need a review cycle. For example, recalculate them every quarter. Store the price table in a configuration file, and record its effective date so you can trace historical bills.

    Data compliance also needs early planning. Before sending business data to an external service, confirm the data classification, masking requirements, and approval process. This prevents sensitive information from being shared without authorization.

    Do not rely on a single metric for decisions. Leaderboard scores, unit prices, and subjective experience are all partial signals. A technical decision is only well supported when capability, cost, and stability are compared together in one table.