LLM API Pricing: Caching, High-Speed Tiers, and Cost Control
This article explains how to estimate large language model API costs, including input and output token pricing, context caching break-even points, when a high-speed tier is worth the premium, generation-to-generation savings, and practical cost-control methods. It also provides a routing decision table and guidance for monitoring and budget alerts.
LLM API Pricing: Caching, High-Speed Tiers, and Cost Control
1. Price Basis and Units
All prices in this article are expressed in CNY per million tokens (MTok). The prices used here are calculation examples only. They demonstrate how to estimate costs and do not represent any provider’s current list prices. Before setting an actual budget, check the provider’s official pricing page and record the date you verified it, because prices can change at any time.
2. Base Billing: Input and Output
LLM API costs are mainly composed of two parts: the input token price and the output token price. The input portion corresponds to the computation required for the model to read context, while the output portion corresponds to the computation required to generate content token by token. Generation happens one token at a time, and each output token depends on the entire preceding sequence, so output prices are usually significantly higher than input prices.
Consider the following example prices:
- Standard version: input 13 CNY/MTok, output 68 CNY/MTok. The output-to-input price ratio is about 5.2:1.
- High-speed version: input 26 CNY/MTok, output 136 CNY/MTok. The ratio remains the same.
To estimate the cost of a single call, first count the input and output tokens, then multiply each by its respective price. For example, if one call has 2K input tokens and 1K output tokens, those amounts are 0.002 MTok and 0.001 MTok, respectively. At standard-version prices, the cost is:
0.002 × 13 + 0.001 × 68 = 0.026 + 0.068 = 0.094 CNY
In other words, 1,000 such calls cost about 94 CNY. This estimation method is simple and sufficient for an initial budget. For a formal budget, replace estimated values with actual token usage from logs.
3. Context Caching: When It Really Saves Money
3.1 How Caching Works
If multiple requests share the same prefix content, such as a system prompt, tool definitions, few-shot examples, or conversation history, the server can reuse previously computed key-value cache and avoid repeated forward computation. From a billing perspective, caching has three prices:
- Cache hit: 1.30 CNY/MTok, about one-tenth of the standard input price.
- Cache write with a 5-minute lifetime: 13.00 CNY/MTok, the same as the standard input price.
- Cache write with a 1-hour lifetime: 26.00 CNY/MTok, twice the standard input price.
3.2 Break-Even for 5-Minute and 1-Hour Writes
Whether caching is worthwhile depends on how many times the same prefix is reused.
For a 5-minute write, the write price is the same as the standard input price. The first request writes the cache, and each subsequent hit is billed at 1.30 CNY/MTok. Let the prefix length be P MTok and the total number of requests be N:
- Without caching: cost = 13 × P × N
- With 5-minute caching: cost = 13 × P + 1.30 × P × (N − 1)
As long as N ≥ 2, caching is cheaper than not caching, provided that the interval between requests does not exceed 5 minutes.
For a 1-hour write, the write price is 13 CNY/MTok higher than the standard input price, and each hit is 11.70 CNY/MTok cheaper than standard input. The cost comparison is:
- Without caching: 13 × P × N
- With 1-hour caching: 26 × P + 1.30 × P × (N − 1)
The calculation shows that when N = 2, caching costs more than not caching; when N = 3, it starts to save money. In other words, a 1-hour write only makes sense if the prefix is used by at least three requests within one hour.
3.3 Boundary Conditions for Caching
The benefit of caching depends on several conditions. If any one of them is not met, costs may increase rather than decrease:
- The prefix must be byte-for-byte identical. If a timestamp or request ID is added to the system prompt, the cache will miss.
- The cache becomes invalid after its lifetime expires. Low-frequency requests are unlikely to hit the cache, and the write cost is wasted.
- Cached content may become stale. If the prompt contains business data that changes, expired content may continue to be used, so an update mechanism is needed.
- Caches should be isolated by tenant or user. Sensitive data from different users should not share the same cache prefix.
Therefore, a caching strategy should first be validated against real logs to determine the hit rate, and only then should you decide on the write duration. Do not simply apply a fixed approach.
4. High-Speed Tier: Is Paying for Low Latency Worth It?
The unit price of the high-speed version is twice that of the standard version. At the token-price level, both versions have the same price on cache hits. Therefore, for workloads with a very high cache hit rate, token costs alone do not require paying extra for the high-speed version.
However, this is only a unit-price comparison. High-speed tiers often also include shorter queue times, more stable time to first token, and clearer timeout guarantees. If the business has an explicit latency SLA—for example, online customer service requires time to first token below a certain number of milliseconds, or a payment confirmation path cannot time out—then the high-speed version may be necessary even with a high cache hit rate. The decision should consider token costs, latency metrics, and the cost of SLA violations together.
For offline batch processing, overnight reports, data labeling, and other tasks that are not sensitive to response time, the standard version is usually the more reasonable choice.
5. Generation Comparison and Savings Estimate
Compare the previous-generation model K3 in the example with the current version K3.1 Pro:
| Comparison Dimension | K3 (Previous Generation) | K3.1 Pro (Current) | Change |
|---|---|---|---|
| Standard input (CNY/MTok) | 20.00 | 13.00 | Down 35% |
| Standard output (CNY/MTok) | 100.00 | 68.00 | Down 32% |
| Cache hit (CNY/MTok) | 2.00 | 1.30 | Down 35% |
| High-speed input (CNY/MTok) | No equivalent version | 26.00 | New tier |
Assume a team makes 100 million tokens of calls per month, or 100 MTok, with input accounting for 70% and output for 30%. The monthly costs for the two generations are:
- K3: 70 × 20 + 30 × 100 = 4,400 CNY
- K3.1 Pro: 70 × 13 + 30 × 68 = 2,950 CNY
The monthly saving is 1,450 CNY, a reduction of about 33%. This result can also be written as 100 × (0.7 × 7 + 0.3 × 32) = 1,450 CNY, where 7 and 32 are the unit-price reductions for input and output, respectively. If the workload has a large number of cache hits, actual savings will also vary because of the price difference on the cached portion.
Note that these savings figures depend on the example prices and the assumed input/output mix. For actual estimates, replace them with official prices and your own traffic structure.
6. Practical Cost Optimization Methods
6.1 Separate Static Prefixes from Dynamic Suffixes
The first step to improving cache hit rates is to adjust prompt structure:
- Static prefix: system prompts, tool definitions, and fixed knowledge summaries should be placed at the very beginning of the request and kept byte-for-byte identical.
- Dynamic suffix: user input, retrieval results, current time, and other content that changes on every request should be placed after the static prefix.
- Session reuse: in multi-turn conversations, include stable historical content as part of the prefix.
Below is a simplified request assembly example:
def build_request(user_input: str, session_id: str) -> dict:prefix = load_static_prompt(session_id) # Read the fixed prefix from the configuration center and keep it byte-identicalreturn {"system": prefix, # Put the static part first"user": user_input, # Put the dynamic part after it"cache_control": {"ttl": "1h"}, # Field names should follow the provider's documentation}
Before launch, use the following checklist to confirm each item:
- How many tokens is the prefix, and is it long enough to be worth caching?
- What is the average reuse count for the same prefix, and does it cover the break-even count?
- Does the lifetime (TTL) match the request interval?
- When the prefix changes, how is the old cache invalidated?
- What is the ratio of daily cache-hit tokens to total input tokens?
6.2 Traffic Tiering and Version Routing
When using both the standard and high-speed versions, you can set routing rules at the API gateway layer without modifying business code. For tiering, use observable decision metrics rather than dividing only by business type:
- L1 (high priority): route to the high-speed version. Conditions include: the user belongs to a paid tier, and the endpoint’s P95 latency target is below an agreed value, or the request belongs to a core path such as payment confirmation or real-time risk control.
- L2 (medium priority): route to the standard version. Conditions include: a looser latency SLO and a lower per-request cost ceiling.
- L3 (low priority): asynchronous tasks are routed to the standard version and scheduled in batch windows.
The routing layer should also monitor error rates. If the high-speed version’s error rate exceeds a threshold, some requests can temporarily be switched back to the standard version, but note that doing so may violate an SLA.
Routing-rule thresholds should be determined from your own data—for example, using P95 latency and user distribution from the past two weeks—rather than directly adopting someone else’s numbers.
6.3 Choosing Cache Write Duration
Choose between 5-minute and 1-hour writes as follows:
- Requests for the same prefix are concentrated within a few minutes and data changes frequently: choose a 5-minute write. Because the write price is the same as standard input, there is almost no additional risk.
- The same prefix appears repeatedly in longer sessions, and request intervals often exceed 5 minutes: choose a 1-hour write, but first confirm that the average reuse count is at least 3.
- The prefix is almost never reused: do not enable cache writes; bill directly at standard input.
Do not recommend one duration unconditionally. Each choice needs to be validated with real reuse counts and request intervals.
6.4 Allocate Models by Task Complexity
Not every task requires the strongest model. Text classification, keyword extraction, format conversion, and similar tasks can usually be handled by smaller, cheaper models. In practice, you can first use a small model for classification and route only complex requests to a large model. This approach requires validating the small model’s accuracy on the target task and keeping manual spot checks.
7. Selection Decision Table
The table below provides a reference approach. The thresholds are only starting points and should be adjusted based on your own traffic and business data.
| Scenario | Traffic Scale | Latency Requirement | Cache Hit Rate | Budget Constraint | Recommended Approach |
|---|---|---|---|---|---|
| Prototype validation | Low | Loose | Low | Tight | Standard version; no cache optimization yet |
| Early product | Medium | Medium | Medium | Medium | Standard version; static prefix plus 5-minute cache |
| Scaled business | High | Strict | High | Sufficient | Hybrid routing: high-speed version for core paths, standard version for the rest |
| Offline batch processing | High | Not sensitive | Not applicable | Strict | Standard version; asynchronous batch execution |
When selecting, focus on two points: first, whether latency requirements are written into an SLA; second, whether the cache hit rate can reliably reach the break-even threshold on real traffic. If these two points are unclear, run the standard version for a period of time, collect logs, and then decide whether to upgrade.
8. Cost Monitoring and Budget Alerts
Without monitoring, cost optimization is impossible. For each call, record fields such as model version, input token count, output token count, cache-hit token count, time to first token, and per-request details.
