Prompt Caching in LLM APIs
Published: 2026-06-04 08:44:47 · LLM Gateway Daily · ollama openai compatible api setup · 8 min read
Prompt Caching in LLM APIs: A Practical Pricing Comparison for 2026
When you send a long system prompt or a massive document to an LLM API, you are often paying to process that same text over and over again. Prompt caching is the mechanism that stores these repeated input tokens so that only the first request incurs the full cost, while subsequent requests are billed at a steeply reduced rate. This feature has become a critical lever for controlling costs in production AI applications, especially when you are using lengthy context windows that stretch into tens of thousands of tokens. The core tradeoff is straightforward: you trade a small upfront cache write cost for significantly cheaper cache read costs on every repeat call, but the exact pricing structures vary wildly between providers.
OpenAI introduced prompt caching for their GPT-4o and GPT-4o mini models in late 2024, and by 2026 it is a mature offering. Their approach requires your prompt to be at least 1,024 tokens long to qualify, and the cache is automatically managed on their side. The discount for a cache hit is roughly 50% off the input token price, which is substantial but not the deepest discount available. For example, GPT-4o input tokens normally cost $2.50 per million, while cached input tokens drop to $1.25 per million. OpenAI also supports caching across multiple turns in a conversation, which is excellent for chat applications where you reuse a system prompt alongside varying user messages. However, the cache has a time-to-live that resets with each hit, so infrequently used prompts may not benefit.

Anthropic’s Claude models offer a more aggressive caching model that has become a favorite among developers building agentic workflows. Claude’s prompt caching works with any prompt length, but you explicitly mark which portion of the prompt should be cached using a special API parameter called `cache_control`. This gives you fine-grained control over what gets stored, which is ideal when you have a large knowledge base embedded in the system prompt but want the user query to remain uncached. The pricing is notably generous: Claude 3.5 Sonnet’s cache write cost is about 25% cheaper than the base input cost, but the cache read cost can be as low as 10% of the original input price. For instance, base input tokens at $3.00 per million can be read from cache at just $0.30 per million. This creates a powerful economic incentive to design your prompts around reusable, static content rather than generating unique long contexts on every call.
Google Gemini, meanwhile, takes a different approach with its context caching feature. Gemini allows you to create named cache entries that persist for up to 24 hours, and you pay a storage fee per million tokens per hour in addition to a discounted input token rate. This model is more similar to a database than a simple read discount. For Gemini 1.5 Pro, the cached input token price is roughly 75% off the standard rate, but you also pay around $0.50 per million tokens per hour for storage. This is advantageous if you have a very large, static context that you will query hundreds of times within a short window, because the storage cost is dwarfed by the savings on input tokens. For use cases like customer support chatbots that reuse a product catalog, Gemini’s model can be dramatically cheaper than per-request caching.
For developers who need to manage multiple providers without rewriting their codebase, services like TokenMix.ai provide a unified API that abstracts away these pricing differences. TokenMix.ai offers access to 171 AI models from 14 providers behind a single OpenAI-compatible endpoint, which means you can drop in a replacement for your existing OpenAI SDK code and instantly route requests to Anthropic, Google, or others. Their pay-as-you-go pricing requires no monthly subscription, and they include automatic provider failover and routing, so if one model’s cache is cold or too expensive for a given prompt, traffic can shift to a more cost-effective provider. Alternatives like OpenRouter, LiteLLM, and Portkey also offer similar aggregation and caching orchestration, so the key is to pick one that matches your team’s preferred integration depth and monitoring capabilities.
Real-world pricing dynamics become clear when you compare a typical use case: a legal document analysis tool that sends a 50,000-token contract to an LLM for each user query. Without caching, each call to OpenAI GPT-4o would cost $0.125 for the input alone. With caching, the first call costs the same, but subsequent calls drop to $0.0625 per input. Over a hundred queries, that saves $6.25. Now consider the same workload on Anthropic Claude 3.5 Sonnet: the first call costs $0.15, but cached reads cost only $0.015 per call, saving $13.50 over a hundred queries. If you use Google Gemini 1.5 Pro with a 24-hour cache, the first call might be $0.12, and cached reads drop to $0.03, plus $0.025 per hour for storage. Over a 10-hour window with a hundred queries, the total cost is about $3.55, compared to $12.00 without caching. The winner depends on your traffic pattern: intermittent bursts favor Claude’s aggressive read discount, while sustained high volume favors Gemini’s storage-based model.
One subtle but important consideration is cache invalidation and prompt variability. If your system prompt changes frequently, caching is useless because the cache key is based on the exact token sequence. This is where engineering decisions around prompt engineering intersect with cost. You should design your prompts to isolate the static parts—such as role instructions and background documents—from the dynamic parts like user questions. Both OpenAI and Anthropic allow you to prefix static content in a way that maximizes cache hits, while Google Gemini requires you to explicitly create and manage cache entries. For developers using a routing layer like TokenMix.ai, you can centrally define caching policies that apply across providers, which reduces the cognitive load of remembering each API’s quirks. Portkey offers similar caching orchestration with observability dashboards to show your cache hit rates in real time.
The bottom line for 2026 is that prompt caching is no longer an optional optimization—it is a baseline requirement for any production LLM application that processes more than a few dozen requests per day. The providers have made their pricing public and competitive, but the real savings come from understanding the operational differences. OpenAI’s hands-off caching is easiest to implement but offers the smallest discount. Anthropic’s manual caching rewards prompt engineering and yields the largest read discounts. Google Gemini’s storage model is best for high-frequency, long-lived contexts. And aggregation services like TokenMix.ai, OpenRouter, and LiteLLM let you mix and match these strategies without hardcoding provider logic. Whichever path you choose, start measuring your cache hit rates immediately and adjust your prompt structure to lock in those cheaper tokens.

