Why Inference Costs Get Cheaper the More You Use It

    This article explains why token counts can differ from actual billing by orders of magnitude in long, repetitive AI coding sessions. It covers how context caching turns repeated prefix reads into low-cost operations, how speculative decoding improves throughput on predictable code output, and a practical cost model built around cache hit rate and new-token ratio. Developers and enterprise architects will find concrete optimization practices for prompt layering, context governance, session splitting, output constraints, observability, and elastic capacity planning.

    1. The Puzzle: 16 Billion Tokens on a $200 Subscription

    A case circulating in developer communities puzzles many people: a long-term user checks a full year of subscription charges and finds the total is only in the low hundreds of dollars, while the client reports token consumption in the tens of billions. Converted at common pay-as-you-go rates, that number looks like a six-figure bill. So why can “reported usage” and “actual payment” differ by three to four orders of magnitude?

    Answering this requires correcting a common misconception: token counts do not equal real compute consumption, and certainly not cost. Tokens are merely a unit of measurement for billing and statistics. Inference cost depends on whether each segment of tokens needs its attention state recomputed, and whether the entire history must be read again. Multiplying “token count” by a “unit price” was roughly valid in the era of single-turn question answering, but it becomes badly distorted in long-session, high-repetition scenarios like AI coding.

    2. Root Cause: AI Coding Is a “High Repeated-Read” Workload

    Traditional chat is one question, one answer, with short context and little reuse, so cost grows roughly linearly with the number of turns. AI coding tools work in a completely different way. They behave more like a continuously running loop:

    1. Read task and repository context
    2. -> Assemble prompt (system instructions + history + tool results)
    3. -> Model outputs the next action
    4. -> Execute action (read file / search / run tests)
    5. -> Append new results back into context
    6. -> Return to step one, until the task is done

    Three characteristics of this loop determine the cost structure:

    1. The prefix is highly stable. System instructions, project notes, and already-read file contents barely change across many consecutive turns.
    2. History only grows and is never modified. Each turn appends a small amount of new content to the end of the existing context.
    3. The new compute per turn is small. The genuinely “new” tokens often account for only a few percent of the whole context.

    In other words, the vast majority of tokens are “repeated reads,” not “repeated computation.” This is the structural reason costs are diluted so heavily.

    3. Mechanism One: Context Caching Turns Repeated Reads into a Cheap Operation

    Mainstream inference services commonly offer context caching. The general principle is that when a request’s prefix is exactly identical to a previous request, the system can reuse the already-computed intermediate attention state and only compute the new portion. In engineering terms, several conditions usually apply:

    • The prefix must match byte for byte; any change invalidates everything after it.
    • There is a minimum cache lifetime; after it expires, the cache must be rebuilt.
    • Cache capacity has an upper limit, with eviction by priority or a least-recently-used policy.
    • Writing to the cache and hitting the cache are priced differently; the former is usually more expensive.

    Several practical conclusions follow. First, put stable content at the very front of the prompt and volatile content (timestamps, random IDs, current cursor position) at the end, and the hit rate improves significantly. Second, avoid modifying the system instruction template mid-session; a single change invalidates the entire history. Third, serializing subtasks reuses the prefix more easily than parallel, fragmented requests.

    An illustrative layout comparison:

    1. Inefficient layout: [current time][random request ID][system instructions][project notes][conversation history]
    2. Efficient layout: [system instructions][project notes][conversation history][current time][random request ID]

    4. Mechanism Two: Speculative Decoding Raises Output Efficiency in Long Sessions

    Speculative decoding is another widely adopted general optimization: a lightweight draft model guesses several tokens in a row, then the main model verifies them all in parallel at once, accepting the correct guesses and rolling back to recompute the rejected ones. Because verifying multiple positions costs far less than generating them one by one, throughput improves markedly in scenarios where output is highly predictable.

    Coding scenarios happen to be highly predictable: boilerplate code, repeated brackets and indentation, common API call patterns, and test assertion structures are all patterns a draft model hits easily. A high hit rate means more output per unit time, higher server-side resource utilization, and lower marginal cost. This also explains why a heavy user who “looks like usage exploded” is not necessarily a loss-making user for the provider.

    5. Cost Model: Replace Intuition with a Computable Formula

    The cost of a single request can be approximated as:

    1. Cost ~= new tokens x new-token price
    2. + cache-hit tokens x cache price (far below new-token price)
    3. + prefix tokens missed by cache x new-token price
    4. + output tokens x output price

    The key variables are the “hit rate” and the “new-token ratio.” In long-session coding workloads, the cache-hit portion often makes up the overwhelming majority while the new-token ratio stays very low, so the total cost is pushed down to a small fraction of the intuitive estimate. This is a reminder to architects: the optimization focus should not be on “using fewer tokens” but on “raising prefix stability and hit rate.”

    6. A Practical Optimization Checklist for Developers

    • Prompt layering: stable layer (role, conventions, repository conventions) first, dynamic layer (task, logs, errors) last.
    • Context governance: load long files on demand via retrieval instead of stuffing everything in every turn.
    • Session splitting: start a new session when switching tasks to avoid unrelated history piling up.
    • Output constraints: constrain output with structured formats to reduce wasted round trips and repeated generation.
    • Observability: use logging services and monitoring alerts to separately track new, cache-hit, and output tokens, and pinpoint abnormal amplification.
    • Elastic capacity: pair a stateless inference front layer with container platforms and message queues to smooth peaks, so long tasks do not saturate resources.

    7. What This Means for Enterprises

    For enterprise decision-makers, the real value of this case lies in three upgrades in understanding. First, evaluating the economics of an AI application should look at “effective new compute,” not surface-level total tokens. Second, cache hit rate is an engineering metric that architecture design can actively influence, and it should be included in capacity planning and cost accounting. Third, if an enterprise builds applications on general cloud capabilities (for example, object storage for a knowledge base, container platforms to host inference services, and logging and monitoring systems for usage attribution), treating cache-friendliness as a hard design constraint often yields greater gains than simply switching to a cheaper model.

    Once you understand this logic, you will no longer be led around by “billed a hundred times over” narratives: what truly determines cost is the proportion of repeated computation that gets eliminated. Whoever organizes context to be more stable and more reusable will produce several times the effective output on the same budget.