A Practical Guide to LLM Inference Selection and Cost Evaluation

    Low per-token prices do not mean low total cost. This guide explains how to evaluate LLM inference by unit-task cost, verify model version and capability limits, break down three-part token billing, design cache-friendly prompts, and run a reproducible quality-plus-cost workflow.

    1. A Common Mistake: Low Unit Price Does Not Mean Low Total Cost

    When evaluating LLM inference, teams often treat “price per million tokens” as the only decision factor. The actual bill is driven by three variables:

    1. Total cost = unit price × tokens consumed per completed task × call volume

    Unit price is only one term. When two candidate models have similar prices, the gap usually comes from the second term—tokens required to finish the same task. Stronger models typically need fewer round trips, shorter intermediate reasoning, and fewer retries. Weaker models may trial-and-error, rewrite repeatedly, and retransmit context, multiplying token use.

    Shift the metric from “price per million tokens” to “cost to complete one standard task unit.” That figure tracks the business budget linearly.

    2. Three Basics to Check Before Selection

    2.1 Model Version and Knowledge Cutoff

    The knowledge cutoff bounds what the model knows about time-sensitive facts, new APIs, and recently released components. Two engineering implications:

    • Time-sensitive Q&A must use retrieval augmentation rather than parametric knowledge.
    • Cutoff is a cheap probe for whether a new version has been rolled out.

    Post-training can add some later corpus, so the model’s self-described knowledge range is often slightly later than the official date; that is not a contradiction. Probe questions should have a unique answer, be checkable offline, and clearly separate old vs. new versions—for example, a fictional or semi-fictional entity after the old cutoff. Use probes only as a secondary signal; official model ID and version fields from the provider are authoritative.

    2.2 Capability Bounds and Context Specs

    Check more than window size: structured output, tool calling and parallel calls, multimodal (vision/audio) input, max output length, and effective recall in long context. Being able to stuff tokens in is not the same as using them reliably. Validate mid-context recall with your own needle-in-a-haystack tests.

    2.3 Billing Dimensions

    Most inference APIs use three-part billing: input tokens, output tokens, and cache-read tokens. Typical relationships (illustrative only; use the provider’s published prices):

    Billing item Characteristics Optimization lever
    Input Usually cheapest, but largest volume in long-context use Trim context; retrieve instead of injecting everything
    Output Often several times input price Cap length; trim structured fields
    Cache read Much cheaper than ordinary input Raise hit rate; keep prefixes stable

    Cache reads are easy to ignore and high leverage. Pricing reuses computed prefix state for identical request prefixes. Prefix stability of the prompt therefore drives the bill.

    3. Cache-Friendly Context Layout

    Cache hits require byte-identical prefixes. Follow “static first, dynamic last”:

    1. [Fixed] system instructions, tool defs, output format, few-shot examples
    2. [Semi-fixed] domain knowledge, long docs (change by version, not per request)
    3. [Dynamic] current user turn, timestamps, tail of session history

    Anti-pattern: timestamps, random IDs, or nicknames at the start of the system prompt. Every request then has a unique prefix and cache never hits.

    Estimate cost before launch:

    1. def estimate_cost(input_tokens, output_tokens, cache_read_tokens,
    2. p_in, p_out, p_cache):
    3. """Estimate per-call cost under three-part billing; keep price units consistent with the caller."""
    4. uncached_input = max(0, input_tokens - cache_read_tokens)
    5. return (uncached_input * p_in
    6. + output_tokens * p_out
    7. + cache_read_tokens * p_cache)
    8. # Example: 20k input, cache hit rate 0 vs 80%
    9. base = dict(input_tokens=20000, output_tokens=800,
    10. p_in=8.0, p_out=40.0, p_cache=0.4)
    11. no_cache = estimate_cost(**base, cache_read_tokens=0)
    12. with_cache = estimate_cost(**base, cache_read_tokens=16000)
    13. print(no_cache, with_cache, no_cache / with_cache)

    In repeated long-context calls, each step up in cache hit rate cuts input-side cost roughly linearly and can reduce the overall bill several times. That is why cache-read price belongs on the scorecard.

    4. Make Evaluation a Reproducible Engineering Process

    1. Build a task benchmark. Sample 100–300 representative requests from production logs (high-frequency, long-tail, and edge cases). Label expected outputs and acceptance rules.
    2. Collect quality and cost together. Record pass rate and human scores plus tokens, unit-task cost, and cache hit rate on the same report so bill swings can be explained.
    3. Route by difficulty. Hard, long-chain work goes to stronger models; frequent simple work to lighter ones. Try a small model first and escalate on failure to cut average cost.
    4. Constrain output. Structured schemas and no unbounded free text cut output tokens directly.
    5. Observability. Log token use, cache hits, time-to-first-token, and retries; alert on per-business quotas and budget thresholds so one spike cannot exhaust credits.
    6. Elasticity and fallback. Stateless deploy on a container platform, queue for peaks; on model outage, fall back to a spare model or cached answers.

    5. Common Pitfalls

    • Watching only list price, not cache-read price, and overrunning long-context budgets.
    • Using the model’s self-described knowledge range instead of official version IDs for rollout checks.
    • Putting dynamic content first so cache never hits.
    • Measuring only average quality, ignoring P95 latency and retry-driven hidden tokens.
    • No per-line-of-business quota isolation, so one experiment drains the whole budget.

    6. Summary

    Selection is not “strongest” or “cheapest.” It is minimizing unit-task completion cost under quality constraints. Path: verify version and knowledge bounds, decompose three-part billing, cut input with cache-friendly layout, cut volume with routing and output constraints, then treat cost as a continuously optimized metric via observability. Teams that want less self-hosted inference ops can evaluate managed combinations of model serving, containers, logging, and monitoring from cloud providers such as Baidu AI Cloud and focus on product outcomes.