LLM API Pricing: Context Caching, Subscription Plans, and Real-World Costs
Context caching and subscription plans can reduce LLM API spending, but headline token prices rarely tell the full story. This article examines how cached input, uncached input, output tokens, and off-peak pricing affect total costs, compares illustrative usage scenarios, and outlines practical approaches to prompt design, workload scheduling, and conversation management.
As more businesses and developers integrate large language models (LLMs) into production applications, API costs become an increasingly important engineering concern. A pricing model that looks inexpensive during testing may become costly as request volumes and conversation lengths grow.
Context caching and subscription plans offer ways to reduce these costs. However, evaluating their value requires more than comparing the lowest advertised price per token. Developers and architects need to understand how billing rules interact with their actual workloads.
This article examines LLM API caching and pricing, compares illustrative cost scenarios, and explores architectural practices for controlling spending.
1. Understanding LLM API Pricing and Context Caching
Traditional LLM API pricing separates usage into two main categories: input tokens and output tokens. Processing input context can require substantial computation, especially when requests contain long system prompts, reference documents, or conversation histories.
To reduce repeated processing, many model providers support context caching.
When multiple requests share the same initial context, the service can reuse cached computation for that prefix. Common examples include:
- System instructions
- Fixed knowledge-base excerpts
- Repeated examples
- Shared conversation history
If a later request matches a cached prefix, the matching input tokens may be billed at a substantially lower rate—sometimes a fraction of the standard input price.
Some providers also distinguish between peak and off-peak pricing. Requests processed during periods of lower demand may qualify for lower rates. For workloads that do not require immediate results, this creates an opportunity to reduce spending through scheduling.
The practical takeaway is that total cost depends on several variables: cached input volume, uncached input volume, output volume, and the pricing window in which requests run.
2. How Cache Usage Changes Total Cost
Consider two hypothetical LLM API services:
| Service | Illustrative cached-input price |
|---|---|
| Model A: a recently released high-performance model | CNY 0.115 per million tokens |
| Model B: a cost-oriented model | CNY 0.05 per million tokens during off-peak hours |
All monetary examples below remain in Chinese yuan (CNY), matching the source figures.
At first glance, Model B appears considerably cheaper: its off-peak cached-input rate is less than half Model A’s rate. But cached-input pricing alone does not determine the bill.
The following scenarios illustrate how the balance between cached input, uncached input, and output can change the result. The total costs are illustrative figures; the complete uncached-input and output rate schedules are not provided, so they cannot be independently reconstructed from the cached-input prices alone.
Scenario 1: Very High Cached-Token Share—98%
Assume a workload with highly stable prefixes. Of its total token volume:
- 98% consists of cached input.
- 1.5% consists of uncached input.
- 0.5% consists of output.
Here, the 98% figure describes cached tokens as a share of all tokens, rather than the percentage of requests that hit the cache.
For a total volume of 100 million tokens, the illustrative costs are:
| Service | Total cost per 100 million tokens |
|---|---|
| Model A | CNY 12.57 |
| Model B, using off-peak pricing | CNY 9.40 |
Under these assumptions, Model B’s lower off-peak cached-input price produces the lower overall cost.
Scenario 2: Lower Cached-Token Share—95%
In production, changing user inputs and adjustments to system prompts can make it difficult to maintain a 98% cached-token share.
Now assume that cached input accounts for 95% of total tokens, with the remaining input and output proportions adjusted accordingly. The illustrative costs for the same 100 million tokens become:
| Service | Total cost per 100 million tokens |
|---|---|
| Model A | CNY 14.92 |
| Model B, using off-peak pricing | CNY 18.25 |
The ranking reverses. As uncached input increases, Model B’s higher uncached-input pricing outweighs its advantage on cached tokens. Model A’s more balanced pricing makes it less expensive in this scenario.
These examples show why API selection should not depend on the lowest advertised token rate. A useful comparison must reflect the workload’s actual token distribution, including how much input can be cached and how much output the application generates.
3. Subscription Plans vs. Pay-as-You-Go APIs
Alongside usage-based APIs, some providers offer monthly subscription plans for frequent development use. These may include entry-level, professional, and flagship tiers, each with usage allowances and potentially different peak and off-peak rules.
In one illustrative plan structure, peak hours are defined as Monday through Friday, from 14:00 to 18:00, according to the provider’s billing schedule. Only those four hours on each weekday fall into the peak window.
Under an idealized 98% cached-token share and off-peak usage, the example allowances translate as follows:
| Subscription tier | Approximate weekly token allowance | Illustrative pay-as-you-go API value |
|---|---|---|
| Basic | 317 million tokens | CNY 160 |
| Professional | 1.90 billion tokens | CNY 955 |
| Flagship | 4.433 billion tokens | CNY 2,229 |
These API-equivalent values depend on the assumed usage mix and pricing conditions. They should not be treated as fixed cash values for the allowances.
The example comparison places subscription pricing at roughly 50%–70% of the equivalent pay-as-you-go API cost. However, the subscription fees and full billing details are not supplied here, so that estimate remains dependent on the underlying plan assumptions.
For development teams with steady, high-volume demand, a suitable subscription can make spending more predictable. Its value still depends on whether the team uses the allowance consistently and whether its workloads fit the plan’s billing windows and usage rules.
4. Architectural Practices for Reducing LLM Costs
Once the pricing model is understood, application architecture can help capture the benefits of caching and off-peak processing.
The following practices can be implemented using cloud-native infrastructure. Baidu AI Cloud services are examples referenced here; their suitability and availability should be checked for the intended deployment environment.
4.1 Structure Prompts Around a Stable Prefix
Place content that changes frequently near the end of the prompt. Keep reusable material at the beginning, including:
- System instructions
- Stable background information
- Few-shot examples
This layout improves the opportunity for later requests to reuse an identical prefix.
Static knowledge-base material can be stored in object storage, such as Baidu Object Storage (BOS), and retrieved before an LLM request is assembled. However, storage alone does not ensure cache hits: the resulting prompt prefix must remain consistent.
When vector retrieval is used, changes in the retrieved passages or their order can change the prefix. The key objective is therefore to preserve identical reusable content wherever possible, rather than assuming that all knowledge-base requests will automatically benefit from caching.
4.2 Schedule Batch Work During Off-Peak Hours
Workloads such as log analysis and bulk document summarization often do not need immediate responses. These are natural candidates for off-peak scheduling.
For example, batch inference jobs can run on a container platform such as Baidu AI Cloud CCE. A CronJob can schedule processing within the provider’s applicable off-peak window—for example, between 02:00 and 06:00 where that period qualifies for discounted pricing.
Container-platform scaling can also reduce supporting infrastructure costs by scaling down resources when they are idle.
This approach addresses two separate cost components:
- The LLM API bill, through eligible off-peak pricing
- The application’s infrastructure bill, through reduced idle capacity
4.3 Trim and Summarize Conversation History
Appending an entire conversation to every request increases input-token volume over time. Changes to earlier history can also disrupt prefix reuse.
An API gateway middleware layer can apply a conversation-length threshold. Once the threshold is reached, a smaller model can summarize older messages, replacing a long history with a fixed-length summary.
This helps control context growth and can preserve a more stable reusable prefix when the summary remains unchanged. Updating the summary changes that portion of the context, so summarization should not be treated as a guarantee of cache stability.
The goal is to balance context size, continuity, and the opportunities for reuse.
Conclusion
LLM API cost optimization is not simply a matter of choosing the lowest price per million tokens. Cached-input rates, uncached-input charges, output volume, peak and off-peak schedules, and subscription allowances all influence the final bill.
The illustrative comparisons show how a small change in cached-token share can reverse which model is cheaper. Subscription plans can offer additional savings and spending predictability, but only when their assumptions match actual usage.
Stable prompt prefixes, appropriately scheduled batch jobs, and controlled conversation histories provide practical ways to manage costs. Combined with workload-specific cost calculations, these practices help teams use LLM capabilities without losing control of operating expenses.
