How to Cut LLM Costs: Billing Models and Prompt Caching in Practice
This guide explains how to compare LLM pricing across platforms, choose between subscription plans and pay-as-you-go API billing, estimate the cost impact of prompt caching, and apply architecture practices such as model routing and context compression to control spending.
Cost in LLM applications comes mainly from compute. Choosing the right billing model, using prompt caching well, and controlling context length can usually lower the bill noticeably. However, pricing rules differ widely between platforms. This article does not assume a single industry standard. Instead, it provides a method you can apply to any platform.
1. Confirm the Billing Unit of Each Platform
Platforms calculate charges in different ways. Two common models exist:
- Token-based billing: Input and output are priced separately, usually per million tokens.
- Credit-based billing: The platform first converts each call into internal credits, then deducts credits from the account. The conversion ratio between credits and tokens is set by the platform and may change by model or feature.
Before comparing prices, convert all unit prices to the same basis. Comparing list prices directly can lead to wrong conclusions.
Output token prices are usually higher than input token prices. The reason is that generation decodes one token at a time in an autoregressive manner. For each new token, the model must read the preceding context state, so it cannot compute in parallel the way it processes input. The exact price multiple varies by platform and model, so refer to each platform’s published price list.
Consider the following example. Suppose a platform charges 1 yuan per million input tokens and 4 yuan per million output tokens. A request with 2,000 input tokens and 500 output tokens costs:
2000 × 1 / 1,000,000 + 500 × 4 / 1,000,000 = 0.002 + 0.002 = 0.004 yuan
This example only illustrates the calculation method. The numbers are not the real prices of any platform.
Model size also affects unit price. Larger models usually cost more per token, but no general ratio applies. Check the price of each model individually.
2. Subscription Plans Versus Pay-as-You-Go API Billing
Subscription plans and pay-as-you-go API billing each suit different scenarios. To compare them, fill in the table below and measure both options with the same metrics.
| Platform | Billing unit | Input/output unit price | Cache write/read price | Plan quota (time window/period) | Suitable scenario | Main risk |
|---|---|---|---|---|---|---|
| Platform A | Tokens or credits | See the official website | See the official website | See the official website | High-frequency, stable calls | Rate limiting |
| Platform B | Tokens or credits | See the official website | See the official website | See the official website | Workloads with clear peaks | Opaque quota |
Two points need attention when filling in the table. First, the nominal plan quota may differ from the actual usable quota. Platform resource scheduling, model load, and time of day can all affect real capacity. Public materials usually do not explain the reasons, so measured results should be the basis for comparison. Second, plans often have both a time-window limit (for example, a cap within a few hours) and a total periodic quota. These two constraints work differently, so verify each one separately.
Measuring actual capacity is straightforward. During a typical time window, send real business requests until the quota is used up. Record the number of completed requests and the total tokens consumed. Then calculate the effective unit price:
Effective unit price = plan price ÷ total tokens actually completed within the window
Compare this value with the pay-as-you-go API unit price to judge whether the plan is worth it. When testing, cover both weekday peak hours and nighttime off-peak hours. Rate limits and response speed can vary significantly across these periods.
Use the following criteria to choose a billing model:
- Steady, high-frequency requests: Calculate the total monthly cost and compare the plan price with pay-as-you-go pricing.
- Clear peaks and troughs in traffic: Beyond total quota, pay attention to concurrency limits and rate-limiting policies. If peak-hour latency requirements are strict, a higher-tier plan may be necessary.
- Intermittent processing of long texts: Pay-as-you-go billing is usually more flexible. It avoids wasting quota during idle periods.
3. Prompt Caching: Conditions and Cost Estimation
In long-context, multi-turn conversation, and retrieval-augmented generation (RAG) scenarios, system prompts, role definitions, and knowledge base content often repeat in every request. If the key-value (KV) cache for these fixed prefixes is recomputed from scratch each time, compute resources are heavily consumed.
The basic idea of prompt caching is as follows. When a prefix is sent for the first time, the server stores its intermediate computation results. If a later request contains the exact same prefix and the cache is still valid, the stored results are reused, and the computation for that part is skipped.
Caching has several requirements:
- The prefix must match exactly: Even one extra space or a timestamp can cause a cache miss.
- A minimum length usually applies: Very short prefixes may not be cached.
- A time-to-live (TTL) applies: After the TTL expires, the cache becomes invalid and must be written again. TTL and renewal rules differ across platforms.
- Isolation granularity varies: Some platforms isolate caches by account, while others isolate by organization or project. Verify which applies to your platform.
On pay-as-you-go API billing, platforms commonly charge slightly more for cache writes than for regular input, and noticeably less for cache reads. The following estimate uses hypothetical rates for illustration only:
- Regular input price: p
- Cache write price: 1.25p
- Cache read price: 0.1p
- Fixed prefix length: 20,000 tokens
- Daily volume: 1,000 requests, with 900 cache hits and 100 misses (each miss rewrites the cache)
Without caching, the daily input cost is:
20,000 × 1,000 × p = 2×10⁷p
With caching, the daily cost is the sum of two parts:
- Hit portion: 20,000 × 900 × 0.1p = 1.8×10⁶p
- Miss portion: 20,000 × 100 × 1.25p = 2.5×10⁶p
The total is 4.3×10⁶p, which is about 21.5% of the cost without caching. This result excludes cache storage fees and output costs. Include both in a real estimate.
On some platforms’ subscription plans, cache reads may not consume quota, or they may count at a lower rate. These policies can change at any time, and they may apply only to specific models or plans. Treating them as a long-term commitment carries risk, so check platform announcements regularly.
4. Caching Practice Checklist
- Stabilize the prefix: Place the system prompt and fixed knowledge at the start of each request. Put user input and dynamic content at the end.
- Move dynamic fields out of the prefix: Keep timestamps, request IDs, random numbers, and similar values out of the prefix.
- Match request intervals to the TTL: If the gap between two requests exceeds the TTL, the cache expires. Adjust the caching strategy to fit the request rhythm of your workload.
- Monitor hit rates: Track hit rates separately for each model and business line. A sudden drop usually means the prefix was changed unintentionally.
- Protect data privacy: Cached content is stored on the provider’s side. Confirm the platform’s data retention period, encryption method, and isolation policy. Do not share caches across users when the context contains sensitive personal information.
- Manage versions: Cached content usually cannot be reused after a model upgrade. Allow time and budget for rebuilding caches when you launch a new model.
5. Architecture for Cost Optimization
Choosing the right plan and enabling caching is not enough on its own. In enterprise settings, you can build a cost control system in the following ways:
- Model routing: Set routing rules at the application gateway. Send simple tasks, such as intent recognition, format validation, and keyword extraction, to lightweight models. Send complex reasoning and code generation to more capable models. Validate routing rules against an offline evaluation set. This prevents simple tasks from reaching heavy models and keeps complex tasks from being handled by light models at a loss of quality.
- Context compression: Apply a sliding window to conversation history, or use a summarization model to compress older content. Compression may lose key information, so keep the user’s explicit constraints, important entities, and key decisions. Compare samples before and after compression.
- Batch and asynchronous processing: For tasks that do not need real-time responses, queue them with a message queue. Merge requests when the platform offers a batch interface. Check the platform documentation to see whether batch interfaces offer discounts and how large those discounts are.
- Infrastructure: Standard cloud-native components are sufficient. Object storage can hold prompt templates and their versions, message queues absorb traffic spikes, and container platforms scale automatically with load. These components do not depend on a specific vendor, so choose them based on what your team already uses.
- Cost monitoring and alerts: Set daily budgets and alert thresholds by model, business line, and user. Unexpected costs often come from loops of repeated calls, unbounded context growth, or a feature that is triggered too frequently.
6. Common Errors and Troubleshooting
- Cache misses: First check the prefix for small changes such as spaces, line breaks, or timestamps. Then check whether the interval between requests exceeds the TTL and whether the model version has changed.
- Plan rate limiting: If you see rate-limit errors, check usage in the current time window first. You can spread requests over time, or assess whether a plan upgrade is needed.
- Routing errors: Classification rules for light and heavy models may label complex questions as simple. Regularly sample routing results against the evaluation set, and track the share of requests that were downgraded.
- Information loss from compression: If the model starts forgetting constraints the user gave earlier, the compression strategy is probably removing key content. Adjust the retention rules and add checks for critical fields.
- Fallback plan: When the primary model is unavailable or costs exceed the budget, switch automatically to a backup model. Log each downgrade for later analysis.
Conclusion
Billing rules, plan structures, and caching policies differ across platforms, and no fixed answer fits every scenario. A safer approach is to measure costs with real traffic first, then decide whether to use subscription plans, pay-as-you-go billing, or a combination of both. Enable caching and monitoring at the same time. Pricing and policies change quickly, so always check the latest official documentation from each platform.
