How to Use Prompt Caching to Cut Your LLM API Bills in Half

Quick Answer: Prompt caching allows AI providers to store your static prompt segments (system instructions, documents, tool definitions) in memory between API calls. To take advantage of this and cut your cache read/input token costs by up to 90% (note: this discount applies specifically to input tokens, not your entire API bill or output tokens), you must structure your prompts in a cache-aware format: place your large, static instructions at the beginning of the prompt (the prefix) and append your small, dynamic user inputs at the very end.
What is the difference between Write and Read caching?
Write caching refers to the cost of processing a new static prefix to write it to cache memory, while Read caching refers to the highly discounted cost of retrieving that prefix on subsequent requests.
As businesses scale their AI agentic workflows in 2026, they quickly run into a major bottleneck: API cost and latency.
When building advanced applications (like code assistants, workspace search agents, or PDF synthesizers), you often have to pass hundreds of pages of context, system instructions, and tool definitions with every single message. In a multi-turn conversation, you end up paying for the same thousands of input tokens over and over again.
To solve this, leading AI providers (such as Anthropic, Google, and OpenAI) have introduced Prompt Caching (leveraging KV cache optimization under the hood). When used correctly, prompt caching can reduce input token costs by up to 90% and significantly reduce latency/Time-to-First-Token (TTFT) depending on the provider and workload. Here is a guide on how it works and how to structure your prompts to maximize savings.
How Does Prompt Caching Work?
What is the cost discount of prompt caching?
Prompt caching typically reduces read token costs by 90% compared to standard input token pricing, turning repeating instructions into highly efficient memory operations.
In a standard API call, the model has to process the entire input prompt from scratch.
With Prompt Caching, the API provider saves the parsed state of a prompt prefix in its fast-access memory. On subsequent requests, the provider checks if the incoming prompt starts with the same sequence of tokens. If it does, the model loads the cached prefix instantly, bypassing the expensive processing step.
The Pricing Impact
While pricing varies by model and changes frequently (you should see current provider pricing for the most up-to-date numbers), caching always offers a substantial discount on input processing:
- Cache Write / Input Processing: Standard rate, sometimes with a minor premium (e.g., 25% extra) to create the cache.
- Cache Read / Input Retrieval: Highly discounted, often saving up to 90% on input token costs for cache hits compared to normal input tokens.
This makes multi-turn conversations and long-context agentic loops extremely cost-effective.
LLM Prompt Caching Provider Comparison
Below is a comparison of how different leading providers handle prompt caching in 2026:
| Provider | Caching Mechanism | Time-to-Live (TTL) | Read Discount (Cache Hit) | Notes / Best Use Case |
|---|---|---|---|---|
| OpenAI (GPT 5.6, GPT-4o, GPT-4o-mini) | Automatic | Typically 5–10 minutes | ~50% discount | Fully hands-off; automatically caches prefixes longer than 1,024 tokens. |
| Anthropic (Claude 5 Fable, Claude 3/3.5) | Explicit (via cache breakpoints) | 5 minutes (default) | ~90% discount | Requires developers to define up to 4 explicit breakpoints (cache_control). Great for system prompts and few-shot examples. |
| Google (Gemini 1.5/3.5) | Explicit (Context Caching API) | User-configurable (1 hour default) | ~75% to 90% discount | Requires creating a cached resource first. Ideal for massive files, video, audio, or codebase context. |
The Core Rule of Cache-Aware Prompt Engineering
How do you format prompts for caching?
To leverage prompt caching, place all static components (system prompts, tool schemas, and documents) at the beginning of your prompt, and place dynamic components (like user queries and timestamps) at the absolute end. (To structure your data correctly, follow our guide on context caching in agentic loops.)
Prompt caching operates on a strict prefix-matching basis. If even a single character changes at the beginning of the prompt, the entire cache is invalidated, resulting in a cache miss.
Therefore, you must structure your prompts so that all static information is placed first, and all dynamic, frequently changing information is placed at the end.
❌ The Bad Structure (No Cache Hits)
In this layout, the user query and random timestamps are placed at the top, which changes every time. This invalidates the cache for the entire rest of the prompt:
=== USER QUERY ===
Current Date: 2026-07-15T19:24:00Z
Query: "Analyze the user profile."
=== SYSTEM RULES ===
[10,000 tokens of static prompt rules, tools, and brand guides...]
The Good Structure (Max Caching)
Here, the large, static instructions are placed at the beginning. When a user sends a new message, the top block matches the cache, resulting in a cheap, fast read:
=== SYSTEM RULES ===
[10,000 tokens of static prompt rules, tools, and brand guides...]
=== USER QUERY ===
Current Date: 2026-07-15T19:24:00Z
Query: "Analyze the user profile."
3 Areas to Optimize for Caching
To get the most out of prompt caching in your SaaS applications, apply these structural guidelines:
1. Group Your Tools
If your agents use tools (Function Calling), pass the tool definitions inside the static prefix block right after your system prompt. Tool schemas are static, meaning they are perfect candidates for caching. Make sure to enforce strict schemas—refer to our guide on structured outputs to get clean JSON schema representations.
2. Standardize Few-Shot Examples
Few-shot examples are static data. Keep your few-shot blocks identical across requests and place them right after the tool definitions. Do not dynamically swap examples based on user input if you want to maintain a high cache hit rate.
3. Handle Long Documents Wisely
If you are building a document search tool, cache the document itself. Structure your prompt as:
- System Prompt (Static)
- Document Content (Static)
- User Question (Dynamic - at the bottom)
When working with complex agent loops, prompt caching is a fundamental building block. See how to optimize agentic workflows using cache-friendly patterns. If you need to secure your prompts against manipulation, read our article on securing system prompts. Finally, if you are targeting multiple LLM providers, read our multi-model prompting guide to configure caching appropriately across different vendor SDKs.
Summary Checklist for Cache Optimization
- Prefix Alignment: Ensure all white spaces, punctuation, and structural dividers at the top of your prompt are 100% identical across calls.
- Dynamic Data Pruning: Keep timestamps, unique conversation IDs, and user messages at the very end of your request payload.
- Cache Lifetime: Remember that caches typically expire after 5 minutes by default; some providers support 1-hour TTL or user-configurable cache durations (like Gemini context caching). Keep agent loops active or group requests to optimize hit rates.
Managing Cache-Optimized Prompts
Structuring prompts for maximum caching requires careful layout control.
At PromptBuff, our template manager and API routes automatically enforce cache-aware layouts. When you define variables, system prompts, and contexts in the PromptBuff dashboard, the platform compiles them by placing static structures first, grouping tool configurations, and pushing dynamic runtime inputs to the end of the prompt payload. This ensures that every API call you make through your PromptBuff integrations gets the maximum possible cache discount.
Stop overpaying for LLM input tokens. Learn how PromptBuff.app can help you optimize your AI architecture today.
Continue reading: Claude 5 Fable vs. GPT 5.6 vs. Gemini 3.5: A Developer's Guide to Multi-Model Prompting · Structured Outputs: How to Get Flawless JSON and XML from Any LLM
Frequently Asked Questions (FAQ)
Does OpenAI support prompt caching?
Yes, OpenAI supports automatic prompt caching on GPT 5.6, GPT-4o, GPT-4o-mini, GPT-4, and GPT-3.5 models. It is automatically enabled for prompt prefixes that are 1,024 tokens or longer.
What invalidates a prompt cache?
Prompt caching relies on strict prefix-matching. If a single character, variable, or space at the beginning of the prompt changes, the entire cache is invalidated, resulting in a cache miss.
How long does prompt cache last?
Caches typically expire after 5 minutes of inactivity by default on Anthropic and OpenAI. Google Gemini context caching allows user-configurable Time-to-Live (TTL), defaulting to 1 hour.
Is prompt caching automatic?
For OpenAI, it is fully automatic. For Anthropic and Google Gemini, prompt caching is explicit and requires developers to define breakpoints or manage cache resources manually via the API.
Does caching affect output quality?
No, prompt caching does not affect output quality or model behavior. Because prompt caching loads the exact mathematical state of the processed tokens, the model's responses are identical in quality and deterministic behavior.