Learning resourcesReviewed · Anthropic

Prompt caching guide (Claude API documentation)

This is Anthropic's official documentation page on prompt caching for the Claude API. It is written for developers who send long or repeated prompts to Claude. The main catch is that savings depend on exact prefix matches, per-model minimum prompt lengths and short cache lifetimes, so a misplaced breakpoint can cost more than it saves. The page explains automatic caching and explicit cache_control breakpoints, 5-minute and 1-hour lifetimes, per-model pricing, what invalidates a cache, how to read the usage fields and how to pre-warm a cache. Its examples use cURL, the ant CLI and seven SDK languages.

Researched 12 Nov 2026

In short.

This is Anthropic's official documentation page on prompt caching for the Claude API. It is written for developers who send long or repeated prompts to Claude. The main catch is that savings depend on exact prefix matches, per-model minimum prompt lengths and short cache lifetimes, so a misplaced breakpoint can cost more than it saves. The page covers two ways to turn caching on: a single top-level cache_control field, or cache_control markers on individual blocks. It also covers the default 5-minute lifetime and the optional 1-hour lifetime, a per-model price table, the prefix order (tools, then system, then messages), a table of changes that invalidate the cache, the usage fields for checking hits, cache pre-warming with max_tokens set to 0, and data-retention notes. Nothing on the page was run or measured, and the page reports no benchmark results of its own.

Researched and written by an AI model and checked by a second AI model. How it works

The scope is the single documentation page at [https://platform.claude.com/docs/en/build-with-claude/prompt-caching.md], captured on 2026-11-12 as selected-page.txt (167,736 bytes) and read in full. No licence file or separate notice was captured with it, so reuse rights are unknown. Pages it links to (thinking, pricing, cache diagnostics, mid-conversation system messages, batch processing, the Cookbook recipe and others) are excluded and were not reviewed. Nothing was run. None of the code examples, API behavior, pricing figures, minimum token lengths or platform-support statements were tested or checked against the live site; they are reported as the page states them.

The overview

Identity

This resource is a single documentation page titled Prompt caching. Anthropic publishes it on its Claude Platform docs site at [https://platform.claude.com/docs/en/build-with-claude/prompt-caching]. The copy reviewed here is the .md version of that address, [https://platform.claude.com/docs/en/build-with-claude/prompt-caching.md]. The page describes the prompt caching feature of the Claude Messages API. Caching lets the API resume processing from a prompt prefix it has already seen, so repeated content is billed at a lower rate and handled faster.

The captured file is selected-page.txt (167,736 bytes, captured on 2026-11-12). It opens with front matter listing the supported models and platforms. The guide follows, then a long set of worked examples, an FAQ and an availability section. It is a reference and tutorial page, not a software package, so there is nothing to install from it.

Assessment

Judged on its text alone, this is a thorough and unusually specific guide from the vendor itself. It goes beyond showing how to add the flag. It explains the rules that decide whether you actually get cache hits: writes happen only at breakpoints, reads look backward over at most 20 positions per breakpoint (the breakpoint itself counts as the first, and on the Claude API a run of consecutive tool_use blocks counts as one position, as does a run of consecutive tool_result blocks), and the hash covers everything up to and including the breakpoint. It also shows a common mistake: putting a breakpoint on a block that changes on every request. For anyone paying for repeated long prompts on Claude, these mechanics are the most valuable part of the page.

The caveats are about scope rather than quality. This is one provider's documentation, so it makes no comparison with other approaches. It states pricing multipliers and rules but reports no measured savings or latency figures, and none of its claims were checked by sending real requests. The copy assessed here was captured on 2026-11-12. The page's last revision date is unknown, and so is whether its pricing, supported models and platform behavior still match the live API. Check the live page before you plan a budget.

Who it is for

The main audience is developers who call Claude with prompts that share a large, unchanging beginning. That includes the Claude API itself and Claude on Amazon Bedrock, Claude Platform on AWS, Claude Models on Google Cloud and Microsoft Foundry. The page lists its own use cases: prompts with many examples, large background documents, repetitive tasks with consistent instructions, long multi-turn conversations, coding assistants that keep a codebase summary in the prompt, agentic tool use with many API calls, and question-answering over books, papers or transcripts.

Beginners can follow the first sections, where the opening example adds one line (cache_control with type ephemeral) to an ordinary request. The later sections assume you are comfortable with the request structure (tools, system, messages), token counts and the usage object. The page does not address people who use Claude only through a chat app, because it is about API request parameters. Teams running Message Batches or tool-heavy agents get dedicated guidance. The page also notes that caching is always on in Managed Agents.

What it covers

The page documents these parts of the feature. With automatic caching, one top-level cache_control field makes the system place the breakpoint on the last cacheable block and move it forward as a conversation grows. Explicit breakpoints can go on tool definitions, system blocks, text, images, documents, tool_use blocks and tool_result blocks, with up to 4 breakpoints per request. The default lifetime is 5 minutes and refreshes on each use at no extra charge. A 1-hour lifetime is selected by setting ttl to 1h.

It also covers several more advanced topics. You can mix lifetimes in one request, but longer lifetimes must come first, and billing follows a three-position rule the page calls A, B and C. Pre-warming sends a request with max_tokens set to 0, which writes the cache without generating any output. Three usage fields track caching: cache_creation_input_tokens, cache_read_input_tokens and input_tokens, and the page gives a formula for total input tokens. It lists what cannot be cached directly (thinking blocks, sub-content such as citations, and empty text blocks) and explains how caching works with thinking blocks.

Supporting material includes a table of the changes that invalidate each cache level, a troubleshooting checklist and a pointer to a separate cache diagnostics feature. There are notes on Message Batches: hits are best-effort, and the page suggests writing the shared prefix to the 1-hour cache first. Worked examples cover a large document, cached tool definitions, a multi-turn conversation and a setup with four breakpoints.

Using it

Requirements

To use what the page describes you need access to the Claude API or one of the listed cloud platforms, and a supported model. The examples that call the Claude API directly use an API key from the ANTHROPIC_API_KEY environment variable, and the cURL examples send it in the x-api-key header. The captured page does not describe how authentication works on Amazon Bedrock, Claude Platform on AWS, Claude Models on Google Cloud or Microsoft Foundry, so those requirements are unknown here. The front matter lists models from the Claude Fable, Mythos, Opus, Sonnet and Haiku families, and the body says caching is supported on all active Claude models. The examples send an anthropic-version header with the value 2026-10-21 and mostly use the model name claude-opus-5-5.

Your prompt must reach the minimum cacheable length for the model. A shorter prompt is processed without caching, and no error is returned. The page gives these minimums for the Claude API, Claude Platform on AWS, Google-managed Claude Models on Google Cloud and Microsoft Foundry:

512 tokens for Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Fable 5, Mythos 5, Opus 5.5, Opus 5, Sonnet 5.5 and Haiku 5.5.

1,024 tokens for Opus 4.8, Sonnet 5, Sonnet 4.6, Sonnet 4.5 and the older Opus 4.1, Opus 4 and Sonnet 4.

2,048 tokens for Mythos Preview and Opus 4.7.

4,096 tokens for Opus 4.6, Opus 4.5 and Haiku 4.5.

Amazon Bedrock (bedrock-mantle) users are sent to AWS documentation for their minimums.

Platform differences matter. Automatic top-level caching is not available on Amazon Bedrock (bedrock-runtime): there, a top-level cache_control field returns a 400 error, and you must use explicit breakpoints instead. The page states no minimum SDK version. The code samples cover cURL, the ant CLI, Python, TypeScript, C#, Go, Java, PHP and Ruby.

How it works

Caching works on prefixes in a fixed order: tools, then system, then messages. When you mark a block with cache_control, the system writes one entry: a cumulative hash of everything up to and including that block. On later requests it computes the hash at your breakpoint. If no entry matches, it walks backward one position at a time, checking at most 20 positions (the breakpoint counts as the first), for an entry that an earlier request wrote. On the Claude API, a run of consecutive tool_use blocks counts as one position, and so does a run of consecutive tool_result blocks. The lookback finds only entries written at earlier breakpoints. It does not find stable content that was never written to the cache.

This explains the failure the page stresses most. Some requests keep a static prefix and replace a varying suffix after it, such as a timestamp, per-request context or the incoming message. If the breakpoint sits on that varying block, the hash at the breakpoint is different every time, and no earlier position was ever written. Each request then pays for a fresh cache write and never gets a read. The fix is to put the breakpoint on the last block that stays identical across requests.

A growing conversation is different. Earlier turns stay unchanged, so even though the newest message changes, the lookback can find the entry the previous request wrote, as long as each turn adds fewer than 20 blocks. If a conversation might grow 20 or more positions past the last write, the page advises keeping a second breakpoint where a previously written prefix ends. That breakpoint starts a second lookback window there. Set it up from the start, so a write builds up at that position before the earlier entry falls outside the 20-position window.

Cache hits require identical segments, including all text and images up to the breakpoint. Entries are always isolated per organization. On the Claude API, Claude Platform on AWS and Microsoft Foundry they are also isolated per workspace. A new entry becomes available only after the first response starts, so parallel requests that need a hit should wait for that response. The lifetime is counted from the start of the request that wrote or read the entry. For example, a response that takes 4 minutes to stream leaves only about one minute of a 5-minute window. Caching does not change output: the page says the response is identical to what you would get without it.

Setup

The page suggests starting with automatic caching. Add cache_control with type ephemeral at the top level of the request body, and keep static content (tool definitions, system instructions, context, examples) at the start of the prompt. The page recommends this first for multi-turn conversations, because it moves the breakpoint for you.

For finer control, put cache_control on individual blocks. To cache tool definitions, put it on the last tool in the tools array. To cache a long document in the system prompt, put it on the system block that holds the document. You can combine both approaches, but the automatic breakpoint then takes one of the 4 slots. The request returns a 400 error if 4 explicit breakpoints already exist, or if the last block has an explicit breakpoint with a different lifetime.

To confirm caching is working, read the usage object in the response. If cache_creation_input_tokens and cache_read_input_tokens are both 0, nothing was cached; the page says the most likely cause is a prompt below the minimum length. For debugging, the page points to a separate cache diagnostics feature that compares consecutive requests. None of these steps were run; this description comes from the page text only.

Example

The page's simplest example is a Messages API request with a system prompt about analyzing literary works, one user message, and a top-level cache_control of type ephemeral. The only caching change is adding { "cache_control": { "type": "ephemeral" } } next to model, max_tokens, system and messages. The page shows this request in cURL, the ant CLI and seven SDK languages (Python, TypeScript, C#, Go, Java, PHP and Ruby).

A more realistic example caches a long legal agreement. The system array holds two text blocks: a short role statement, and the full agreement with cache_control on it. The user question stays uncached. On the first request, the usage fields show the whole system message, including the agreement, under cache_creation_input_tokens, and only the question under input_tokens. On later requests within the lifetime, the same system tokens appear under cache_read_input_tokens.

The pre-warming example sends the same system block with max_tokens set to 0 and a placeholder user message, warmup. The response has an empty content array, a stop_reason of max_tokens and no billed output tokens. A cache write is still charged if the prefix was not already cached. The breakpoint must sit on the shared system block, not on the placeholder, so this case needs an explicit breakpoint rather than automatic caching. These examples are taken from the page; none of them were run.

Assessment & evidence

Limitations

Limits of the feature, as the page states them. Only the ephemeral cache type exists, with a default 5-minute lifetime and a 1-hour option. A cache cannot be cleared manually. Prompts below the model's minimum length are not cached, and no error is returned. Thinking blocks cannot take cache_control directly, and a request can have at most 4 breakpoints.

Many changes invalidate caches:

Changing tool definitions in the top-level tools array (names, descriptions, parameters) invalidates the tools, system and messages caches.

Turning web search, citations or speed mode on or off invalidates the system and messages caches.

Changing tool_choice, or adding or removing images, invalidates the messages cache.

Changing thinking parameters or output_config.effort can invalidate more, depending on the model.

There is one documented way around the tool-definition rule. On models that support mid-conversation tool changes, a beta enabled with the inline-tools-2026-09-15 header lets you add a tool or change its definition without touching the tools array. You send the definition in a tool_addition block inside an appended mid-conversation system message and leave the tools array exactly as first sent, so the cached prefix still matches. The exception: if the tools array has no non-deferred tool, the first tool added this way causes one full cache miss on that request. Which models support this is described on a linked page that is outside the captured scope.

Other documented constraints. The 20-position lookback can miss an earlier entry in long conversations. Message Batches give only best-effort hits, because batch requests are processed concurrently and in any order. A max_tokens 0 pre-warm request is rejected if it sets streaming, extended thinking, structured outputs, or a tool_choice of type tool or any, and it is also rejected inside batches. Caches are isolated per workspace on some platforms and per organization on others. Some languages (the page names Swift and Go) randomize JSON key order in tool_use blocks, which can break caches.

Limits of this report. The page is one vendor's own documentation and contains no independent benchmarks or measured savings. Nothing was tested, the SDK examples were not run, and the price and model tables were not checked against the live site. Linked pages, such as those on thinking, pricing, cache diagnostics and mid-conversation system messages, are outside the captured scope, so their details are unknown here.

Reasoning

The assessment rests on what the page itself establishes. It is the vendor's own description of how its API behaves, so its rules (prefix order, lookback window, minimum token lengths, invalidation table, price multipliers) come from the party that defines them. Many parts agree with each other; for example, the multiplier note matches the price table. The page is not fully consistent, though. It defines input_tokens as the tokens after the last cache breakpoint. Yet its continuing-conversation example puts cache_control on the final user message and then says that message is counted under input_tokens. That explanation conflicts with the definition, so check the usage fields in your own responses rather than relying on that example's explanation.

The guidance is practical rather than promotional. It says when not to use the 1-hour cache: if a prompt is sent more often than every 5 minutes, the 5-minute cache keeps refreshing for free. It warns about a specific automatic-caching pitfall: when a request keeps a static prefix and replaces a varying suffix after it (a timestamp, per-request context or the incoming message), automatic caching puts the breakpoint on that varying block, no earlier request has written a matching entry, and every request pays for a fresh write without ever getting a read. The page separates this from growing conversations, where earlier turns stay unchanged and the lookback can reuse the entry the previous request wrote. It also warns that a pre-warm request is billed for its cache write. These are the decisions a developer actually has to make, and they keep the page from reading like a sales page.

Confidence is limited because nothing was run. Hit behavior, latency improvements and exact billing are the page's claims, not verified outcomes. The page says you generally see faster time-to-first-token for long documents but gives no figures, so the size of any benefit for your workload is unknown until you measure it with the usage fields.

Alternatives and related options

The page itself points to several related resources, none of which were reviewed here. The Claude Cookbook has a prompt caching recipe with more examples at [https://platform.claude.com/cookbook/misc-prompt-caching]. A separate cache diagnostics page at [https://platform.claude.com/docs/en/build-with-claude/cache-diagnostics] helps find where a prompt prefix diverged. Amazon Bedrock (bedrock-mantle) users are directed to [https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html] for their minimums and field names. The Message Batches API at [https://platform.claude.com/docs/en/build-with-claude/batch-processing] is a separate way to cut costs, and the page says its discount stacks with caching.

The page does not compare Claude prompt caching with caching or context features from other model providers. Nor does it compare it with application-level approaches such as shortening prompts or retrieving only the relevant passages. Whether those would suit a given project is not assessed here.

Evidence

All findings come from one captured file, selected-page.txt (evidence_2564211c-e6e7-403e-8a23-250f9d0b33d1). It is the .md version of the prompt caching page, 167,736 bytes, captured on 2026-11-12. The parts relied on include the introduction and the two ways to enable caching, the How prompt caching works section, the pricing table with its footnotes and multiplier note, the minimum token lengths under Cache limitations, the What invalidates the cache table, the Tracking cache performance note, the sections on the 1-hour cache and mixed lifetimes, the pre-warming section and its limitations, the worked examples, the FAQ, and the availability and data-handling sections.

No other evidence was available: no licence text, no changelog, no code repository and no independent test results. Claims beyond the page, such as real-world savings or comparisons with other providers, have no evidence behind them here.

Access & freshness

Costs

The page states no cost for reading the documentation. The feature itself is billed per token, using these multipliers of the base input price: 1.25 times for 5-minute cache writes, 2 times for 1-hour writes, and 0.1 times for cache reads and refreshes. Some models have lower read prices: 0.025 times for Claude Fable 5.2, Mythos 5.2, Fable 5.1 and Mythos 5.1, and 0.05 times for Opus 5.5 and Sonnet 5.5. Breakpoints themselves cost nothing; you pay only for what is written, read or sent uncached.

Examples from the published table, per million tokens:

Claude Opus 5: base input $5, 5-minute write $6.25, 1-hour write $10, cache hit $0.50, output $25.

Claude Sonnet 5.5: base input $2, 5-minute write $2.50, 1-hour write $4, cache hit $0.10, output $10.

Claude Haiku 4.5: base input $1, 5-minute write $1.25, 1-hour write $2, cache hit $0.10, output $5.

Claude Haiku 5.5 has two price tiers by prompt length: base input is $0.10 for prompts up to 100,000 tokens and $0.50 above that. The table also lists older models, marked as retired except on some platforms.

Here is an illustration worked out from the stated multipliers; it is arithmetic, not a measured result. On a model with the standard 0.1 times read price, a prefix written once to the 5-minute cache and read once costs about 1.35 times its base input price. Sending it uncached twice would cost 2 times. A prefix that is never reused costs 1.25 times, which is more than not caching at all. The page says these multipliers stack with the Batch API discount, long-context pricing and data-residency pricing, and that cache hits are not deducted from rate limits. Check current prices on the live page, because the table may have changed since capture.

Rights and reuse

The captured page contains no licence, copyright notice or statement of reuse terms for the documentation text or its code samples, and no separate licence or notice file was captured. Reuse and redistribution rights for the page are therefore unknown. Do not assume that copying or republishing the page is permitted.

What the page does describe is how the API feature handles your data. Prompt caching is eligible for zero data retention (excluding Covered Models) and for HIPAA readiness. Anthropic says it does not store the raw text of prompts or responses. Key-value cache representations and cryptographic hashes are held in memory for the cache lifetime and deleted promptly, though not immediately, after it ends. These statements are about your data, not about any licence on the documentation.

Freshness

The page was captured on 2026-11-12. At that time it listed Claude Fable 5.2, Mythos 5.2, Opus 5.5, Sonnet 5.5 and Haiku 5.5 among the supported models. Its examples used the anthropic-version value 2026-10-21, and it mentioned a beta header, inline-tools-2026-09-15, for changing tools mid-conversation. It marked Claude Opus 4.1, Opus 4 and Sonnet 4 as retired except on some platforms, and Sonnet 4.5 as deprecated. These names and dates show what the page said when it was captured. They do not show that the page is accurate now.

The captured text has no visible revision date or version number, so its last edit date is unknown. Whether its operational details still hold today is also unknown. Model lineups, prices, minimum token counts and per-platform support are the details most likely to change. If you plan to act on the numbers, compare them with the live page at [https://platform.claude.com/docs/en/build-with-claude/prompt-caching] first.

Suggested next steps

If you are new to caching, read the opening section, How prompt caching works and Cache limitations first. Then try automatic caching on a request whose prompt is clearly longer than your model's minimum. Send a second identical request within five minutes and check that cache_read_input_tokens is above 0. If it stays at 0, check the model's minimum length, whether anything near the end of the prompt changes each time, and whether tools, images or thinking settings differ between calls.

If you run a larger system, decide where the stable prefix ends. If your requests replace a varying suffix after that prefix (timestamps, per-request context or the incoming message), put an explicit breakpoint at the end of the stable prefix rather than relying on automatic caching's last-block placement; for growing conversations, the page suggests automatic caching as the starting point. Use the What invalidates the cache table to keep tool definitions and system text stable. For the lifetime, the page says to keep the 5-minute cache for prompts sent more often than every 5 minutes, because it refreshes at no extra charge. It suggests the 1-hour lifetime for prompts likely reused less often than every 5 minutes but more often than every hour, when latency matters and follow-up prompts might arrive after 5 minutes, and when you want better rate-limit utilization, since cache hits are not deducted from rate limits; weigh these cases against the 2 times write price. Track hit rates through the usage fields before concluding that caching saves money, and confirm prices on the live page before relying on them. If you plan to copy or republish text from the page, look for the publisher's terms first, because none were captured.

Evidence for this report

selected-page.txtselected · checked 2026-11-12