← Blog

Claude Prompt Caching Implementation Guide

2026-11-10 · 5 min read · SubToAPI Team

Prompt caching lets Claude reuse large chunks of a prompt — system instructions, tool definitions, long documents — across multiple requests instead of reprocessing them every time. Implementing it correctly means marking the right parts of your prompt with cache_control breakpoints, keeping those sections byte-for-byte identical between calls, and structuring requests so the cacheable content comes before anything that changes.

If you're here because your Claude API bill is dominated by repeated context — a 20-page policy document sent on every support ticket, a 5,000-token system prompt sent on every chat turn — prompt caching is the fix, and it's a config change, not a rewrite. This guide walks through the actual implementation: where to put breakpoints, how the TTL and pricing work, and how to verify it's actually hitting.

How prompt caching actually works

Claude's API lets you tag specific content blocks with cache_control: {"type": "ephemeral"}. When you send a request, Claude checks if a prefix matching that cached block already exists from a recent request. If it does, it skips reprocessing that content and just reads it from cache — much cheaper and faster than a full prompt evaluation.

A few mechanics matter for implementation:

Where to put cache breakpoints

The general rule: put static, reusable content first, mark it with a breakpoint, then put the variable, per-request content after it. Common candidates:

Here's what a cached request looks like in practice:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "system": [
      {
        "type": "text",
        "text": "<your 4000-token system prompt and guidelines>",
        "cache_control": {"type": "ephemeral"}
      }
    ],
    "messages": [
      {"role": "user", "content": "Summarize ticket #4821 using the above guidelines."}
    ]
  }'

The system block is cached; the user message changes on every call but doesn't invalidate the cache because it comes after the breakpoint.

For tool-heavy agents, apply the breakpoint to the tool definitions instead:

const response = await anthropic.messages.create({
  model: "claude-sonnet-4-5",
  max_tokens: 1024,
  tools: [
    { name: "search_orders", input_schema: { /* ... */ } },
    { name: "refund_order", input_schema: { /* ... */ } },
  ],
  system: [
    { type: "text", text: longSystemPrompt, cache_control: { type: "ephemeral" } }
  ],
  messages: conversationHistory,
});

You can set multiple breakpoints in a single request (e.g., one after the system prompt, one after a static document, one after few-shot examples) as long as each block before a breakpoint stays identical across calls.

Verifying the cache is actually working

Don't assume caching is working just because you added cache_control — check the usage object returned with every response:

{
  "usage": {
    "input_tokens": 25,
    "cache_creation_input_tokens": 1150,
    "cache_read_input_tokens": 0,
    "output_tokens": 340
  }
}

On the first call, you'll see cache_creation_input_tokens populated — that's the write. On subsequent calls within the TTL window, you want cache_read_input_tokens populated instead, with cache_creation_input_tokens at or near zero. If you keep seeing cache creation on every call, something upstream is changing the cached prefix — check for timestamps, random IDs, or non-deterministic ordering in your system prompt or tool list.

Common implementation mistakes

Where this fits if you're building on top of Claude

If you're exposing Claude through your own product or internal tool, prompt caching is something you implement once at the request layer and it benefits every downstream call. If you'd rather not manage API keys, billing, and request plumbing yourself, SubToAPI turns your existing Claude access into a straightforward HTTPS API — with application keys, streaming, and usage metadata per key — so your team can focus on prompt structure instead of infrastructure. The Messages docs cover request formatting, and streaming and tools work the same way you'd expect from a direct Claude integration. Start with the quickstart or check pricing if you're evaluating plans.

questions

Does prompt caching reduce output quality or change responses? No. Caching only affects how input tokens are processed internally; it doesn't change the model, the prompt content, or the generated output in any way.

How long does the cache stay alive between requests? It's typically around five minutes of inactivity, refreshed on each cache hit. For bursty or steady traffic, this keeps the cache warm; for sparse, infrequent requests, you'll pay the cache-write cost more often than you get cache-read savings.

Can I cache multiple separate blocks in one request? Yes — you can set several cache_control breakpoints in a single request (for example, after the system prompt and again after a static document), as long as everything up to each breakpoint stays identical across calls.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →