Prompt caching for Claude
Last updated: 2026-11-08T13:49:34-03:00 (UTC-3)
Claude reads a prompt prefix from its cache only up to a point the request marks with cache_control. A cached read costs a tenth of the input price or less, but the provider never caches on its own: a request without a mark pays the full input price every time. An application that talks to Claude in the OpenAI format (Chat Completions or Responses) usually sends no mark, and until T115 the gateway also dropped the marks an OpenAI-compatible SDK did send, so a Claude alias reached through an OpenAI client never got the discount.
The gateway now carries the marks a client sends to every Claude target, and can place marks itself on a target with prompt_cache: {mode: auto}. This covers requests translated to the Anthropic Messages API and to Claude on Amazon Bedrock (Converse). A native /v1/messages call to an Anthropic target is already the client’s own request and goes as the client sent it.
Marks the client sends
Section titled “Marks the client sends”A Chat Completions request may carry cache_control, the extension that OpenAI-compatible SDKs already use for Claude, in three places:
| Where | Effect |
|---|---|
A content part (text or image_url) of any message |
The point is at the end of that part |
A message ({"role": ..., "content": ..., "cache_control": {...}}) |
The point is at the end of the message’s last block; useful for string content |
A tool ({"type": "function", "function": {...}, "cache_control": {...}}) |
The point is at the end of that tool definition |
The value is {"type": "ephemeral"}, with an optional "ttl": "5m" or "1h" (five minutes by default). Anything else, an unknown member included, is refused with 422 before any provider call, because the provider would refuse it too and a guess could double the price of a write.
{ "model": "claude", "messages": [ {"role": "system", "content": [ {"type": "text", "text": "<a long, stable system prompt>", "cache_control": {"type": "ephemeral"}} ]}, {"role": "user", "content": "Summarize the attached contract."} ]}A Messages request translated to another provider (for example /v1/messages on an alias whose target is Bedrock) keeps its block marks (text and image blocks, assistant text blocks, tool results and the text inside them), its tool marks and its top-level cache_control (automatic caching: the last block). Two marks have no exact place in the canonical format and move to the nearest later point: a mark on an assistant tool_use block moves to the end of that turn’s last tool call, and a mark inside a tool result covers the whole result. Such a point then also covers the rest of that tool-call run or tool result; marks on thinking blocks are not carried, like the thinking blocks themselves. A mark on an empty text block is refused with 400, as the Messages API refuses it.
How each target uses the marks:
| Target | What it receives |
|---|---|
Anthropic Messages (protocol: anthropic) |
cache_control on the same block, tool or system block. A system or assistant message with a marked part is sent one block per part, so the point ends where the client put it; without marks it stays one block, as before. |
Bedrock Converse, Claude model (anthropic.claude-*) |
A cachePoint block right after the marked block, in system, messages or toolConfig.tools; "ttl": "1h" only for one-hour marks (Bedrock may refuse the field on a model with the five-minute TTL only). A system message with a marked part is sent one block per part, as on Anthropic. |
| OpenAI Chat Completions, reached from Chat Completions | The client’s body, unchanged, as before T115 (OpenAI-compatible servers that accept the extension keep working). |
| Any other target (OpenAI from another route or with the Responses API, Gemini, Cohere, SageMaker, OCI, a non-Claude Bedrock model) | No mark: it is removed from that attempt, and the answer lists cache_control in X-Gateway-Translation-Lossy. |
Each attempt of a fallback decides for itself, so a request that falls back from Claude to another provider loses the marks only on the second attempt, and the header describes the attempt that answered.
Two provider rules are checked before the call, on the client’s marks and on automatic ones alike, because both providers refuse such a request: at most four points per request, and no one-hour point after a five-minute one (tools come first, then the system prompt, then the messages). An empty text part cannot carry a mark either, nor can a message whose last block is empty text or that has no content. A refusal skips the target without calling it, as any translation refusal does.
Automatic points
Section titled “Automatic points”models: - id: claude targets: - provider: anthropic model: claude-haiku-5-5 prompt_cache: mode: auto # off (default) or auto ttl: 5m # 5m (default) or 1h points: [tools, system, history] # default; in prompt order min_prefix_tokens: 0 # 0: the model's documented minimum| Field | Default | Values |
|---|---|---|
mode |
off |
off: nothing is added. auto: the gateway places points when the request has none. |
ttl |
5m |
5m or 1h, for every automatic point. |
points |
[tools, system, history] |
Up to four of tools (end of the tool definitions), system (end of the system prompt), history (end of the turn before the last one), last_message (end of the last turn). |
min_prefix_tokens |
0 |
0 to 1,000,000; 0 uses the model’s documented minimum (below). |
prompt_cache is accepted on anthropic and bedrock targets of chat, messages, responses and generate_content aliases; auto on Bedrock needs a model ID that names Claude (anthropic.claude-*, with or without a regional prefix). It is saved and validated like the rest of the alias (YAML, PUT /api/v1/admin/models/{id}, console Model catalog → Edit routing → Prompt cache) and applies from the next request, without a restart. There is no feature flag: the setting is opt-in per target.
The rules, and why:
- The client’s marks win. A request that carries any mark gets no automatic point. Adding points next to the client’s could pass the four-point limit or break the TTL order, and the client knows its own stable prefix better.
- Only where the prefix can be cached. Each point needs the whole prompt before it (tools, then system, then messages) to reach the model’s minimum. The gateway does not tokenize: it counts the serialized prefix at three UTF-8 bytes per token, which overestimates most text (English runs near four), so a point is skipped only when the prefix is clearly too short. A point placed on a prefix that turns out shorter costs nothing: the provider answers without caching and without an error.
- The history point is the conversation before the final turn. Placed there, the next turn of the same conversation reads everything up to it, and the current question, which changes every time, is never written to the cache.
last_messagealso caches the final turn, which pays the write premium on every request and only helps when the same request, or a longer one built on it, comes back within the TTL: an agent loop, or a prompt that ends with a large stable document. - Writes cost more than reads save on a single call. A five-minute write bills at 1.25× the input price and a one-hour write at 2×; a read at 0.1× (0.05× or 0.025× on some models). A prefix used twice within five minutes already pays off at
5m;1hneeds at least three uses and only helps when uses are more than five minutes apart.
The attempt’s upstream_attempt log names prompt_cache_points (how many points were placed) when automatic points were added; every other attempt keeps its log fields.
Minimum cacheable prefix
Section titled “Minimum cacheable prefix”| Models | Claude API | Bedrock |
|---|---|---|
| Claude Fable 5.1, Mythos 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5, Mythos 5, Opus 5 | 512 | 512 |
| Claude Opus 4.8, Sonnet 5, Sonnet 4.6, Sonnet 4.5, Opus 4.1, Opus 4, Sonnet 4 | 1,024 | 1,024 |
| Claude Mythos Preview | 2,048 | 2,048 |
| Claude Opus 4.7 | 2,048 | 4,096 |
| Claude Opus 4.6, Opus 4.5, Haiku 4.5 | 4,096 | 4,096 |
| Any other model | 4,096 | 4,096 |
Sources, read on 2026-11-08: the Claude prompt caching guide (“Cache limitations”: minimums, four breakpoints, TTL order, empty text blocks, prices) and the Bedrock prompt caching guide (“Supported models, Regions, and explicit caching limits”: minimums, four checkpoints, cachePoint with ttl). A model ID matches a family exactly or followed by a date (-20251101), a version (-v1:0, @20251101) or a context tag ([1m]), so claude-opus-5 never matches claude-opus-5-5. A model the table does not know takes the largest documented minimum; set min_prefix_tokens for a new model.
Cost and measurement
Section titled “Cost and measurement”The cache counters the provider reports are what the gateway measures, never an estimate:
- The Chat Completions answer reports cached reads in
usage.prompt_tokens_details.cached_tokensand writes incache_creation_tokens, both insideprompt_tokens. - The usage valuation and budgets price reads, five-minute writes and one-hour writes each at its own price, from the provider’s own answer: Anthropic’s
cache_creationbreakdown and Bedrock’scacheDetails. Without a published price for a category the cost stays unknown, never priced as plain input. A request that carriescache_control(a mark of the two supported TTLs) is valued and fits the chat budget profile when its target is Claude, whose answer splits the writes by TTL. On an OpenAI Chat Completions passthrough, whose answer reports writes without a TTL, a marked request stays unknown and outside the budget profile, as before: a one-hour write could otherwise be priced as a five-minute one. - The request event carries
tokens.cache_readandtokens.cache_write.
Measured on 2026-11-08 with the native binary, PostgreSQL 16.15 and claude-haiku-5-5 (input $0.10, output $0.50, cache read $0.01, five-minute write $0.125, one-hour write $0.20 per million tokens), a Chat Completions request with a 14,000-token system prompt, sent twice:
| Request | Cache write | Cache read | Valued cost |
|---|---|---|---|
| Client mark, first call | 14,013 (5m) | 0 | $0.001755725 |
| Client mark, second call | 0 | 14,013 | $0.000144230 |
prompt_cache: {mode: auto, ttl: 1h}, first call |
14,014 (1h) | 0 | $0.002806900 |
| Same, second call | 0 | 14,014 | $0.000144240 |
Uncached, the same request costs about $0.001406: the second call costs about a tenth of that, and the first pays the write premium.
Upgrade notes
Section titled “Upgrade notes”- A Chat Completions client that already sent
cache_controlto a Claude target now gets it honored, and a malformed one, which was ignored before, is refused with 422 on that target. On a target that cannot use marks they are removed without being checked. - A Messages client on an alias translated to Bedrock or to an OpenAI target no longer sees
cache_controlinX-Gateway-Translation-Lossywhen the target is Claude; it still does for any other target. - A multi-part system or assistant message with a marked part reaches Anthropic as one block per part instead of one joined block.
- Nothing changes for a target without
prompt_cacheand a request without marks.
Limits
Section titled “Limits”prompt_cache_key(the OpenAI Responses hint) and Gemini’scachedContentare not Claude cache marks: the first is still left out and announced, the second still refused.- Automatic points are not added to native
/v1/messagespassthrough requests: the gateway does not rewrite a native body.prompt_cacheon amessagesalias whose targets are all Anthropic is accepted but has no effect, since every request there is native. - On Bedrock, marks and automatic points need a model ID that names Claude; an application inference profile ARN that does not is treated as another model.
- A Messages assistant turn with a marked text block keeps its text blocks apart in the canonical format; a target that cannot use the mark then receives those blocks joined by a newline, where an unmarked turn joins them directly.
- The prefix estimate is not a tokenizer: near the minimum, a point may be placed on a prefix the provider then does not cache (at no cost), or skipped on one it would have cached.