Types of Caching
There are three main approaches to prompt caching used by LLM providers:- Implicit caching — The provider automatically caches repeated prompt prefixes. No code changes or configuration required. Requests with matching prefixes are routed to servers that recently processed the same content, enabling cache hits automatically. This is the simplest approach and is used by OpenAI, DeepSeek, Gemini, and many open-source models (Qwen, MiniMax, and others).
-
Explicit caching — You declare which content to cache using API parameters (such as headers or request body fields). This gives you more control over what gets cached and when. Anthropic uses this model via the
X-Cache-TTLheader. - Storage-based caching — You create managed caches via API that persist for a defined duration, billed per token-hour. This offers the most control but requires cache lifecycle management. Gemini offers this as a separate feature from its implicit caching.
Anthropic — Explicit Caching
Anthropic uses explicit caching via theX-Cache-TTL header. You opt in per request by setting the header, and our API automatically wraps your system messages with cache_control: {type: "ephemeral"} blocks. No modifications to your message content are needed—just add the header.
How it works
-
Set the
X-Cache-TTLheader to either"5m"or"1h". -
Our API places one
cache_controlmarker on the last system message to cache the entire stable system-prefix block. A single marker caches everything before it, covering the full assembled system prompt. -
The remaining three breakpoints are free for your own
cache_controlmarkers on your message content. -
If your request already contains 4
cache_controlmarkers, our marker is silently skipped — your request succeeds with no error, but system-prefix caching is not applied for that call. - Dynamic content at the end of your system messages (such as timestamps or user-specific data) is excluded from the cached block automatically.
Endpoint behavior
The Anthropic breakpoint limit is 4 per request. Minimum cacheable token thresholds vary by model (e.g., 4,096 tokens for Claude Haiku 4.5). See Anthropic’s prompt caching docs for current thresholds.
Billing
Cache writes are billed at a multiple of the standard input rate. Cache reads are always billed at 10% of the input rate.
Supported models
Anthropic caching works with all Claude models available through our API. See Supported Models for the current model list.Example
OpenAI — Implicit + Explicit Caching
OpenAI uses implicit caching as its primary mechanism. Caching works automatically on all API requests—no code changes required. When your prompt contains 1,024 tokens or more, OpenAI routes requests to servers that recently processed the same prompt prefix, enabling cache hits. This can reduce latency by up to 80% and input token costs by up to 90%. See OpenAI’s prompt caching announcement for details. For finer control, you can use explicit caching by adding aprompt_cache_key to your request body. This optional parameter influences server routing so that requests sharing the same key and common prefix are more likely to land on the same server, improving cache hit rates.
How it works
- Caching is implicit and automatic for prompts with 1,024+ tokens.
- Requests are routed to servers that recently processed the same prompt prefix.
- Optionally, add
"prompt_cache_key": "your-key"to your request body to improve routing for requests with shared prefixes. - Cache hits reduce both latency and cost. Cached tokens are billed at a discounted rate that varies by model — 10% of the input rate for GPT-5 models and 25% for GPT-4.1 and o-series models — with no write fee.
Billing
The cache read discount depends on the model. Current OpenAI families:
There is no write fee for OpenAI caching — you only pay for cache reads, at the model-specific rate above. Note that cheaper GPT-5 variants (gpt-5-mini, gpt-5-nano) have higher effective cache-read ratios (~23–56%) because of a minimum read-rate floor. See Checking your rates for exact per-model values.
Supported models
OpenAI caching works with OpenAI models available through our API. Theprompt_cache_key parameter is silently ignored for other providers. See Supported Models for the current model list.
Best practice: stable cache keys
Use deterministic, stable keys that match your prompt structure. Changing the system prompt means you should use a new cache key.Example
DeepSeek — Implicit Caching
DeepSeek uses implicit caching that works entirely on the provider side. No user action or configuration is needed.- No headers or request body fields required — caching is automatic.
- Cache read rates vary per model (roughly 9–90% depending on the model).
- No cache write fee.
- Savings from cache reads appear automatically in your billing.
Gemini — Implicit Caching
Gemini uses implicit caching on the provider side. No headers or request body fields are required—repeated prompt prefixes are automatically cached when you send a request that matches a previously seen prefix.How it works
- No customer action needed — caching is automatic. No
X-Cache-TTLheader, nocache_controlmarkers, and noprompt_cache_keyare required. - Repeated prefixes are cached by the provider automatically.
- Cache read rates are roughly 10% of the input rate for larger Gemini models; cheaper flash and flash-lite models are higher (up to ~33%) — check the models endpoint for exact per-model rates. Cache hits surface as a separate
cache_readsegment in your billing, the same as the other providers. There is no cache write fee for implicit caching.
Supported models
Gemini caching is available for all Gemini models in the Gloo AI catalog. Minimum token thresholds vary by model and are determined by the provider.Other Models (Qwen, MiniMax, and more) — Implicit Caching
A number of additional models in the Gloo AI catalog — including Qwen, MiniMax, and Xiaomi MiMo — support implicit caching through their upstream provider. Caching is automatic; no headers,cache_control markers, or prompt_cache_key are required.
- Automatic — repeated prompt prefixes are cached provider-side and surface as a
cache_readsegment in your billing, the same as the other providers. - Cache read rates vary widely per model (roughly 25–65% of the input rate — the discount is much smaller than the major providers’ for some models). A few models (e.g. some Qwen variants) also carry a cache write fee of 1.25× the input rate; most do not.
- Because rates differ substantially between models, use the models endpoint for exact per-model
cache_read/cache_writevalues.
Billing Summary
How total cost is calculated
The formula above applies to all four providers — cached tokens are billed as
a separate
cache_read segment. Gemini and OpenAI have no cache write fee, so
their cache_write term is always zero.Checking your rates
Use the models endpoint to see current per-model rates:Best Practices
- Static content first: For all providers, place static content (system prompts, instructions) at the beginning of your prompt. This maximizes prefix matches for implicit caching and ensures stable blocks for explicit caching.
- Use explicit caching when available: For Anthropic models, add the
X-Cache-TTLheader to opt in. For OpenAI, useprompt_cache_keyto improve routing for requests with shared prefixes. - Pre-warm on startup: Send an initial request with your standard system prompt to warm the cache before serving users.
- Monitor cache impact: Compare your token usage and billing over time. Cached tokens are billed at a reduced rate, so you’ll see lower input costs when caching is effective. Check your usage in the Gloo Studio billing dashboard.
Migration Guide
If you’re not currently using prompt caching, here’s how to get started:Implicit caching (OpenAI, DeepSeek, Gemini)
No code changes needed. Caching is automatic for prompts with repeated prefixes. Place static content (system prompts, instructions) at the beginning of your prompt to maximize cache hits. On Gemini, prefix-only caching works on the provider side with no special parameters.Explicit caching (Anthropic)
Add theX-Cache-TTL: 5m header to opt in to caching. System message caching is then automatic—no content modifications needed.
Improving cache hit rates (OpenAI)
Add"prompt_cache_key": "your-key" to your request body with a stable key that matches your prompt prefix. This improves server routing for requests with shared prefixes.
Related Documentation
- Completions V2 — Core routing mechanisms and streaming details
- Supported Models — Model IDs, capabilities, and current pricing

