Add prompt-caching module: Spring AI 2.1 Anthropic cache strategies on the real request (breakpoints per strategy, hit/miss/write in Usage, one changed word, multi-block system caching, minimum length, 5-minute and 1-hour lifetimes, the 20-block lookback), OpenAI automatic caching with prompt_cache_key, and a cost table. The vendors are a local server applying their documented rules; no vendor API called. Spring Boot 4.2.0, Spring AI 2.1.0, Java 25.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4gvXXQgw1eTk5EoTT
This commit is contained in:
Claude
2026-11-24 06:07:23 +05:30
parent 45d83826da
commit 02c3cbf439
32 changed files with 1759 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
# Cost of 1,000 requests: a 24,000-character policy + 4 tools + 2 retrieved chunks + a question, 150 output tokens (list prices 2026-11-24)
A. claude-sonnet-5-5: the same 300 requests, arriving every N seconds (cost per 1,000 requests)
gap setup plain read write dollars vs none
20 s no caching 2,187k 0k 0k $16.08
SYSTEM_AND_TOOLS, 5 minutes 198k 1,982k 7k $3.54 -78%
SYSTEM_AND_TOOLS, 1 hour 198k 1,982k 7k $3.57 -78%
CONVERSATION_HISTORY, 5 minutes 0k 1,982k 205k $3.87 -76%
240 s no caching 2,187k 0k 0k $16.08
SYSTEM_AND_TOOLS, 5 minutes 198k 1,982k 7k $3.54 -78%
SYSTEM_AND_TOOLS, 1 hour 198k 1,982k 7k $3.57 -78%
CONVERSATION_HISTORY, 5 minutes 0k 1,982k 205k $3.87 -76%
301 s no caching 2,187k 0k 0k $16.08
SYSTEM_AND_TOOLS, 5 minutes 198k 0k 1,988k $19.39 +21%
SYSTEM_AND_TOOLS, 1 hour 198k 1,982k 7k $3.57 -78%
CONVERSATION_HISTORY, 5 minutes 0k 0k 2,187k $19.72 +23%
3700 s no caching 2,187k 0k 0k $16.08
SYSTEM_AND_TOOLS, 5 minutes 198k 0k 1,988k $19.39 +21%
SYSTEM_AND_TOOLS, 1 hour 198k 0k 1,988k $29.33 +82%
CONVERSATION_HISTORY, 5 minutes 0k 0k 2,187k $19.72 +23%
B. The same requests every 20 seconds, per model (SYSTEM_AND_TOOLS with the 5-minute lifetime for Anthropic)
model no caching cached saving
claude-haiku-5-5 $0.80 $0.21 -74%
claude-sonnet-5-5 $16.08 $3.54 -78%
claude-opus-5-5 $32.15 $7.07 -78%
gpt-6.2-sol $16.35 $3.54 -78% (OpenAI: automatic; 'no caching' = every request sent with a changing first message)
C. How many hits inside the lifetime does a write pay back? hits = (write multiple - 1) / (1 - read multiple)
model write 5m read hits (5m) hits (1h)
claude-haiku-5-5 1.25x 0.100x 0.28 1.11
claude-sonnet-5-5 1.25x 0.050x 0.26 1.05
claude-opus-5-5 1.25x 0.050x 0.26 1.05