Skip to main content
Prompt caching lets you reuse processed prompt tokens across multiple requests, reducing both cost and latency. When requests start with the same text (the same prompt prefix, such as a long system prompt or a shared document), those tokens can be served from cache instead of being processed again. Current per-token rates are available on the models page.
New to token pricing? Cost and Speed in the AI Learning Center covers how requests are priced, how caching lowers the cost, and how to choose a model and reasoning effort.

Providers at a glance

Percentages are of the model’s input rate. The models endpoint has the exact rates for every model.

Types of caching

LLM providers use three main approaches:
  • Implicit caching: the provider automatically caches repeated prompt prefixes, with no code changes or configuration. Requests with matching prefixes are routed to servers that recently processed the same content. 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), for more control over what gets cached and when. Anthropic uses this model via the X-Cache-TTL header.
  • 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.
Most providers combine approaches. The provider details cover what each provider supports and how to use it through Gloo AI.

Turn caching on

To start using prompt caching:

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 the X-Cache-TTL: 5m header to opt in to caching. System message caching is then automatic, with no content changes.

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.

Provider details

Anthropic uses explicit caching via the X-Cache-TTL header. You opt in per request by setting the header, and Gloo AI caches your system messages for you, with no changes to your message content.

How it works

  1. Set the X-Cache-TTL header to either "5m" or "1h".
  2. Add at most three cache_control markers of your own on your message content.
  3. If your request already contains four cache_control markers of its own, your system messages aren’t cached on that call. The request still succeeds with no error.
  4. Keep per-request values (such as timestamps or user-specific data) in the user message, so your system messages stay identical from call to call.

Endpoint behavior

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 billed at 10% of the input rate on most Claude models, and less on some newer ones: 5% on Claude Opus 5.5 and Sonnet 5.5, and 2.5% on Claude Fable 5.1. The models endpoint lists the exact rate for each model.

Supported models

Anthropic caching works with all Claude models available through our API. See Supported Models for the current model list.

Example

Cost and rates

How total cost is calculated

The formula above applies to all four providers: cached tokens are billed as a separate cache_read segment. On a model with no cache write fee, such as most OpenAI models and the DeepSeek models, the cache_write term is zero.
The per-segment rates returned by the models endpoint are list prices (the model’s published rate). Direct endpoints and Grounded Responses bill these rates as listed; guarded endpoints and Grounded Completions are priced at the list price plus 6.5% on every segment, the guarded platform price.

Checking your rates

Use the models endpoint to see current per-model rates:

Best Practices

  1. 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.
  2. Use explicit caching when available: For Anthropic models, add the X-Cache-TTL header to opt in. For OpenAI, use prompt_cache_key to improve routing for requests with shared prefixes.
  3. Pre-warm on startup: Send an initial request with your standard system prompt to warm the cache before serving users.
  4. Monitor cache impact: Compare your token usage and billing over time. Effective caching shows up as lower input costs. Check your usage in the Gloo Studio billing dashboard.
  5. Expect fewer cache hits after failover: Caches are held by each provider, so a request that fails over to another provider does not read the cache built on the original one.
For request structure on the guarded endpoints, such as keeping your instructions in the system message and pinning a model, see Building with Guarded Endpoints. To apply these step by step and measure the savings on your own traffic, follow the Prompt Caching tutorial. For caching alongside the other levers on your bill, see Controlling Cost.

Next steps

Step-by-step tutorial

Restructure a prompt for caching and measure the savings.

Completions V2

Core routing mechanisms and streaming details.

Supported Models

Model IDs, capabilities, and current pricing.

Provider Failover

What happens when the provider serving your model fails.
For core routing mechanisms and streaming details, see Completions V2.