Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteSpring 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:
- 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
ChatClientAPI are preserved. - Direct constructors and the old
AnthropicApiDTOs were removed. - Cache helper types moved from the
.apipackage toorg.springframework.ai.anthropic, so imports copied from older tutorials will fail on 2.0.x. - The default
maxTokenschanged 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, defaultNONEmulti-block-system-caching, defaultfalse
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.
| 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.
Rank #4
Choose five minutes when the same prefix is hit frequently. Consider one hour when reuse is sporadic, but weigh the higher write price (below).
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11The 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.
Best Value
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.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:
- Enable a strategy and send a request with a long, stable prefix. Expect creation tokens above zero.
- Send a second request with the identical prefix inside the TTL. Expect read tokens above zero.
- 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.
- 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.
Recommended Free Tools
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.
Quick Recap
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.




