Lightweight LLM Selection: Using Cost-Performance Metrics for Technical Decisions

    This article explains how to evaluate lightweight LLMs by total task cost rather than unit token price. It covers common billing dimensions, a monthly cost estimation model, evaluation criteria beyond price, a standardized selection workflow, and engineering optimizations that reduce cost after deployment.

    1. Why Unit Price Becomes the Selection Focus

    After an LLM is integrated into a business service, token consumption often becomes a major variable cost. At sufficient call volume, small differences in unit price are amplified. For example, if a service handles millions of requests per day, even a small fraction of a cent difference per call can lead to a significant difference in the monthly bill. Developers therefore naturally treat unit price as the first screening criterion.

    But unit price is only part of the cost. Whether a model can complete the task, how many calls it takes to complete it once, and whether manual rework is required also determine the final cost. During selection, “price per unit” should be replaced with “total cost to complete a single business task.”

    2. Understand Common Billing Dimensions

    Most model services charge by token, and billing rules usually include the following dimensions:

    • Separate pricing for input and output: Input tokens refer to prompts and context, while output tokens refer to content generated by the model. Their unit prices are often different, and output tokens are generally priced higher.
    • Cache hits and misses: When the prefix of a request matches recent requests, some services charge a lower price. The more stable the system prompt and fixed knowledge snippets are, the higher the hit rate.
    • Time-based differences: Some services charge higher unit prices during peak business hours and lower prices during idle periods.
    • Concurrency and rate limiting: Under high concurrency, rate limiting can cause queuing or retries, indirectly increasing latency and request counts.

    Billing rules change with service versions and plans. Before selection, rely on the provider’s latest documentation rather than numbers from older articles.

    3. Build a Cost Estimation Model

    You can use the following formula to estimate monthly cost:

    1. monthly_cost = daily_requests * 30 * (avg_input_tokens * input_price_per_m + avg_output_tokens * output_price_per_m) / 1_000_000

    For actual estimates, count the real input and output lengths from production workloads rather than using ideal values. Example code:

    1. def estimate_monthly_cost(daily_requests, avg_input_tokens, avg_output_tokens,
    2. input_price_per_m, output_price_per_m,
    3. cache_hit_ratio=0.0, cached_input_price_per_m=None):
    4. """Estimate monthly call cost. Unit prices are per million tokens."""
    5. if cached_input_price_per_m is None:
    6. cached_input_price_per_m = input_price_per_m
    7. hit_tokens = avg_input_tokens * cache_hit_ratio
    8. miss_tokens = avg_input_tokens - hit_tokens
    9. per_request_cost = (
    10. miss_tokens * input_price_per_m
    11. + hit_tokens * cached_input_price_per_m
    12. + avg_output_tokens * output_price_per_m
    13. ) / 1_000_000
    14. return daily_requests * 30 * per_request_cost

    When using this type of function, it is advisable to treat parameters such as cache hit rate and peak-hour share as ranges, then calculate optimistic and pessimistic values separately instead of relying on a single result.

    4. Evaluation Dimensions Beyond Unit Price

    At the same unit price, the actual cost of different models can vary widely. The main reasons include the following.

    1. Task completion rate: A model may have a lower cost per call but a higher failure rate on complex tasks. Retries and manual corrections after failures can offset the unit price advantage.
    2. Output quality: Offline evaluation should be performed on your own business data to check factual accuracy, format stability, and compliance with business rules.
    3. Latency and throughput: Time to first token and overall response time affect user experience. Batch tasks focus more on throughput, while real-time interaction focuses more on latency.
    4. Context length: The context window determines whether a long document can be processed in one pass. When the window is insufficient, splitting and stitching are required, which increases the number of calls.
    5. Structured output capability: If downstream systems depend on fixed formats such as JSON, the format error rate directly affects system stability.
    6. Migration cost: Whether prompts, evaluation sets, and post-processing logic depend on the behavior of a specific model determines the difficulty of switching in the future.

    5. Standardized Selection Process

    The following steps are recommended to make selection conclusions reproducible.

    1. Define task benchmarks: List typical tasks in the business and classify them by difficulty, such as simple classification, information extraction, and multi-step reasoning.
    2. Build evaluation sets: Collect dozens to hundreds of real samples for each task category and annotate the expected results.
    3. Standardize invocation conditions: Fix prompt templates, parameters such as temperature, and output formats so that the comparison focuses on the models themselves.
    4. Collect three types of metrics simultaneously: Quality, latency, and cost per call.
    5. Use weighted scoring: Set weights according to business priorities and calculate a composite score.

    Example of weighted scoring:

    1. def weighted_score(metrics, weights):
    2. """Metrics in metrics are normalized to 0-1, with higher values being better. Cost metrics need to be inverted first."""
    3. return sum(metrics[k] * weights[k] for k in weights)
    4. weights = {"quality": 0.5, "latency": 0.2, "cost": 0.3}
    5. candidate = {"quality": 0.82, "latency": 0.70, "cost": 0.90}
    6. print(round(weighted_score(candidate, weights), 3))

    Weights should be determined jointly by business and technical stakeholders. Financial review scenarios usually assign a higher weight to quality, while content summarization scenarios can place more emphasis on cost.

    6. Engineering-Level Optimization Methods

    After a model is selected, total cost can still be reduced through engineering design.

    • Stable prefix design: Place system prompts and fixed knowledge at the beginning of requests and keep them byte-for-byte consistent to help improve cache hit rates.
    • Tiered routing: Use lightweight models to handle simple requests first, and escalate to stronger models only when confidence is insufficient or the task is complex.
    • Abstraction call layer: Encapsulate the invocation methods of different services behind a unified interface to facilitate A/B testing and failover.
    • Usage monitoring: Record input and output token counts, latency, retry counts, and cost for each call, and summarize them by business line.
    • Quality sampling: Periodically sample online outputs for manual or automated evaluation, and adjust routing rules promptly when quality degradation is detected.

    7. Conclusion and Caveats

    A low unit price does not necessarily mean a low total cost. During selection, unit price, task completion rate, retry cost, and migration cost should be compared within the same framework.

    Model service prices and capabilities change with version updates. It is advisable to retest quarterly using the same evaluation set. As long as the evaluation process remains fixed, the benefits or risks brought by new options can be identified in time, and technical decisions can be adjusted accordingly.