Large Language Model 1M Context and Prompt Caching: A Practical Guide to Pricing and Engineering

    This article explains what it means when a large language model makes a roughly 1M token context window the default rather than a premium tier, and how to design around it. It breaks down a two-tier pricing structure (Flash and Pro) to show why input and output are billed separately, why cache-hit discounts are deep, and why those discounts act as a guide for how to structure requests. It covers the engineering logic of prefix caching, the hard rule of placing static content before dynamic content, prefix versioning, typical scenarios such as long-document review and code repository understanding, a joint cost-and-quality optimization checklist, and common mistakes to avoid.

    1. What It Means When Long Context Becomes Standard Instead of a Selling Point

    Over the past year, long context was typically a premium-tier feature. Recently, the industry has shown a clear shift: million-token context is being set as the default capability of official services, with no tier separation. As described in the source material, a model preview offers both a Pro and a Flash tier, and both support roughly 1M tokens of context. The difference lies mainly in per-token price and throughput characteristics.

    The engineering implications matter more than the marketing ones. Once the context window shifts from a scarce resource to a baseline resource, application-layer architecture assumptions need to be rewritten:

    • Retrieval augmentation is no longer the only answer. Previously, working around the window limit required a full pipeline of chunking, vector recall, and reranking. When the window is large enough, an entire document or a medium-sized code directory can go straight into context, and the pipeline can be simplified significantly.
    • Chunking shifts from mandatory to optional. Whether to chunk becomes a tradeoff between quality and cost rather than a capability constraint.
    • The pressure to compress memory in multi-turn conversations drops. Long-running dialogues no longer need aggressive summarization; a sliding window plus retention of key fragments can maintain coherence.

    But a larger window does not mean attention quality improves linearly. Locating information within a long context and resisting distraction remain part of model capability, so engineering still needs to organize the order and structure of materials sensibly.

    2. Two Tiers and the Price Structure: Understanding the Billing Model Matters More Than Memorizing Numbers

    The pricing structure in the source material can be abstracted into the following general model (values are illustrative; refer to the provider’s published pricing for actual figures):

    Tier Input (cache miss) Input (cache hit) Output
    Flash 1 CNY / 1M tokens 0.2 CNY / 1M tokens 2 CNY / 1M tokens
    Pro 12 CNY / 1M tokens 1 CNY / 1M tokens 24 CNY / 1M tokens

    The material also notes that a certain overseas flagship model’s output pricing is equivalent to over 200 CNY per million tokens, leaving the lightweight tier’s output price more than an order of magnitude lower. What developers should really focus on is not “how many times cheaper” but three structural patterns:

    1. Input and output are priced separately, and output is usually more expensive. This determines where cost concentrates in long-context scenarios: the input side can be optimized heavily through caching, while the output side can only be optimized by controlling generation length.
    2. Cache-hit discounts are very deep. For Flash, a hit costs about one-fifth of a miss; for Pro, about one-twelfth. The higher the tier, the deeper the discount, which shows that higher-value tiers rely more on prefix reuse.
    3. The discount structure is a form of usage guidance. It tells developers clearly: put stable, unchanging content at the front of the request so prefix caching takes effect automatically.

    3. The Engineering Logic Behind Cache-Hit Discounts

    The core premise of prefix caching (also commonly called context caching or prompt caching) is that a model’s processing of an input sequence has reusable prefixes. When the first N tokens of a request are identical to those of prior requests, the computation for that portion can be reused, and only the new part needs to be computed.

    For this mechanism to work reliably, several engineering conditions must be met:

    • Byte-for-byte identical prefixes. Dynamic content such as timestamps, random IDs, and usernames placed at the beginning will invalidate the entire prefix.
    • Order sensitivity. Swapping the order of content is equivalent to a new prefix, and the cache is invalidated.
    • Lifecycle and capacity limits exist. Cache entries expire or get evicted, so hit rates are probabilistic and cannot be relied on as a deterministic capability.
    • Isolation boundaries matter. In multi-tenant environments, cache scope is usually isolated per calling entity and not shared across entities.

    This leads to one hard coding rule: the request body must be “static first, dynamic last.”

    1. [System prompt + tool/function definitions + domain rules] <- stable prefix, aim for 100% hit
    2. [Fixed few-shot examples + document templates] <- semi-stable, updated by version
    3. [Retrieved fragments / user input / conversation history] <- dynamic tail

    A minimal request construction example:

    1. def build_request(static_prefix: str, dynamic_tail: str, question: str):
    2. # static_prefix must be managed by version; any content change is treated as a new prefix
    3. return {
    4. "model": "<model tier identifier>",
    5. "messages": [
    6. {"role": "system", "content": static_prefix},
    7. {"role": "user", "content": f"{dynamic_tail}\n\nQuestion: {question}"},
    8. ],
    9. "max_tokens": 1024, # the first gate for controlling output-side cost
    10. }

    Prefix versioning is a detail many teams overlook. Abstracting the prefix into a hash-tagged immutable object both guarantees hits and makes canary releases and rollbacks easier:

    1. import hashlib
    2. def versioned_prefix(text: str) -> str:
    3. digest = hashlib.sha256(text.encode("utf-8")).hexdigest()[:8]
    4. return f"[prefix:{digest}]\n{text}"

    4. How Typical Scenarios Play Out

    Long documents and contract review. Sending the entire material into the window and limiting output to structured conclusions and clause locations gives high input-side hit rates because the document template is fixed, while strong constraints keep output short. This is one of the scenarios with the highest cache-discount payoff.

    Code repository understanding and intelligent coding. Repository-level context combined with tool definitions placed up front can significantly reduce the retrieval pipeline; tool schemas are naturally stable and make ideal prefix content.

    Multi-turn agents. The system prompt, tool list, and output protocol form a stable prefix, with conversation history appended as a dynamic tail; a sliding window controls tail length to keep long-session costs from spiraling.

    Batch offline processing. High-concurrency batch processing under the same prefix can push hit rates very high, at which point cost is mainly determined by output length, and batch size and concurrency need to be determined through throughput load testing.

    5. A Joint Cost-and-Quality Optimization Checklist

    • Layered context: separate stable, semi-stable, and dynamic layers, controlling update frequency layer by layer.
    • Output budgeting: set max_tokens caps for different tasks, and switch long-output tasks to segmented generation.
    • Observable hit rates: bring the cache-hit ratio, average input length, output length, and per-request cost into logging services and monitoring alerts, with thresholds for abnormal fluctuations.
    • Load test rather than estimate: use real traffic replay to measure hit behavior and latency distribution under different prefix lengths, avoiding theoretical values for capacity planning.
    • Fallback path: switch to the lightweight tier or shorten context under high load, prioritizing availability.
    • Data compliance: define what content may enter context, desensitize sensitive fields before concatenation, and note that cache reuse does not replace access control.

    6. Common Mistakes

    First, treating the cache as a deterministic guarantee and ignoring expiration and eviction, which distorts the cost model. Second, writing dynamic content into the system prompt, which permanently invalidates the prefix. Third, optimizing only the input while ignoring the output, when in long-context scenarios output is often the main expense. Fourth, blindly trying to “stuff all data into the window,” ignoring quality regressions from attention dilution and rising latency.

    7. Conclusion

    Million-token context becoming a default capability, separate input and output pricing, and deep cache-hit discounts all point to the same conclusion: competitiveness in the long-context era lies not in “whether you can fit it in” but in how refined your context engineering and cost engineering are. Restructure requests into a static prefix plus a dynamic tail, bring the prefix under version management, and make hit rate and per-request cost observable metrics, and you can capture the benefits of long context while keeping the bill within a predictable range. If you need logging, monitoring, and elastic compute to carry such long-context applications, you can build on general-purpose capabilities such as container platforms, object storage, and monitoring and alerting from Baidu AI Cloud, keeping the architecture neutral and portable.