What Prompt Caching and Tiered Pricing Mean for LLM API Cost Optimization
A recent price adjustment by a major cloud provider cut flagship LLM API input/output token prices by roughly 20%, while cached input tokens dropped by about 60%. This article explains the billing model behind prompt caching, why the discount structure matters more than the discount size, and practical engineering techniques—prompt layering, tiered model routing, batch processing, and FinOps observability—to capture non-linear cost savings.
What Prompt Caching and Tiered Pricing Mean for LLM API Cost Optimization
1. Background: A Typical Pricing Restructure
A major cloud provider recently restructured pricing for its flagship LLM API series: input and output token prices for the standard tier dropped roughly 20% compared to the previous flagship generation, while cached input token prices fell by about 60%. Higher-capability models in the same series kept their previous pricing unchanged.
The detail developers should focus on is not the price cut itself, but the fact that the discount is unevenly distributed. A 20% reduction on input/output is a linear gain; a 60% reduction on cached input is a structural one—it signals that the vendor is using pricing to steer callers toward restructuring how they build requests. Understanding this is more valuable than memorizing any specific number.
Note that billing rules and discount structures vary widely across vendors and models. This article cites no specific prices and only discusses general billing models and optimization methods.
2. First, Clarify the Billing Model
Token billing for mainstream LLM APIs is typically split into four categories:
| Billing Item | Meaning | Optimization Potential |
|---|---|---|
| Input tokens | Request portions not served by cache | Medium |
| Output tokens | Content generated by the model | Medium (limited by task nature) |
| Cached input tokens | Input portions hitting the prefix cache | High |
| Cache write/storage | Some schemes charge extra for creating caches | Evaluate case by case |
The key mechanism is prefix caching: when multiple requests share an identical prompt prefix, the server can reuse precomputed intermediate states, and those tokens are billed at the cache price—usually significantly lower than the standard input price.
This leads to an important conclusion: cost optimization is not about “writing shorter prompts,” but about making identical content appear at the front and stay stable over time. Caches match on the longest common prefix. Once anything changes within the prefix, everything after it falls back to standard input billing.
3. Practice 1: Prompt Layering and Prefix Stabilization
Structure prompts into three segments—“stable,” “semi-stable,” and “dynamic”—in that order, which must not be reversed:
[Stable] System role, output format rules, glossary, safety policy ← rarely changes, highest cache benefit[Semi-stable] Domain knowledge snippets, few-shot examples ← updated per version[Dynamic] User question, retrieval results, timestamps, session IDs ← changes every call, place last
A common anti-pattern is putting timestamps, random IDs, or retrieval snippets at the beginning of the prompt, which drives cache hit rates toward zero. Illustrative code:
SYSTEM_PROMPT = "You are a data analysis assistant. Output must be JSON. Glossary: ..." # version-controlleddef build_messages(query: str, retrieved: list[str]) -> list[dict]:# Dynamic content always goes last to keep the prefix stabledynamic = f"Retrieved snippets:\n{chr(10).join(retrieved)}\n\nQuestion: {query}"return [{"role": "system", "content": SYSTEM_PROMPT},{"role": "user", "content": dynamic},]
Supporting engineering practices include: keeping prompts under version control with staged rollouts; banning uncontrolled variables in string concatenation; and unit-testing templates to assert that the hash of the first N characters stays unchanged.
4. Practice 2: Tiered Routing and Model Selection
Unchanged pricing for higher-capability tiers shows that the “capability premium” still exists. A sound approach is a routing layer that dispatches by task difficulty:
- Hard tasks (complex reasoning, long-form generation) go to the flagship tier;
- Easy-to-medium tasks (classification, extraction, rewriting, formatting) go to a lightweight tier;
- Rule-solvable tasks don’t call the model at all—handle them with traditional code or regex.
Routing decisions can use a lightweight classifier, heuristics (input length, presence of code blocks), or confidence-based fallback: try the small model first and escalate when confidence is insufficient. For example:
def route(task):if task.kind in {"format", "extract"}:return "light"if task.estimated_difficulty > 0.7:return "flagship"return "standard"
5. Practice 3: Batching, Streaming, and Output Constraints
- Batch processing: if the service offers an asynchronous batch channel, it usually comes with an extra discount and suits offline workloads (log analysis, bulk tagging).
- Output constraints: use structured output / JSON Schema to enforce formats, reducing invalid generations and retries—directly cutting output tokens.
- Tighten max_tokens: set per-task ceilings to prevent unusually long generations from bad inputs.
- Streaming: improves perceived latency but saves no tokens; it shouldn’t be marketed as a cost-saving measure.
- Retry governance: exponential backoff plus idempotency keys to prevent bills from ballooning during outages.
6. Practice 4: Observability and a FinOps Loop
No metrics, no optimization. Track the following and correlate them with business dimensions:
- Cache hit rate = cached input tokens / total input tokens;
- Average tokens per request and cost per business operation;
- Traffic share per model tier and escalation rate;
- Failure, retry, and timeout rates.
cost ≈ input_tokens × input_price + output_tokens × output_price+ cached_input_tokens × cache_price + cache_writes × write_price
Tag costs by tenant / business line / endpoint, and set budget alerts and quotas to close the loop of “monitor → attribute → optimize → verify.” Cache write fees versus hit gains must be balanced empirically: long prefixes reused infrequently may cost more than they save.
7. Migration and Risk Control
When prices and models change, keep in mind: a lower unit price does not guarantee a lower bill—volume growth often offsets the savings. Don’t hardcode model names in prompts; manage them via a configuration center. Retain A/B testing and rollback capability. Verify cache consistency, and guard against cross-session cache leakage—requests containing sensitive data must confirm the cache isolation policy.
8. Conclusion
The real signal in this round of price adjustments is that billing granularity is shifting from “token volume” to “token position and reuse efficiency.” Developers should treat prompts as engineering assets that need version control and performance optimization, and combine tiered routing, batching, and FinOps measurement to capture non-linear savings during a period of falling unit prices. If your organization uses model services from platforms such as Baidu AI Cloud, the same advice applies: model costs with a general billing framework and let measured data drive optimization, rather than relying on any single discount expectation.
