Tiered LLM API Pricing and Cache Optimization in Practice
This article explains how tiered token pricing changes the cost structure of LLM API calls. It covers cost modeling with cached and uncached input tokens, prefix design for higher cache hit rates, model routing across model tiers, and observability and budget controls. It also includes a pseudocode example and an implementation checklist.
As LLM services move from single-model calls to parallel use of multiple model lines, pricing is becoming more granular. Instead of the simple two-part model of “input tokens plus output tokens,” many providers now separate standard input, cached input, and output, and apply different pricing to different model lines. For developers, this means cost optimization cannot stop at “writing shorter prompts.” It requires systematic work on request structure, cache design, model routing, cost attribution, and budget governance.
This article covers general technical issues under tiered pricing. It discusses how to build a cost model, how to improve cache hit rates, how to route requests across model tiers, and how to use observability to put these optimizations into practice.
1. Understand the Billing Dimensions: Cost Depends on Three Token Types
Under tiered pricing, the cost of a single call can usually be broken into three parts:
- Standard input tokens: Context that is not reused from the cache. This includes system prompts, tool descriptions, few-shot examples, retrieved documents, and the user’s question.
- Cached input tokens: The part of the request that shares a stable prefix with earlier requests and is reused from the server-side cache. These tokens typically cost significantly less than standard input tokens.
- Output tokens: The content the model generates. In most cases, output tokens cost more than input tokens, so controlling output length is often the main focus of cost optimization.
The key point is not to memorize specific prices. It is to understand how the pricing structure affects architecture. If the discount on cached input is large enough, reusing a stable prefix becomes a cost optimization, not just a performance optimization. If output tokens are expensive, structured output, maximum length limits, summary-style answers, and staged generation become more valuable. If prices differ widely across model lines, routing requests by task difficulty directly affects unit economics.
2. Build a Cost Model: Turn “Feels Cheap” Into “Measurable”
Build a cost model during system design. Let p_in be the standard input price, p_cache the cached input price, and p_out the output price. Let u_in, u_cache, and u_out be the token usage for one call. The cost of that call can then be written as:
cost = u_in * p_in + u_cache * p_cache + u_out * p_out
Let the total input be u_total = u_in + u_cache, and the cache hit rate be r = u_cache / u_total. The effective input price is then:
effective_input_price = (1 - r) * p_in + r * p_cache
This formula has two direct uses. First, it estimates how much cost can drop when the cache hit rate improves. Second, it helps set priorities. When output cost dominates, reduce output length and unnecessary generation first. When input cost dominates, prioritize prefix stabilization, context trimming, and retrieval result deduplication.
When deploying at enterprise scale, also attribute costs by tenant, feature module, model line, and request type. Otherwise, the total bill only shows that spending increased, not where. At a minimum, record the following fields: input token breakdown, output tokens, cached token volume, model line routing result, request latency, retry count, business feature identifier, and tenant identifier. If logs contain user content, apply redaction and collect only the minimum data needed.
3. Optimize Cache Hits: A Stable Prefix Is the Core
Cache hits usually depend on the prefix of a request staying stable. If the system prompt, tool definitions, example format, version number, or timestamp changes with every request, the cache is hard to reuse. Consider these design practices:
- Fix system prompts and tool descriptions: Place content that does not change per request at the beginning, and put dynamic context at the end.
- Version prompt templates: Use explicit version numbers for prompt templates. Roll out changes gradually so that unintended edits do not break the cache.
- Move dynamic content to the end: Place the user’s question, real-time retrieval results, and temporary parameters after the stable prefix whenever possible.
- Reduce random noise: Do not insert timestamps, random IDs, or meaningless ordering fields into the prefix.
- Isolate tenants: Design cache keys with tenant and permission boundaries in mind. Reuse must not expose data across users.
- Set expiration policies: For time-sensitive content such as policies, prices, or inventory, set appropriate refresh intervals to avoid stale cache entries.
Caching should not mean caching everything. Reusing a stable prefix requires that the content can be shared and does not expose sensitive information. For context that contains personal data, keys, or internal policies, apply redaction, splitting, or isolation first.
4. Model Routing: Balance Quality, Latency, and Cost With Tiered Strategies
Tasks differ widely in the model capability they need. You can build a lightweight routing layer. Simple classification, extraction, and formatting tasks go to lower-cost model lines. Complex reasoning, long-document analysis, and critical decisions go to higher-capability model lines. For failed requests, set limited retries and fallback strategies. Routing decisions can be based on task type, input length, historical success rate, business priority, and budget thresholds.
At the same time, avoid downgrading every request in the same way. Any downgrade strategy should come with quality evaluation. For example, apply rule-based checks to key fields, validate structured output against a schema, and send low-confidence results to human review or a second call. Only when quality thresholds and cost targets are both part of routing can you avoid saving money on calls while creating more rework.
5. Observability and Budget Governance
Instrument the call chain to record token breakdowns and cost estimates. Connect these records to a general-purpose logging service and monitoring and alerting tools. Build budget dashboards by day, by hour, and by tenant. Alert rules can cover sudden cost increases for a single tenant, a drop in cache hit rate, abnormal output length, a higher retry rate, and a model line whose share of total cost is too high. Keep sampled logs for abnormal requests so you can trace problems caused by prompt template changes or routing policies.
6. Pseudocode Example: Request Construction and Cost Estimation
function build_request(stable_prefix, dynamic_context, question):return {"prefix": stable_prefix, // System prompt, tool descriptions, fixed examples"context": dynamic_context, // Retrieval results, temporary parameters"question": question}function estimate_cost(usage, price):return usage.uncached_input * price.input+ usage.cached_input * price.cache+ usage.output * price.outputfunction effective_input_price(hit_rate, price):return (1 - hit_rate) * price.input + hit_rate * price.cache
Before launch, use replays of historical requests to estimate the benefit of optimization. First, measure the current cache hit rate and the share of output tokens. Then simulate how costs change after prefix stabilization, context trimming, and model routing. Rank optimizations by benefit, risk, and implementation cost, and roll them out in small gradual steps.
7. Implementation Checklist
- Inventory existing request templates and identify unstable prefixes and repeated context.
- Set up token breakdown and cost attribution fields. Measure first, then optimize.
- Define a stable prefix standard, including clear boundaries for dynamic content and template version management.
- Configure model routing and fallback strategies for different tasks, and add quality checks.
- Set up budget alerts and cache hit rate monitoring, and review unusual changes on an ongoing basis.
- Redact and isolate sensitive context so that cache reuse does not expose data across boundaries.
Tiered pricing is more than a change on the bill. It signals that application architecture needs to become more fine-grained. By combining cost modeling, cache design, model routing, and observability, developers can balance quality, latency, and cost in a sustainable way.
