LLM Inference Cost: A Practical Benchmarking and Model Selection Guide

    This article explains why comparing models by per-token price alone usually leads to wrong decisions, and shows how to build a more accurate cost model based on token volume, cache hit rate, retry rounds, and output length distribution. It covers four metrics to quantify your token profile, how prefix caching and multi-round strategies reduce cost, a one-week A/B testing plan, turning prompts into reusable cost-saving assets, evaluating frontend and multimodal code generation, and a set of practices for making model selection a sustainable engineering process.

    1. The Starting Point: Why “Price-per-Token Comparison” Is Almost Always Wrong

    Whenever a new lightweight LLM launches, the hottest community discussion tends to focus on “how much per million tokens.” This comparison is intuitive, but it very easily leads to the wrong conclusion. The reason is simple: unit price is only one coefficient in the cost formula. What actually determines the bill is total token volume, cache hit ratio, number of retry rounds, and the distribution of output lengths. Discussing unit price while holding these variables fixed amounts to assuming that all options have identical workloads, when in reality their behavior patterns differ dramatically.

    A cost model closer to engineering reality can be written as:

    1. Cost per task ≈ (input tokens × input price × (1 - cache discount × hit rate)
    2. + output tokens × output price) × expected call rounds

    From this formula, you can see that a 30% fluctuation in any one of the three multiplier factors will erase the advantage of “half the unit price.” Therefore, the first step in selection is not to look at the price list, but to quantify the token profile of your own workload.

    2. Quantifying the Token Profile: Four Metrics You Must Measure First

    1. Average input-to-output ratio. Code generation tasks have long inputs and short outputs; summarization and rewriting tasks are the opposite. The ratio determines which side’s unit price is more sensitive.
    2. Prefix stability. If the prompt template, system instructions, and knowledge base snippets are highly consistent across multiple calls, prefix caching can take effect; if you concatenate a timestamp or random ID every time, cache hits are nearly impossible.
    3. Expected rounds. Asking the model to self-check, vote across multiple candidates, or retry on failure all multiply the number of calls.
    4. Output length variance. The impact of long-tail, extra-long outputs on the bill often exceeds that of the average itself.

    It is recommended to turn these four items into a baseline table that serves as the anchor for all subsequent comparisons. A comparison without a baseline is just a numbers game.

    3. Caching and Multi-Round Strategies: Two Undervalued Levers

    The essence of prefix caching is to amortize repeated computation; the higher the hit rate, the lower the effective input unit price. Engineering practices to improve the hit rate include: placing stable content first, placing volatile content last, structuring prompts into layers, and avoiding the insertion of session-level variables into the common prefix. A schematic structure is shown below:

    1. [Stable layer] Role definition + output specification + domain knowledge
    2. [Semi-stable layer] Task template + a few examples
    3. [Volatile layer] User input + session context + timestamps

    Multi-round convergence is another path: instead of delivering after a single generation, let the model produce multiple candidates and then converge, trading rounds for accuracy. Its cost is a linear increase in call volume, and its benefit is reduced rework from a lower error rate. The criterion is clear—if the downstream is an automated pipeline, the cost of fixing an error downstream is far higher than one extra call, so a multi-round strategy pays off; if the downstream is human review, then reducing rounds should take priority.

    4. Replace Intuition with A/B Testing: A One-Week Benchmark Plan

    The most reliable approach is to run real traffic through candidate options in the same environment. Key design points:

    • Same dataset: Fix the task set and random seed to avoid sample drift.
    • Same prompt: Replace only the model layer to isolate variables.
    • Layered accounting: Track tokens and costs separately by task type rather than looking only at the total.
    • Quality gate: Record pass rate and human spot-check scores at the same time, to prevent “cheaper but unusable.”

    Pseudocode skeleton:

    1. for case in dataset:
    2. for model in candidates:
    3. r = call(model, prompt=case.prompt)
    4. ledger[model].add(r.usage, latency=r.latency)
    5. score[model].add(evaluate(case, r.text))
    6. report(ledger, score) # Three-way comparison: cost, hit rate, quality

    Only after running through a complete business cycle (including peaks and troughs) do the conclusions carry statistical meaning.

    5. Treating Prompts as Assets: Moving Cost Reduction from the Model Layer to the Engineering Layer

    An often-overlooked fact is that accumulated high-quality prompts are themselves a cost-reducing asset. Structuring prompts, task summaries, and reusable skill snippets into a searchable case library, and having new tasks reuse them first rather than build from scratch, can significantly reduce trial-and-error calls. The typical generation pipeline for such an asset library can be abstracted into three steps:

    1. Collect raw requirements → Normalize summaries → Extract reusable prompt templates → Store and tag applicable scenarios

    The pipeline itself can be handed to a low-cost model for scheduled batch processing, reserving expensive models for steps that require complex reasoning, forming a cost gradient.

    6. Frontend and Multimodal Code Generation: Another Measurable Capability

    Beyond text tasks, interface code generation is one of the fastest-changing directions today. When evaluating this capability, it is recommended to focus on four observable metrics: whether the structure and semantics are correct, style fidelity, whether the interaction runs, and the maintainability of the generated result. The testing method is straightforward—give the same page requirement to each candidate, have them produce their output, then run, screenshot, and compare in a unified environment. This capability places higher demands on prompt structuring; specifying component hierarchy and design constraints explicitly is usually more effective than piling on adjectives.

    7. Implementation Advice: Make Selection a Sustainable Mechanism

    1. Build a baseline table and an accounting dashboard, attributing costs by task dimension.
    2. Use a layered prompt structure to improve cache hits, placing volatile content last.
    3. Enable multi-round convergence for high-value tasks; limit rounds and output length for long-tail tasks.
    4. Re-run the A/B test every quarter, because both prices and model capabilities change.
    5. Run evaluation and batch processing tasks on general-purpose cloud resources, with object storage for datasets, log services and monitoring alerts to track cost and quality metrics, and a container platform to host reproducible evaluation environments, making the whole process repeatable and auditable.

    The conclusion is not complicated: don’t ask “which model is cheapest,” but ask “under my token profile and quality constraints, which combination has the lowest total cost.” Breaking this question down into measurable metrics, reproducible experiments, and accumulable assets turns cost optimization from a one-time judgment into a long-term engineering capability.