Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Prompt Caching Support in Spring AI with Anthropic Claude: Configuration, Strategies, and Verification

How to enable Claude prompt caching in Spring AI, pick a strategy for stable context, confirm cache reads in usage metadata, and avoid stale pre-2.0 examples.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Spring AI can turn on Anthropic Claude prompt caching through a single option: a cache strategy (NONE, SYSTEM_ONLY, TOOLS_ONLY, SYSTEM_AND_TOOLS or CONVERSATION_HISTORY). It is off by default. Support began with Spring AI 1.1, and the current reference covers Spring AI 2.0.1. Setting a strategy does not guarantee a cache hit, so the useful skill is choosing the strategy that matches your stable prefix and then confirming reuse in the response’s usage metadata.

Version context before you copy any example

The Anthropic starter is org.springframework.ai:spring-ai-starter-model-anthropic. Spring AI documents a BOM for aligning dependency versions, so import the BOM that matches the release you build against. Settings live under the spring.ai.anthropic.* prefix, including the API key and chat options.

As an Amazon Associate I earn from qualifying purchases.

Prompt caching was announced with Spring AI 1.1 (the 1.1 GA release announcement covers Anthropic Claude and AWS Bedrock). The current reference describes 2.0.1, and the two are not interchangeable in code:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • In the 2.0.0-M3 milestone, the Anthropic integration was rewritten on the official Anthropic Java SDK.
  • Per Spring’s migration guide, the starter, Maven coordinates, property prefix and ChatClient API are preserved.
  • Direct constructors and the old AnthropicApi DTOs were removed.
  • Cache helper types moved from the .api package to org.springframework.ai.anthropic, so imports copied from older tutorials will fail on 2.0.x.
  • The default maxTokens changed from 500 to 4096. That affects output length, and it also affects cache timing (see below).

How to configure caching

There are two documented property keys, both under spring.ai.anthropic.chat.cache-options:

#1 Best Overall
  • strategy, default NONE
  • multi-block-system-caching, default false
spring.ai.anthropic.chat.cache-options.strategy=SYSTEM_ONLY
spring.ai.anthropic.chat.cache-options.multi-block-system-caching=false

In code, AnthropicChatOptions can carry an AnthropicCacheOptions object, which lets you set the strategy per request rather than globally. Check the exact builder methods against the reference for your version, since the helper types moved in 2.0.

Other documented options: per-message-type TTL (FIVE_MINUTES or ONE_HOUR), a minimum content length, a custom content-length function, and optional tool-result caching when you use conversation-history caching.

Choosing a strategy

Pick the strategy by asking which part of the request is identical from one call to the next.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Strategy What is cached Fits when
NONE Nothing (default) Prompts are short, unique per request, or rarely repeated
SYSTEM_ONLY System-message content A large, stable system prompt and few or no tools
TOOLS_ONLY Tool definitions Large tool schemas, with a system prompt that varies
SYSTEM_AND_TOOLS System content and tool definitions Agents with both a stable system prompt and a stable tool set
CONVERSATION_HISTORY Broader conversation context, up to four breakpoints Long multi-turn chats where earlier turns are resent each time

If your system message mixes a static portion with request-specific instructions, a single combined block changes whenever the dynamic part changes, which breaks the match. Spring AI’s multi-block system caching lets the static part be cached as its own block. Enable it with multi-block-system-caching=true and keep the static text first.

Content must also qualify. Anthropic caches repeated prefixes, so the cached portion must match exactly and be long enough; Spring AI exposes a minimum content length option for this reason.

TTL and timing

Two TTLs are documented: five minutes (the default) and one hour. Anthropic measures lifetime from the start of the request that writes or reads the entry, so time spent generating a response counts against the window. A long answer leaves less time for a follow-up. Anthropic says a cache hit refreshes the entry at no additional cost.

Choose five minutes when the same prefix is hit frequently. Consider one hour when reuse is sporadic, but weigh the higher write price (below).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The four-breakpoint limit

Anthropic allows at most four cache breakpoints per prompt. The Spring AI 2.0 implementation tracks breakpoint use and skips additional markers after four, logging a one-time warning. The migration guide notes a behavioral consequence: a request that might previously have failed at the API now succeeds with reduced caching. After upgrading, check your hit rate rather than assuming it survived. Combining CONVERSATION_HISTORY, multi-block system caching and tool-result caching is the easiest way to reach the ceiling.

Anthropic’s documentation states that prompt caching is supported on all active Claude models. That list changes, so confirm your chosen model against Anthropic’s current page.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verifying that caching works

Spring AI documents reaching the native Anthropic SDK Usage object through response metadata. Two fields matter:

  • cacheCreationInputTokens() non-zero: content was written to the cache.
  • cacheReadInputTokens() non-zero: previously cached content was reused.

A practical check:

  1. Enable a strategy and send a request with a long, stable prefix. Expect creation tokens above zero.
  2. Send a second request with the identical prefix inside the TTL. Expect read tokens above zero.
  3. If both stay at zero, check the prefix for hidden variation (timestamps, IDs, reordered tools), the minimum length, the model, and whether the TTL lapsed.
  4. If creation tokens appear on every call, the prefix is changing between requests or the entry is expiring before reuse.

Log these two values in production. After any Spring AI upgrade, compare them again, given the breakpoint behavior above.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reading the cost claims

Anthropic’s current documentation prices five-minute cache writes at 25% above base input-token price and one-hour writes at 2× base input price. Cache hits use a lower multiplier that varies by model, so check the current pricing table before quoting a rate. A write costs more than uncached input; savings appear only when the entry is read enough times within its TTL.

Published savings figures are best-case descriptions of the cached portion. Spring’s 1.1 announcement says caching can reduce costs “by up to 90% while improving response times”, which is Spring’s claim, not a guaranteed result. Spring’s October 2025 implementation guide works an example showing a 68% reduction for the cached system-prompt portion, and it notes that user-question and output tokens are not cached, so total savings are lower. Your result depends on the share of input that is cacheable, how often it is reused within the TTL, the model’s pricing, and how much spend is output.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.