A Practical Guide to Million-Token Context and Cached Pricing for LLMs

    This article explains how million-token context windows and prefix caching reshape LLM cost and architecture. It breaks down three-part pricing (uncached input, cached input, output), shows why cache discounts matter, and details how to layer prompts so stable content stays cached. It also covers long-document and codebase patterns, a simple cost estimation model, validation metrics, common pitfalls, and a pre-launch selection checklist.

    1. Why Long Context Has Become a Baseline Capability

    In scenarios such as long-document understanding, cross-file code analysis, AI coding tools, and multi-turn agents, the size of the context window directly determines how much useful information a single request can hold. When the window expands from a few thousand tokens to the million-token range, a model can cover an entire set of API docs, multiple source files, or lengthy meeting notes in one call. The need for retrieval chunking and multi-turn stitching drops, and both pipeline complexity and latency jitter converge noticeably.

    As a result, the industry has been moving in one common direction: shifting million-token context from “an exclusive capability of a few premium tiers” to “a default configuration across the official service lineup,” while offering two specifications within the same model generation. One leans toward a higher capability ceiling and suits complex reasoning and long-chain tasks; the other leans toward higher throughput and lower cost, fitting high-frequency calls such as batch processing, extraction, rewriting, and code completion. Because both share the same context specification, developers can switch between them according to task value without changing how they call the API.

    2. Price Structure: Three-Part Pricing and the Cache Discount

    The key to understanding cost is to split a request into three parts: uncached input, cached input, and output. The common industry practice is to publish three numbers — input price, cached-input price, and output price — and output is usually far more expensive than input, which is the main source of cost in long-context scenarios.

    A set of public prices from the source material serves as an illustration: the lightweight tier is 1 per million input tokens, 0.2 for cached hits, and 2 for output; the high-capability tier is 12 for input, 1 for cached hits, and 24 for output. For comparison, a certain overseas flagship model’s next-day pricing was 30 USD per million output tokens, a gap that works out to two orders of magnitude after conversion. Note that specific numbers change over time and with vendor strategy; readers should rely on the official pricing page, and the figures cited here only illustrate the order of magnitude.

    What deserves real attention is the discount ratio: cached hits cost roughly one-fifth of uncached input on the lightweight tier and about one-twelfth on the high-capability tier. This design is not accidental; it steers a clear engineering habit — put stable, unchanging content first so caching takes effect naturally.

    3. How Cache Hits Work and How to Layer Prompts

    The general principle of prefix caching is that the server reuses the already-computed intermediate state for a leading segment of tokens that matches a previous request exactly, skipping the repeated forward computation. Hit detection typically requires the prefix to match token by token, and any difference at any position invalidates everything after it. Several practical rules follow from this.

    A layered structure is recommended: layer one holds system instructions and safety constraints, layer two holds tool and function definitions, layer three holds domain knowledge, templates, and a glossary, and only layer four holds the variable content of the current request. The first three layers should be “fixed at build time and unchanged at runtime.”

    1. [System instructions + output format constraints] # extremely stable, largest contribution to hit rate
    2. [Tool/function schema and calling conventions] # changes with version releases
    3. [Document templates / glossary / few-shot examples] # updated weekly or per version
    4. [Retrieved snippets and user input for this request] # different every time, keep at the very end

    Supporting engineering details include: disable random sampling that breaks determinism, fix the position of timestamps and random identifiers, avoid inserting request-level unique strings at the head, version-control templates and refresh the cache uniformly on release. If the platform exposes parameters such as cache expiration or minimum cacheable length, set them against call frequency so the reuse window of the fixed prefix covers business peaks.

    4. Practical Patterns for Long Documents and Codebases

    For long-document QA, you can place an entire contract, report, or specification into the context at once and use structured instructions to make the model locate the relevant section before answering, reducing the semantic fragmentation caused by chunking. In codebase scenarios, you can fix directory conventions, dependency lists, coding standards, and interface definitions in the prefix and append the files to be analyzed after them, so the access pattern of “standards stay fixed, code keeps changing” naturally fits the caching mechanism.

    Batch jobs are where caching pays off most clearly. Offline extraction, labeling, translation, and regression-test case generation usually share the same instructions and templates, so the hit rate can stay high over the long term; combined with async queues and concurrency control, throughput improves significantly under a fixed budget.

    5. Cost Estimation and Validation

    Use a simple model for budgeting: total cost equals uncached input volume times its unit price, plus cached input volume times the discounted price, plus output volume times the output price. Since output carries the highest unit price, controlling wasteful output (verbose explanations, repeated restatement) is often more effective than compressing input; structured output and length caps deliver direct savings.

    1. def estimate(reqs, p_in, p_hit, p_out):
    2. # reqs: [(uncached input tokens, cached input tokens, output tokens), ...]
    3. return sum(a * p_in + b * p_hit + c * p_out for a, b, c in reqs) / 1_000_000

    For validation, watch three categories of metrics at the same time: task accuracy or human rating, time to first token and overall latency, and cache hit rate plus per-request cost. Only when all three pass does the optimization count as successful. If the pipeline runs on general cloud capabilities, use logging services to record hits, monitoring and alerts to track cost drift, and object storage to archive samples for regression.

    6. Common Pitfalls and Risk Boundaries

    First, assuming “longer context is always better” — irrelevant content actually dilutes attention and must be paired with reranking and trimming. Second, writing variables into the head, which invalidates the whole cache. Third, looking only at unit price while ignoring the output share, which distorts the budget. Fourth, overlooking data compliance: long context means more data leaving local systems, so masking, retention, and deletion policies must be explicit. Fifth, ignoring vendor lock-in and migration cost; it is advisable to abstract prompts and templates and keep room to switch between the two model tiers and multiple vendors.

    7. Selection Checklist

    Before launch, start with six questions: does the task really need a million-token window; can the fixed prefix exceed half of the request; is output length controllable; how will the two model tiers be split; do cache expiration and call frequency match; and are the acceptance thresholds for cost, latency, and quality clear. Write the answers as configuration items rather than verbal agreements, and the benefits of long context and cached pricing will actually show up on the bill.