Request 2 caches its request content (not the response) changedbuild-with-claude/prompt-caching
Nearest release: v2.1.309, published 3 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+229added
Lines−225removed
From line
133
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits29to this page, all time
The whole hunk
from line 133, old and new numbered
/
The two sides of this change are more than 400 edits apart, too far apart to line up, so this is the differ's own diff of it and the words inside a line are not marked.
from line 133
133133 // ...
134134 public class PromptCachingExample {
135135
136 public static void main(String[] args) {
137 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
138
139 MessageCreateParams params = MessageCreateParams.builder()
140 .model(Model.CLAUDE_OPUS_5_5)
141 .maxTokens(1024)
142 .cacheControl(CacheControlEphemeral.builder().build())
143 .system("You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.")
144 .addUserMessage("Analyze the major themes in 'Pride and Prejudice'.")
145 .build();
146
147 Message message = client.messages().create(params);
148 System.out.println(message.usage());
149 }
136 public static void main(String[] args) {
137 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
138
139 MessageCreateParams params = MessageCreateParams.builder()
140 .model(Model.CLAUDE_OPUS_5_5)
141 .maxTokens(1024)
142 .cacheControl(CacheControlEphemeral.builder().build())
143 .system("You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.")
144 .addUserMessage("Analyze the major themes in 'Pride and Prejudice'.")
145 .build();
146
147 Message message = client.messages().create(params);
148 System.out.println(message.usage());
149 }
150150 }
151151 ```
152152
153153 ```php PHP
154154 use Anthropic\Messages\CacheControlEphemeral;
155 use Anthropic\Messages\Model;
155156 // ...
156157 $client = new Client();
157158
from line 161
160161 messages: [
161162 ['role' => 'user', 'content' => "Analyze the major themes in 'Pride and Prejudice'."]
162163 ],
163 model: 'claude-opus-5-5',
164 model: Model::CLAUDE_OPUS_5_5,
164165 cacheControl: CacheControlEphemeral::with(),
165 system: "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
166 system: 'You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.',
166167 );
167168 echo json_encode($response->usage);
168169 ```
from line 411
410411 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
411412
412413 MessageCreateParams params = MessageCreateParams.builder()
413 .model(Model.CLAUDE_OPUS_5_5)
414 .maxTokens(1024)
415 .cacheControl(CacheControlEphemeral.builder().build())
416 .system("You are a helpful assistant that remembers our conversation.")
417 .addUserMessage("My name is Alex. I work on machine learning.")
418 .addAssistantMessage("Nice to meet you, Alex! How can I help with your ML work today?")
419 .addUserMessage("What did I say I work on?")
420 .build();
414 .model(Model.CLAUDE_OPUS_5_5)
415 .maxTokens(1024)
416 .cacheControl(CacheControlEphemeral.builder().build())
417 .system("You are a helpful assistant that remembers our conversation.")
418 .addUserMessage("My name is Alex. I work on machine learning.")
419 .addAssistantMessage("Nice to meet you, Alex! How can I help with your ML work today?")
420 .addUserMessage("What did I say I work on?")
421 .build();
421422
422423 Message message = client.messages().create(params);
423424 System.out.println(message.usage());
from line 428
427428
428429 ```php PHP
429430 use Anthropic\Messages\CacheControlEphemeral;
431 use Anthropic\Messages\Model;
430432 // ...
431433 $client = new Client();
432434
from line 439
437439 ['role' => 'assistant', 'content' => 'Nice to meet you, Alex! How can I help with your ML work today?'],
438440 ['role' => 'user', 'content' => 'What did I say I work on?'],
439441 ],
440 model: 'claude-opus-5-5',
442 model: Model::CLAUDE_OPUS_5_5,
441443 cacheControl: CacheControlEphemeral::with(),
442444 system: 'You are a helpful assistant that remembers our conversation.',
443445 );
from line 603
601603
602604These minimums apply on every platform where each model is available.
603605
604Shorter prompts cannot be cached, even if marked with `cache_control`. Any requests to cache fewer than this number of tokens are processed without caching, and no error is returned. To verify whether a prompt was cached, check the [response usage fields](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#tracking-cache-performance): if both `cache_creation_input_tokens` and `cache_read_input_tokens` are 0, the prompt was not cached (likely because it did not meet the minimum length requirement).
606Shorter prompts cannot be cached, even if marked with `cache_control`. Any requests to cache fewer than this number of tokens are processed without caching, and no error is returned. To check whether a prompt was cached, look at the [response usage fields](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#tracking-cache-performance): if both `cache_creation_input_tokens` and `cache_read_input_tokens` are 0, the prompt was not cached (likely because it did not meet the minimum length requirement).
605607
606608If your prompt falls just short of the minimum for your model and platform, expanding the cached content to reach the threshold is often worthwhile. Cache reads cost significantly less than uncached input tokens, so reaching the minimum can reduce costs for frequently reused prompts.
607609
from line 748
746748### Cache storage and sharing
747749
748750<Warning>
749 Prompt caching uses [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces)-level isolation. Caches are isolated per workspace, ensuring data separation between workspaces within the same organization. This applies to the Claude API, Claude Platform on AWS, and Microsoft Foundry; Bedrock and Claude Models on Google Cloud (Google managed) maintain organization-level cache isolation. If you use multiple workspaces, review your caching strategy to account for this difference.
751 Prompt caching uses [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces)-level isolation. Caches are isolated by workspace, ensuring data separation between workspaces within the same organization. This applies to the Claude API, Claude Platform on AWS, and Microsoft Foundry; Bedrock and Claude Models on Google Cloud (Google managed) maintain organization-level cache isolation. If you use multiple workspaces, review your caching strategy to account for this difference.
750752</Warning>
751753
752* **Organization and workspace isolation:** Caches are isolated between organizations. Different organizations never share caches, even if they use identical prompts. Caches are also isolated per workspace within an organization on the Claude API, Claude Platform on AWS, and Microsoft Foundry; Bedrock and Claude Models on Google Cloud (Google managed) use organization-level isolation only.
754* **Organization and workspace isolation:** Caches are isolated between organizations. Different organizations never share caches, even if they use identical prompts. Caches are also isolated by workspace within an organization on the Claude API, Claude Platform on AWS, and Microsoft Foundry; Bedrock and Claude Models on Google Cloud (Google managed) use organization-level isolation only.
753755
754756* **Exact matching:** Cache hits require 100 percent identical prompt segments, including all text and images up to and including the block marked with cache control.
755757
from line 1031
10291031 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
10301032
10311033 Message prewarm = client.messages().create(MessageCreateParams.builder()
1032 .model(Model.CLAUDE_OPUS_5_5)
1033 .maxTokens(0)
1034 .systemOfTextBlockParams(List.of(TextBlockParam.builder()
1035 .text("You are an expert software engineer with deep knowledge of distributed systems...")
1036 .cacheControl(CacheControlEphemeral.builder().build())
1037 .build()))
1038 .addUserMessage("warmup")
1039 .build());
1034 .model(Model.CLAUDE_OPUS_5_5)
1035 .maxTokens(0)
1036 .systemOfTextBlockParams(List.of(TextBlockParam.builder()
1037 .text("You are an expert software engineer with deep knowledge of distributed systems...")
1038 .cacheControl(CacheControlEphemeral.builder().build())
1039 .build()))
1040 .addUserMessage("warmup")
1041 .build());
10401042
10411043 IO.println(prewarm.stopReason()); // Optional[max_tokens]
10421044 IO.println(prewarm.content()); // []
from line 1394
13921394 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
13931395
13941396 List<TextBlockParam> systemPrompt = List.of(TextBlockParam.builder()
1395 .text("You are an expert software engineer with deep knowledge of distributed systems...")
1396 .cacheControl(CacheControlEphemeral.builder().build())
1397 .build());
1397 .text("You are an expert software engineer with deep knowledge of distributed systems...")
1398 .cacheControl(CacheControlEphemeral.builder().build())
1399 .build());
13981400
13991401 // Call this at application startup or on a scheduled interval.
14001402 void prewarmCache() {
14011403 client.messages().create(MessageCreateParams.builder()
1402 .model(Model.CLAUDE_OPUS_5_5)
1403 .maxTokens(0)
1404 .systemOfTextBlockParams(systemPrompt)
1405 .addUserMessage("warmup")
1406 .build());
1404 .model(Model.CLAUDE_OPUS_5_5)
1405 .maxTokens(0)
1406 .systemOfTextBlockParams(systemPrompt)
1407 .addUserMessage("warmup")
1408 .build());
14071409 }
14081410
14091411 // The real user request; benefits from a warm cache.
14101412 Message respond(String userMessage) {
14111413 return client.messages().create(MessageCreateParams.builder()
1412 .model(Model.CLAUDE_OPUS_5_5)
1413 .maxTokens(1024)
1414 .systemOfTextBlockParams(systemPrompt)
1415 .addUserMessage(userMessage)
1416 .build());
1414 .model(Model.CLAUDE_OPUS_5_5)
1415 .maxTokens(1024)
1416 .systemOfTextBlockParams(systemPrompt)
1417 .addUserMessage(userMessage)
1418 .build());
14171419 }
14181420
14191421 void main() {
from line 1425
14231425 // Later, when the user submits a message, the system-prompt prefix is already cached.
14241426 Message response = respond("How do I implement a binary search tree?");
14251427 response.content().stream()
1426 .flatMap(block -> block.text().stream())
1427 .forEach(textBlock -> IO.println(textBlock.text()));
1428 .flatMap(block -> block.text().stream())
1429 .forEach(textBlock -> IO.println(textBlock.text()));
14281430 }
14291431 ```
14301432
from line 1705
17031705 // ...
17041706 public class LegalDocumentAnalysisExample {
17051707
1706 public static void main(String[] args) {
1707 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
1708
1709 MessageCreateParams params = MessageCreateParams.builder()
1710 .model(Model.CLAUDE_OPUS_5_5)
1711 .maxTokens(1024)
1712 .systemOfTextBlockParams(
1713 List.of(
1714 TextBlockParam.builder()
1715 .text("You are an AI assistant tasked with analyzing legal documents.")
1716 .build(),
1717 TextBlockParam.builder()
1718 .text(
1719 "Here is the full text of a complex legal agreement: [Insert full text of a 50-page legal agreement here]"
1708 public static void main(String[] args) {
1709 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
1710
1711 MessageCreateParams params = MessageCreateParams.builder()
1712 .model(Model.CLAUDE_OPUS_5_5)
1713 .maxTokens(1024)
1714 .systemOfTextBlockParams(
1715 List.of(
1716 TextBlockParam.builder()
1717 .text("You are an AI assistant tasked with analyzing legal documents.")
1718 .build(),
1719 TextBlockParam.builder()
1720 .text(
1721 "Here is the full text of a complex legal agreement: [Insert full text of a 50-page legal agreement here]"
1722 )
1723 .cacheControl(CacheControlEphemeral.builder().build())
1724 .build()
1725 )
17201726 )
1721 .cacheControl(CacheControlEphemeral.builder().build())
1722 .build()
1723 )
1724 )
1725 .addUserMessage("What are the key terms and conditions in this agreement?")
1726 .build();
1727
1728 Message message = client.messages().create(params);
1729 System.out.println(message.usage());
1730 }
1727 .addUserMessage("What are the key terms and conditions in this agreement?")
1728 .build();
1729
1730 Message message = client.messages().create(params);
1731 System.out.println(message.usage());
1732 }
17311733 }
17321734 ```
17331735
from line 1744
17421744 'content' => 'What are the key terms and conditions in this agreement?'
17431745 ]
17441746 ],
1745 model: 'claude-opus-5-5',
1747 model: Model::CLAUDE_OPUS_5_5,
17461748 system: [
17471749 [
17481750 'type' => 'text',
from line 2098
20962098 // ...
20972099 public class ConversationWithCacheControlExample {
20982100
2099 public static void main(String[] args) {
2100 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
2101
2102 // Create ephemeral system prompt
2103 TextBlockParam systemPrompt = TextBlockParam.builder()
2104 .text("...long system prompt")
2105 .cacheControl(CacheControlEphemeral.builder().build())
2106 .build();
2107
2108 // Create message params
2109 MessageCreateParams params = MessageCreateParams.builder()
2110 .model(Model.CLAUDE_OPUS_5_5)
2111 .maxTokens(1024)
2112 .systemOfTextBlockParams(List.of(systemPrompt))
2113 // First user message (without cache control)
2114 .addUserMessage("Hello, can you tell me more about the solar system?")
2115 // Assistant response
2116 .addAssistantMessage(
2117 "Certainly! The solar system is the collection of celestial bodies that orbit our Sun. It consists of eight planets, numerous moons, asteroids, comets, and other objects. The planets, in order from closest to farthest from the Sun, are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. Each planet has its own unique characteristics and features. Is there a specific aspect of the solar system you would like to know more about?"
2118 )
2119 // Second user message (with cache control)
2120 .addUserMessageOfContentBlockParams(
2121 List.of(
2122 ContentBlockParam.ofText(TextBlockParam.builder().text("Good to know.").build()),
2123 ContentBlockParam.ofText(
2124 TextBlockParam.builder()
2125 .text("Tell me more about Mars.")
2126 .cacheControl(CacheControlEphemeral.builder().build())
2127 .build()
2128 )
2129 )
2130 )
2131 .build();
2132
2133 Message message = client.messages().create(params);
2134 System.out.println(message.usage());
2135 }
2101 public static void main(String[] args) {
2102 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
2103
2104 // Create ephemeral system prompt
2105 TextBlockParam systemPrompt = TextBlockParam.builder()
2106 .text("...long system prompt")
2107 .cacheControl(CacheControlEphemeral.builder().build())
2108 .build();
2109
2110 // Create message params
2111 MessageCreateParams params = MessageCreateParams.builder()
2112 .model(Model.CLAUDE_OPUS_5_5)
2113 .maxTokens(1024)
2114 .systemOfTextBlockParams(List.of(systemPrompt))
2115 // First user message (without cache control)
2116 .addUserMessage("Hello, can you tell me more about the solar system?")
2117 // Assistant response
2118 .addAssistantMessage(
2119 "Certainly! The solar system is the collection of celestial bodies that orbit our Sun. It consists of eight planets, numerous moons, asteroids, comets, and other objects. The planets, in order from closest to farthest from the Sun, are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. Each planet has its own unique characteristics and features. Is there a specific aspect of the solar system you would like to know more about?"
2120 )
2121 // Second user message (with cache control)
2122 .addUserMessageOfContentBlockParams(
2123 List.of(
2124 ContentBlockParam.ofText(TextBlockParam.builder()
2125 .text("Good to know.")
2126 .build()),
2127 ContentBlockParam.ofText(
2128 TextBlockParam.builder()
2129 .text("Tell me more about Mars.")
2130 .cacheControl(CacheControlEphemeral.builder().build())
2131 .build()
2132 )
2133 )
2134 )
2135 .build();
2136
2137 Message message = client.messages().create(params);
2138 System.out.println(message.usage());
2139 }
21362140 }
21372141 ```
21382142
from line 2157
21532157 ],
21542158 [
21552159 'role' => 'assistant',
2156 'content' => "Certainly! The solar system is the collection of celestial bodies that orbit our Sun. It consists of eight planets, numerous moons, asteroids, comets, and other objects. The planets, in order from closest to farthest from the Sun, are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. Each planet has its own unique characteristics and features. Is there a specific aspect of the solar system you would like to know more about?"
2160 'content' => 'Certainly! The solar system is the collection of celestial bodies that orbit our Sun. It consists of eight planets, numerous moons, asteroids, comets, and other objects. The planets, in order from closest to farthest from the Sun, are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. Each planet has its own unique characteristics and features. Is there a specific aspect of the solar system you would like to know more about?'
21572161 ],
21582162 [
21592163 'role' => 'user',
from line 2171
21672171 ]
21682172 ]
21692173 ],
2170 model: 'claude-opus-5-5',
2174 model: Model::CLAUDE_OPUS_5_5,
21712175 system: [
21722176 [
21732177 'type' => 'text',
from line 2805
28012805 // ...
28022806 public class MultipleCacheBreakpointsExample {
28032807
2804 public static void main(String[] args) {
2805 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
2806
2807 // Search tool schema
2808 InputSchema searchSchema = InputSchema.builder()
2809 .properties(
2810 JsonValue.from(
2811 Map.of("query", Map.of("type", "string", "description", "Search query"))
2812 )
2813 )
2814 .putAdditionalProperty("required", JsonValue.from(List.of("query")))
2815 .build();
2816
2817 // Get document tool schema
2818 InputSchema getDocSchema = InputSchema.builder()
2819 .properties(
2820 JsonValue.from(
2821 Map.of("doc_id", Map.of("type", "string", "description", "Document ID"))
2822 )
2823 )
2824 .putAdditionalProperty("required", JsonValue.from(List.of("doc_id")))
2825 .build();
2826
2827 MessageCreateParams params = MessageCreateParams.builder()
2828 .model(Model.CLAUDE_OPUS_5_5)
2829 .maxTokens(1024)
2830 // Tools with cache control on the last one
2831 .addTool(
2832 Tool.builder()
2833 .name("search_documents")
2834 .description("Search through the knowledge base")
2835 .inputSchema(searchSchema)
2836 .build()
2837 )
2838 .addTool(
2839 Tool.builder()
2840 .name("get_document")
2841 .description("Retrieve a specific document by ID")
2842 .inputSchema(getDocSchema)
2843 .cacheControl(CacheControlEphemeral.builder().build())
2844 .build()
2845 )
2846 // System prompts with cache control on instructions and context separately
2847 .systemOfTextBlockParams(
2848 List.of(
2849 TextBlockParam.builder()
2850 .text(
2851 "You are a helpful research assistant with access to a document knowledge base.\n\n# Instructions\n- Always search for relevant documents before answering\n- Provide citations for your sources\n- Be objective and accurate in your responses\n- If multiple documents contain relevant information, synthesize them\n- Acknowledge when information is not available in the knowledge base"
2808 public static void main(String[] args) {
2809 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
2810
2811 // Search tool schema
2812 InputSchema searchSchema = InputSchema.builder()
2813 .properties(
2814 JsonValue.from(
2815 Map.of("query", Map.of("type", "string", "description", "Search query"))
2816 )
28522817 )
2853 .cacheControl(CacheControlEphemeral.builder().build())
2854 .build(),
2855 TextBlockParam.builder()
2856 .text(
2857 "# Knowledge Base Context\n\nHere are the relevant documents for this conversation:\n\n## Document 1: Solar System Overview\nThe solar system consists of the Sun and all objects that orbit it...\n\n## Document 2: Planetary Characteristics\nEach planet has unique features. Mercury is the smallest planet...\n\n## Document 3: Mars Exploration\nMars has been a target of exploration for decades...\n\n[Additional documents...]"
2818 .putAdditionalProperty("required", JsonValue.from(List.of("query")))
2819 .build();
2820
2821 // Get document tool schema
2822 InputSchema getDocSchema = InputSchema.builder()
2823 .properties(
2824 JsonValue.from(
2825 Map.of("doc_id", Map.of("type", "string", "description", "Document ID"))
2826 )
28582827 )
2859 .cacheControl(CacheControlEphemeral.builder().build())
2860 .build()
2861 )
2862 )
2863 // Conversation history
2864 .addUserMessage("Can you search for information about Mars rovers?")
2865 .addAssistantMessageOfContentBlockParams(
2866 List.of(
2867 ContentBlockParam.ofToolUse(
2868 ToolUseBlockParam.builder()
2869 .id("tool_1")
2870 .name("search_documents")
2871 .input(JsonValue.from(Map.of("query", "Mars rovers")))
2872 .build()
2873 )
2874 )
2875 )
2876 .addUserMessageOfContentBlockParams(
2877 List.of(
2878 ContentBlockParam.ofToolResult(
2879 ToolResultBlockParam.builder()
2880 .toolUseId("tool_1")
2881 .content(
2882 "Found 3 relevant documents: Document 3 (Mars Exploration), Document 7 (Rover Technology), Document 9 (Mission History)"
2883 )
2884 .build()
2885 )
2886 )
2887 )
2888 .addAssistantMessageOfContentBlockParams(
2889 List.of(
2890 ContentBlockParam.ofText(
2891 TextBlockParam.builder()
2892 .text(
2893 "I found 3 relevant documents about Mars rovers. Let me get more details from the Mars Exploration document."
2894 )
2895 .build()
2896 )
2897 )
2898 )
2899 .addUserMessageOfContentBlockParams(
2900 List.of(
2901 ContentBlockParam.ofText(
2902 TextBlockParam.builder()
2903 .text("Yes, please tell me about the Perseverance rover specifically.")
2904 .cacheControl(CacheControlEphemeral.builder().build())
2905 .build()
2906 )
2907 )
2908 )
2909 .build();
2910
2911 Message message = client.messages().create(params);
2912 System.out.println(message.usage());
2913 }
2828 .putAdditionalProperty("required", JsonValue.from(List.of("doc_id")))
2829 .build();
2830
2831 MessageCreateParams params = MessageCreateParams.builder()
2832 .model(Model.CLAUDE_OPUS_5_5)
2833 .maxTokens(1024)
2834 // Tools with cache control on the last one
2835 .addTool(
2836 Tool.builder()
2837 .name("search_documents")
2838 .description("Search through the knowledge base")
2839 .inputSchema(searchSchema)
2840 .build()
2841 )
2842 .addTool(
2843 Tool.builder()
2844 .name("get_document")
2845 .description("Retrieve a specific document by ID")
2846 .inputSchema(getDocSchema)
2847 .cacheControl(CacheControlEphemeral.builder().build())
2848 .build()
2849 )
2850 // System prompts with cache control on instructions and context separately
2851 .systemOfTextBlockParams(
2852 List.of(
2853 TextBlockParam.builder()
2854 .text(
2855 "You are a helpful research assistant with access to a document knowledge base.\n\n# Instructions\n- Always search for relevant documents before answering\n- Provide citations for your sources\n- Be objective and accurate in your responses\n- If multiple documents contain relevant information, synthesize them\n- Acknowledge when information is not available in the knowledge base"
2856 )
2857 .cacheControl(CacheControlEphemeral.builder().build())
2858 .build(),
2859 TextBlockParam.builder()
2860 .text(
2861 "# Knowledge Base Context\n\nHere are the relevant documents for this conversation:\n\n## Document 1: Solar System Overview\nThe solar system consists of the Sun and all objects that orbit it...\n\n## Document 2: Planetary Characteristics\nEach planet has unique features. Mercury is the smallest planet...\n\n## Document 3: Mars Exploration\nMars has been a target of exploration for decades...\n\n[Additional documents...]"
2862 )
2863 .cacheControl(CacheControlEphemeral.builder().build())
2864 .build()
2865 )
2866 )
2867 // Conversation history
2868 .addUserMessage("Can you search for information about Mars rovers?")
2869 .addAssistantMessageOfContentBlockParams(
2870 List.of(
2871 ContentBlockParam.ofToolUse(
2872 ToolUseBlockParam.builder()
2873 .id("tool_1")
2874 .name("search_documents")
2875 .input(JsonValue.from(Map.of("query", "Mars rovers")))
2876 .build()
2877 )
2878 )
2879 )
2880 .addUserMessageOfContentBlockParams(
2881 List.of(
2882 ContentBlockParam.ofToolResult(
2883 ToolResultBlockParam.builder()
2884 .toolUseId("tool_1")
2885 .content(
2886 "Found 3 relevant documents: Document 3 (Mars Exploration), Document 7 (Rover Technology), Document 9 (Mission History)"
2887 )
2888 .build()
2889 )
2890 )
2891 )
2892 .addAssistantMessageOfContentBlockParams(
2893 List.of(
2894 ContentBlockParam.ofText(
2895 TextBlockParam.builder()
2896 .text(
2897 "I found 3 relevant documents about Mars rovers. Let me get more details from the Mars Exploration document."
2898 )
2899 .build()
2900 )
2901 )
2902 )
2903 .addUserMessageOfContentBlockParams(
2904 List.of(
2905 ContentBlockParam.ofText(
2906 TextBlockParam.builder()
2907 .text("Yes, please tell me about the Perseverance rover specifically.")
2908 .cacheControl(CacheControlEphemeral.builder().build())
2909 .build()
2910 )
2911 )
2912 )
2913 .build();
2914
2915 Message message = client.messages().create(params);
2916 System.out.println(message.usage());
2917 }
29142918 }
29152919 ```
29162920
from line 2969
29652969 ]
29662970 ]
29672971 ],
2968 model: 'claude-opus-5-5',
2972 model: Model::CLAUDE_OPUS_5_5,
29692973 system: [
29702974 [
29712975 'type' => 'text',
from line 3273
32693273
32703274 1. Cache keys are generated using a cryptographic hash of the prompts up to the cache control point. This means only requests with identical prompts can access a specific cache.
32713275
3272 2. On the Claude API, Claude Platform on AWS, and Microsoft Foundry, caches are isolated per workspace within an organization. On Bedrock and Claude Models on Google Cloud (Google managed), caches are isolated per organization. In every case, caches are never shared across organizations, even for identical prompts. See [Cache storage and sharing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing) for details.
3276 2. On the Claude API, Claude Platform on AWS, and Microsoft Foundry, caches are isolated by workspace within an organization. On Bedrock and Claude Models on Google Cloud (Google managed), caches are isolated by organization. In every case, caches are never shared across organizations, even for identical prompts. See [Cache storage and sharing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing) for details.
32733277
32743278 3. The caching mechanism is designed to maintain the integrity and privacy of each unique conversation or context.
32753279
32763280
No line in this hunk matches that.