LLM Inference Cost Optimization: Model Selection and Practices in the Era of Cheaper Caching

    This article examines a pricing shift where standard input and output rates stay flat while cached input (cache read) prices drop significantly. It explains how prompt caching works across the prefill and decode stages, why chat-style workloads see little benefit, and which scenarios such as agents, RAG, batch extraction, and code understanding gain the most. You will find a practical effective-cost model, techniques for designing stable prefixes to raise cache hit rates, and a tiered routing approach for model selection instead of a full migration, along with common pitfalls to avoid.

    1. The Signal: List Prices Held Steady, but Caching Got Cut

    A recent round of pricing changes is worth a closer look: mainstream LLM services keep their standard input and output rates at the same tier of $2 and $10 per million tokens, while the real reduction targets cached input (cache read) prices, with some options cut in half again. At the same time, advanced coding and computer-use capabilities have moved up to higher-positioned model tiers.

    Many developers’ first reaction is “another same-price rebrand,” so they focus on benchmark tables. From an engineering perspective, however, the point of this change is not the leaderboard but the cost structure: when cache read prices fall well below standard input prices, the unit cost of “repeated prefix” workloads such as long context, multi-turn conversations, and batch document processing gets redefined, while short conversations and low-repetition workloads barely notice the difference.

    This article does not evaluate any specific product. Instead, it abstracts the issue into a general technical question: under a cache-based pricing model, how do you estimate real cost, improve cache hit rates, and make tiered selection across model tiers?

    2. How It Works: What Prompt Caching Actually Saves

    LLM inference has two stages:

    • Prefill: encoding all input tokens at once, with compute growing as input length increases; this is the main cost of long context.
    • Decode: generating output token by token, affected by output length and concurrency.

    The core idea of prompt caching is that if multiple requests share an identical prefix (system prompt, tool definitions, long documents, few-shot examples), the KV (Key/Value) computation for that prefix can be reused without re-running prefill. This creates three billing categories:

    Billing item Meaning Relative cost
    Cache write Input that establishes the cache for the first time Usually close to or slightly above standard input
    Cache read Input that hits the cache Significantly below standard input, cut again this round
    Standard input Input that misses the cache Baseline price
    Output Generated content Usually the highest

    The key point: caching only applies to parts where the prefix is exactly identical. Whether you get a hit does not depend on whether you want to save, but on whether your request assembly is stable.

    3. Boundaries: Why “Chat Doesn’t Benefit” Is Correct

    The claim that “cache prices are halved, but chat doesn’t benefit” holds up in engineering terms, for three reasons:

    1. Unstable prefix: each turn of a multi-turn chat appends content. The history may stay unchanged, but if the system prompt or tool definitions change dynamically within a session (timestamps, random IDs, user profile injection), the prefix hash changes and the cache is invalidated.
    2. Low repetition: short conversations have a small base of input tokens. Even with a full hit, the absolute savings are limited and not enough to offset the engineering cost of modifying the integration layer.
    3. Limited hit window: caches usually have a time-to-live (TTL). Long gaps between turns can expire the cache and force a rewrite.

    Conversely, these workloads are the main beneficiaries of cheaper caching:

    • Agent loops with a fixed system prompt and fixed tool schema;
    • Repeated Q&A and retrieval-augmented generation (RAG) over long documents or large codebases;
    • Batch structured extraction: the same template processing thousands of records;
    • Code completion and repository-level understanding: stable repository context with only the tail changing.

    4. Cost Accounting: Don’t Just Look at Unit Price, Calculate Effective Cost

    Use a simple model to make decisions instead of relying on intuition:

    1. # Illustrative cost model; parameters must be based on the actual bill
    2. def effective_cost(n_requests, ctx_tokens, out_tokens,
    3. p_in, p_out, p_cache_write, p_cache_read,
    4. hit_rate, write_ratio=0.1):
    5. hit = ctx_tokens * hit_rate
    6. miss = ctx_tokens - hit
    7. writes = ctx_tokens * write_ratio # extra writes from cache rebuilds
    8. per_req = (miss * p_in
    9. + hit * p_cache_read
    10. + writes * p_cache_write
    11. + out_tokens * p_out)
    12. return per_req * n_requests

    Three cautions when using this model:

    • Hit rate is not 0/1, but a continuous value affected by prefix stability, TTL, and concurrency scheduling; it must be estimated from real traffic samples.
    • Write cost cannot be ignored; frequently rebuilding the cache (a prefix with random elements) turns the “discount” into a “surcharge.”
    • Output cost is often the dominant term; if outputs are long, cache optimization has limited impact on the total bill.

    A rule of thumb: cache optimization is worthwhile only when the ctx_tokens / out_tokens ratio is high and prefix repetition across requests is high.

    5. Practice: Turning Hit Rate from Luck into Something You Can Design

    Improving the hit rate is essentially an engineering problem of request construction. Recommended practices:

    1. Fix prefixes in stability layers: assemble content by stability—tool definitions → system instructions → long-term knowledge → conversation history → current input. Put anything that changes at the tail.
    1. [stable] tools schema
    2. [stable] system instructions
    3. [stable] long documents / codebase context
    4. [semi-stable] conversation history
    5. [volatile] current user input, timestamps, random IDs
    1. Remove dynamic variables from the prefix: keep time, random numbers, and request IDs out of the prefix.
    2. Control cache granularity: a prefix that is too long extends write time, while one that is too short yields low hit gains; load-test by workload.
    3. Monitor instead of guessing: instrument hit rate, cache read share, and average context length, and watch trends with monitoring and alerts.
    4. Fallback path: when the cache is unavailable or the hit rate drops sharply, automatically fall back to standard input, prioritizing availability.

    6. Selection: Tier Capabilities and Route, Don’t Switch Everything

    The real dilemma is whether teams that already switched should switch again. The safer answer: don’t do a full switch; build tiered routing.

    • Tier by task: split requests into “high-value, high-difficulty” (complex coding, long tool-call chains, computer use) and “high-frequency, low-difficulty” (classification, extraction, short Q&A, formatting).
    • Tier by cost: route high-frequency, low-difficulty tasks to the cost-effective tier and make use of caching where possible; route difficult tasks to a more capable, higher-positioned tier.
    • Decide with an evaluation set: maintain a regression set of 50–200 real business samples, tracking accuracy, latency, and cost per request; run any switch against this set first.
    • Canary and rollback: roll out by traffic percentage, set cost and latency thresholds, and roll back automatically on anomalies.

    Illustrative routing logic:

    1. def route(task):
    2. if task.difficulty >= 3 or task.needs_tool_loop:
    3. return "high_capability_tier"
    4. if task.repeat_prefix and task.ctx_len > 8000:
    5. return "cache_friendly_tier"
    6. return "cost_efficient_tier"

    7. Common Pitfalls

    • Pitfall 1: A price cut equals savings. With a very low hit rate, cache writes actually raise cost.
    • Pitfall 2: Longer context is always better. Long context adds prefill overhead and noise; trimming context after retrieval is often more economical.
    • Pitfall 3: Choosing models by benchmarks alone. Business metrics and unit cost are the basis for decisions; leaderboards are only a reference.
    • Pitfall 4: A one-time full migration. Migration without evaluation and rollback carries far more risk than benefit.

    8. Conclusion

    This round of “steady list prices, cheaper caching” essentially hands control of cost optimization back to engineering: whoever designs a more stable prefix, achieves a higher hit rate, and tiers models more finely captures the real cost dividend. For teams already using a given model tier, the right move is not to switch again, but to first measure hit rate and effective cost, then use an evaluation set and canary mechanisms to decide on tiered migration. When deploying in the cloud, you can combine object storage for long documents, a message queue for peak shaving, a container platform for the inference gateway, and logging with monitoring and alerts to observe hit rates, forming a closed-loop cost governance system.