Skip to content
Search documentation titles, headings, and guides
API v1Updated 2026-09-26

Prompt caching

How upstream prompt caching works, how to structure prompts so the cache hits, and how cache hits lower your bill.

Upstream prompt caching lets part of your input be served from a cache instead of being recomputed. When a cache hit happens, the cached portion of your prompt is billed at a discount rather than full price. This page explains how to structure your requests so the cache actually hits.

How prompt caching works#

Caching is keyed on the prefix of your prompt. The upstream provider stores recently seen prompt prefixes and, when a later request starts with the same prefix, serves that portion from cache. The part that matches the cache is called a cache read; the part the provider has to compute from scratch is fresh input.

Structure prompts for stable prefixes#

The single most important rule: put stable content at the start of your prompt and dynamic content at the end. Because caching matches on the prefix, any change at the beginning of the prompt invalidates the entire cache window.

  • Keep your system prompt, shared instructions, and reference context stable and at the top.
  • Put per-request data — timestamps, IDs, user queries, retrieved documents — at the bottom.
  • Avoid injecting a timestamp or nonce near the start of the prompt.
  • In multi-turn conversations, keep the conversation history ordered and append new turns rather than rewriting earlier ones.

Anthropic cache_control breakpoints#

On the Anthropic Messages endpoint, caching is opt-in: you mark breakpoints with a cache_control field. A breakpoint tells the provider where a cacheable prefix ends, so the prefix before it can be reused on the next request.

Mark a breakpoint with cache_control
{
  "model": "<public-name>",
  "max_tokens": 1024,
  "system": [
    {
      "type": "text",
      "text": "You are a helpful assistant with a large, stable instruction block.",
      "cache_control": { "type": "ephemeral" }
    }
  ],
  "messages": [
    { "role": "user", "content": "Dynamic user question goes here." }
  ]
}

OpenAI automatic caching#

On OpenAI-compatible routes, caching is automatic — you do not send any opt-in header. The provider caches based on prefix stability alone, so the guidance above still applies: keep stable content first and dynamic content last.

Provider-specific limits#

Not every model or route supports prompt caching, and the details vary by provider. The cache time-to-live (TTL), the minimum token threshold, and which endpoints support caching are all provider-specific and can change without notice. Do not assume a given model caches — verify it for your workload.

To confirm caching is working, check the usage breakdown in your dashboard. If you need the exact TTL or minimum thresholds for a specific model, ask your reseller for the current values.