LLM Inference Cost Benchmarking: Why Price Per Token Doesn't Equal Your Bill

    This article breaks down LLM inference cost measurement into three calculable variables—prompt tokens, completion tokens, and throughput—and explains why a higher-priced model can cost less overall due to better token efficiency. It covers reproducible benchmark design, result interpretation, and engineering techniques such as context governance, prompt caching, and tiered routing to control spending.

    1. The Problem: Unit Price Is Not Your Bill

    In a comparison test across model generations, a seemingly contradictory pattern emerged: a model priced one tier higher cost only twice as much as the cheaper model to complete the same task, rather than the four times implied by its unit price. It also finished faster. In a few samples, the more expensive model was slower—usually because the cheaper model terminated generation early and produced incomplete output.

    This reveals a commonly overlooked fact: your bill is determined by unit price multiplied by actual consumption, and actual consumption depends on the model’s token efficiency. Comparing price per million tokens alone easily leads to the wrong conclusion.

    2. Breaking Cost Into Three Calculable Variables

    Let the total task cost be:

    1. Cost = (PromptTokens + CompletionTokens) / 1e6 * PricePerMillion
    2. Latency ≈ TTFT + OutputTokens / Throughput

    Three key variables:

    • PromptTokens: The accumulated input from system prompts, context, tool results, and conversation history.
    • CompletionTokens: Includes the final output and intermediate reasoning content such as chain-of-thought, and is the main source of generational differences.
    • Throughput: Decoding throughput, which determines end-to-end latency.

    “Token efficiency” means the total tokens consumed per task without sacrificing output quality. Newer models often reach the correct conclusion with fewer tokens through more thorough training and optimized inference strategies; older models tend to probe repeatedly and re-read context, causing “token bloat.”

    3. Test Design: Making Results Reproducible

    The original test used “relatively easy tasks.” Such tasks are suitable for validating a methodology, but extrapolating the conclusions requires caution. A more rigorous benchmark should include:

    1. Task tiers: Short Q&A, multi-step code edits, long-document summarization, and cross-file refactoring, measured separately.
    2. Fixed context: Standardize the system prompt and retrieved snippets to avoid input-side differences contaminating results.
    3. Repeated sampling: Run each task type at least 3–5 times, and report the median and dispersion rather than a single value.
    4. Quality gate: Define a pass criterion first (for example, all unit tests green), and count costs only for “passed samples.” Otherwise, the cheaper model’s “savings” are just early abandonment.
    5. Full-chain logging: Account for cache hit rate, retry count, and tool-call rounds.

    Illustrative statistics script:

    1. record = {
    2. "task_id": tid,
    3. "model_tier": "high", # high / low tier
    4. "prompt_tokens": p,
    5. "completion_tokens": c,
    6. "latency_sec": t,
    7. "passed": True,
    8. }
    9. cost = (p + c) / 1_000_000 * unit_price

    4. Interpreting Results: Why the Pricier Model Can Be Cheaper

    • Non-linear cost: A fourfold unit price with less than half the consumption yields roughly twice the total spend; a twofold unit price with flat consumption yields a total comparable to the previous generation.
    • Latency vs. completeness trade-off: Longer runtime does not necessarily mean slower; judge it alongside task completion. Output that ends early often requires rework, and rework cost belongs in the total.
    • Rework is a hidden expense: One incomplete output can trigger multiple retries, and the actual token and labor cost far exceeds the apparent price difference.

    5. Cost-Reduction Techniques on the Engineering Side

    • Context governance: Inject retrieved snippets on demand and use rolling summaries for conversation history to avoid repeatedly billing irrelevant content.
    • Prompt caching: Place stable system instructions and knowledge snippets first to improve cache hit rate and reduce duplicate input billing.
    • Tiered routing: Send simple requests to lightweight models and escalate complex reasoning to higher-capability tiers, using rules or confidence scores for routing.
    • Output constraints: Limit structure and length to suppress unbounded expansion.
    • Observability: Aggregate tokens and cost by task in logging services and monitoring alerts to build a cost dashboard, and use container platform auto-scaling to control peak spending.

    6. Conclusion

    The right approach to model selection is not comparing unit prices, but comparing the cost per unit of effective output. Teams should build their own small benchmark set, lock in quality gates, repeated sampling, and full-chain metering, and then set tiered invocation and budget strategies accordingly. If you already use relevant general capabilities from Baidu AI Cloud (such as logging services, monitoring alerts, and container platforms), you can apply the metering approach above directly within your observability system, turning cost optimization from experience-based judgment into a data-driven process.