Follow Discord
Sweep 10 Nov 2026 · 02:18Z Build v2.1.322 539 read Stable v2.1.311 Latest v2.1.322 Next v2.1.322 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

Request 2 caches its request content (not the response) changedbuild-with-claude/prompt-caching

Recorded here
Lines+250added
Lines−96removed
From line 28 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits41to this page, all time

The whole hunk

from line 28, old and new numbered
/
lines
from line 28
2828 - claude-sonnet-4-5-20250929
2929 supportedPlatforms:
3030 Claude API: stable
31 Amazon Bedrock: stable
32 Amazon Bedrock (bedrock-runtime): stable
3133 Claude Platform on AWS: stable
3234 Claude Models on Google Cloud (Anthropic managed): stable
33 Amazon Bedrock: stable
34 Amazon Bedrock (InvokeModel): stable
3535 Claude Models on Google Cloud (Google managed): stable
3636 Microsoft Foundry: stable
3737---
from line 241
241241The lifetime is measured from the start of the request that writes or reads the cache entry, not from the end of its response. Time spent generating a response counts against the lifetime: if a response takes 4 minutes to stream, a follow-up request that reuses the same cached prefix must start within about 1 minute of that response completing.
242242 
243243<Note>
244 If you find that 5 minutes is too short, Anthropic also offers a 1-hour cache duration [at additional cost](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing).
244 If you find that 5 minutes is too short, Anthropic also offers a 1-hour cache duration at additional cost (see [Pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing)).
245245 
246246 For more information, see [1-hour cache duration](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration).
247247</Note>
from line 546
546546* If the last block is not eligible as an automatic cache breakpoint target, the system silently walks backward to find the nearest eligible block. If none is found, caching is skipped.
547547 
548548<Note>
549 Automatic caching is available on every platform except the legacy [Amazon Bedrock (Opus 4.6 and earlier)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy) integration. On that integration, the API returns a 400 error for a top-level `cache_control` field, so use [explicit cache breakpoints](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints) instead.
549 Automatic caching is available on every platform except [Amazon Bedrock (`bedrock-runtime`)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy). There, the API returns a 400 error for a top-level `cache_control` field, so use [explicit cache breakpoints](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints) instead.
550550</Note>
551551 
552552***
from line 628
628628* 1,024 tokens for Claude Opus 4.8, Claude Sonnet 5, Claude Sonnet 4.6, Claude Sonnet 4.5 ([deprecated](https://platform.claude.com/docs/en/about-claude/model-deprecations)), Claude Opus 4.1 ([retired, except on Claude Models on Google Cloud (Google managed) and Bedrock](https://platform.claude.com/docs/en/about-claude/model-deprecations)), Claude Opus 4 ([retired, except on Claude Models on Google Cloud (Google managed)](https://platform.claude.com/docs/en/about-claude/model-deprecations)), and Claude Sonnet 4 ([retired, except on Claude Models on Google Cloud (Google managed) and Bedrock](https://platform.claude.com/docs/en/about-claude/model-deprecations))
629629* 4,096 tokens for Claude Haiku 4.5
630630 
631These minimums apply on every platform where each model is available.
631These minimums apply on each of these platforms where the model is available.
632632 
633633Shorter 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).
634634 
from line 635
635635If 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.
636636 
637637<Note>
638 [Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock) is an AWS-operated platform. On Bedrock, see the [Bedrock prompt caching documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html) for the per-model minimums, failure behavior, and usage-field names that apply.
638 [Amazon Bedrock (`bedrock-mantle`)](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock) is an AWS-operated platform. On Amazon Bedrock, see the [Bedrock prompt caching documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html) for the per-model minimums, failure behavior, and usage-field names that apply.
639639</Note>
640640 
641641For concurrent requests, note that a cache entry only becomes available after the first response starts. If you need cache hits for parallel requests, wait for the first response before sending subsequent requests.
642642 
643Currently, `ephemeral` is the only supported cache type, which by default has a 5-minute lifetime.
643`ephemeral` is the only supported cache type, which by default has a 5-minute lifetime.
644644 
645645### What can be cached
646646 
from line 674
674674 
675675The following table shows which parts of the cache are invalidated by different types of changes. ✘ indicates that the cache is invalidated, whereas ✓ indicates that the cache remains valid.
676676 
677| What changes | Tools cache | System cache | Messages cache | Impact |
678| ----------------------------------------------------- | -------------- | -------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
679| **Tool definitions** | ✘ | ✘ | ✘ | Modifying tool definitions (names, descriptions, parameters) invalidates the entire cache |
680| **Web search toggle** | ✓ | ✘ | ✘ | Enabling/disabling web search modifies the system prompt |
681| **Citations toggle** | ✓ | ✘ | ✘ | Enabling/disabling citations modifies the system prompt |
682| **Speed setting** | ✓ | ✘ | ✘ | Switching between [`speed: "fast"` and standard speed](https://platform.claude.com/docs/en/build-with-claude/fast-mode) invalidates system and message caches |
683| **Tool choice** | ✓ | ✓ | ✘ | Changes to the `tool_choice` parameter only affect message blocks |
684| **Images** | ✓ | ✓ | ✘ | Adding/removing images anywhere in the prompt affects message blocks |
685| **Thinking parameters** | Model-specific | Model-specific | ✘ | The thinking configuration (mode, and `budget_tokens` in extended mode) is rendered into the prompt, so changing it always invalidates message blocks; tool and system caches are also invalidated on models that render the configuration ahead of them. See [Thinking and prompt caching](https://platform.claude.com/docs/en/build-with-claude/thinking#thinking-and-prompt-caching). |
686| **Effort setting** | Model-specific | Model-specific | ✘ | Changing the [`output_config.effort`](https://platform.claude.com/docs/en/build-with-claude/effort) value always invalidates message blocks, with the same model-specific effect on tool and system caches as thinking parameters. Setting effort explicitly to the model’s default is equivalent to omitting it and does not invalidate. On models that support [per-message effort](https://platform.claude.com/docs/en/build-with-claude/effort#change-effort-mid-conversation-beta), an effort change carried in a `role: "system"` message inside `messages` leaves the cached prefix intact. |
687| **Non-tool results passed to requests with thinking** | ✓ | ✓ | Model-specific | On Opus 4.5+, Sonnet 4.6+, and Haiku 5.5, thinking blocks are preserved by default, so the cache remains valid (✓). On earlier Opus/Sonnet models and Haiku models through Claude Haiku 4.5, all previously-cached thinking blocks are stripped from context, and any messages that follow those thinking blocks are removed from the cache (✘). For more details, see [Caching with thinking blocks](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#caching-with-thinking-blocks). |
688| **Dropped thinking blocks** | ✓ | ✓ | ✘ | When the API drops a thinking block that isn’t [preserved](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-thinking) on that request, the cached prefix changes from that block’s position onward on that request. Blocks the receiving model can read, passed back unchanged, keep the cache intact. |
677| What changes | Tools cache | System cache | Messages cache | Impact |
678| ----------------------------------------------------- | -------------- | -------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
679| **Tool definitions** | ✘ | ✘ | ✘ | Modifying tool definitions (names, descriptions, parameters) invalidates the entire cache |
680| **Web search toggle** | ✓ | ✘ | ✘ | Enabling/disabling web search modifies the system prompt |
681| **Citations toggle** | ✓ | ✘ | ✘ | Enabling/disabling citations modifies the system prompt |
682| **Speed setting** | ✓ | ✘ | ✘ | Switching between [`speed: "fast"` and standard speed](https://platform.claude.com/docs/en/build-with-claude/fast-mode) invalidates system and message caches |
683| **Tool choice** | ✓ | ✓ | ✘ | Changes to the `tool_choice` parameter only affect message blocks |
684| **Images** | ✓ | ✓ | ✘ | Adding/removing images anywhere in the prompt affects message blocks |
685| **Thinking parameters** | Model-specific | Model-specific | ✘ | The thinking configuration (mode, and `budget_tokens` in extended mode) is rendered into the prompt, so changing it always invalidates message blocks; tool and system caches are also invalidated on models that render the configuration ahead of them. See [Thinking and prompt caching](https://platform.claude.com/docs/en/build-with-claude/thinking#thinking-and-prompt-caching). |
686| **Effort setting** | Model-specific | Model-specific | ✘ | Changing the [`output_config.effort`](https://platform.claude.com/docs/en/build-with-claude/effort) value always invalidates message blocks, with the same model-specific effect on tool and system caches as thinking parameters. Setting effort explicitly to the model’s default is equivalent to omitting it and does not invalidate. On models that support [per-message effort](https://platform.claude.com/docs/en/build-with-claude/effort-per-message), an effort change carried in a `role: "system"` message inside `messages` leaves the cached prefix intact. |
687| **Non-tool results passed to requests with thinking** | ✓ | ✓ | Model-specific | On Opus 4.5+, Sonnet 4.6+, and Haiku 5.5, thinking blocks are preserved by default, so the cache remains valid (✓). On earlier Opus/Sonnet models and Haiku models through Claude Haiku 4.5, all previously-cached thinking blocks are stripped from context, and any messages that follow those thinking blocks are removed from the cache (✘). For more details, see [Caching with thinking blocks](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#caching-with-thinking-blocks). |
688| **Dropped thinking blocks** | ✓ | ✓ | ✘ | When the API drops a thinking block that isn’t [preserved](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-thinking) on that request, the cached prefix changes from that block’s position onward on that request. Blocks the receiving model can read, passed back unchanged, keep the cache intact. |
689689 
690690On models that support [mid-conversation tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#mid-conversation-tool-changes), the `inline-tools-2026-09-15` beta header lets you add a tool, or change a tool’s definition, partway through a conversation without editing `tools`. Send the definition in a `tool_addition` block in a mid-conversation system message and leave `tools` exactly as you first sent it. The cached prefix still matches, so only the appended message is processed as new input. The one exception is a `tools` array with no non-deferred tool, where the first tool defined this way costs one full cache miss on that request. See [Define tools in a message](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#define-tools-in-a-message-beta).
691691 
692692<Note>
693 On Claude Fable 5.2, [Claude Mythos 5.2](https://platform.claude.com/docs/en/models/mythos-5-2/overview), Claude Fable 5.1, [Claude Mythos 5.1](https://platform.claude.com/docs/en/models/mythos-5-1/overview), Claude Fable 5, [Claude Mythos 5](https://platform.claude.com/docs/en/models/mythos-5/overview), Claude Opus 5.5, Claude Opus 4.8, Claude Opus 5, Claude Sonnet 5.5, and Claude Haiku 5.5, you can add a new system instruction partway through a conversation without invalidating the system or message caches. Append a `{"role": "system"}` message to `messages` instead of editing the top-level `system` field, so the cached prefix stays unchanged. This feature is not available on Claude Sonnet 5. Use the top-level `system` field instead. See [Mid-conversation system messages and tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages).
693 On Claude Fable 5.2, [Claude Mythos 5.2](https://platform.claude.com/docs/en/models/mythos-5-2/overview), Claude Fable 5.1, [Claude Mythos 5.1](https://platform.claude.com/docs/en/models/mythos-5-1/overview), Claude Fable 5, [Claude Mythos 5](https://platform.claude.com/docs/en/models/mythos-5/overview), Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, Claude Sonnet 5.5, and Claude Haiku 5.5, you can add a new system instruction partway through a conversation without invalidating the system or message caches. Append a `{"role": "system"}` message to `messages` instead of editing the top-level `system` field, so the cached prefix stays unchanged. This feature is not available on Claude Sonnet 5. Use the top-level `system` field instead. See [Mid-conversation system messages and tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages).
694694</Note>
695695 
696696### Tracking cache performance
from line 831
831831 
832832## 1-hour cache duration
833833 
834If you find that 5 minutes is too short, Anthropic also offers a 1-hour cache duration [at additional cost](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing).
834If you find that 5 minutes is too short, Anthropic also offers a 1-hour cache duration at additional cost (see [Pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing)).
835835 
836836<Note>
837 The 1-hour cache duration is available on the Claude API, [Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock), [Amazon Bedrock (Opus 4.6 and earlier)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy), [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws), [Claude Models on Google Cloud (Google managed)](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/google-managed), and [Microsoft Foundry](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry).
837 The 1-hour cache duration is available on the Claude API, [Amazon Bedrock (`bedrock-mantle`)](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock), [Amazon Bedrock (`bedrock-runtime`)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy), [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws), [Claude Models on Google Cloud (Google managed)](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/google-managed), and [Microsoft Foundry](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry).
838838</Note>
839839 
840840To use the extended cache, include `ttl` in the `cache_control` definition like this:
from line 2493
24932493 system=[
24942494 {
24952495 "type": "text",
2496 "text": "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",
2496 "text": """You are a helpful research assistant with access to a document knowledge base.
2497 
2498 # Instructions
2499 - Always search for relevant documents before answering
2500 - Provide citations for your sources
2501 - Be objective and accurate in your responses
2502 - If multiple documents contain relevant information, synthesize them
2503 - Acknowledge when information is not available in the knowledge base""",
24972504 "cache_control": {"type": "ephemeral"},
24982505 },
24992506 {
25002507 "type": "text",
2501 "text": "# 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...]",
2508 "text": """# Knowledge Base Context
2509 
2510 Here are the relevant documents for this conversation:
2511 
2512 ## Document 1: Solar System Overview
2513 The solar system consists of the Sun and all objects that orbit it...
2514 
2515 ## Document 2: Planetary Characteristics
2516 Each planet has unique features. Mercury is the smallest planet...
2517 
2518 ## Document 3: Mars Exploration
2519 Mars has been a target of exploration for decades...
2520 
2521 [Additional documents...]""",
25022522 "cache_control": {"type": "ephemeral"},
25032523 },
25042524 ],
from line 2612
25922612 system: [
25932613 {
25942614 type: "text",
2595 text: "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",
2615 text: `You are a helpful research assistant with access to a document knowledge base.
2616 
2617 # Instructions
2618 - Always search for relevant documents before answering
2619 - Provide citations for your sources
2620 - Be objective and accurate in your responses
2621 - If multiple documents contain relevant information, synthesize them
2622 - Acknowledge when information is not available in the knowledge base`,
25962623 cache_control: { type: "ephemeral" }
25972624 },
25982625 {
25992626 type: "text",
2600 text: "# 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...]",
2627 text: `# Knowledge Base Context
2628 
2629 Here are the relevant documents for this conversation:
2630 
2631 ## Document 1: Solar System Overview
2632 The solar system consists of the Sun and all objects that orbit it...
2633 
2634 ## Document 2: Planetary Characteristics
2635 Each planet has unique features. Mercury is the smallest planet...
2636 
2637 ## Document 3: Mars Exploration
2638 Mars has been a target of exploration for decades...
2639 
2640 [Additional documents...]`,
26012641 cache_control: { type: "ephemeral" }
26022642 }
26032643 ],
from line 2736
26962736 {
26972737 new TextBlockParam()
26982738 {
2699 Text = "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",
2739 Text = """
2740 You are a helpful research assistant with access to a document knowledge base.
2741 
2742 # Instructions
2743 - Always search for relevant documents before answering
2744 - Provide citations for your sources
2745 - Be objective and accurate in your responses
2746 - If multiple documents contain relevant information, synthesize them
2747 - Acknowledge when information is not available in the knowledge base
2748 """,
27002749 CacheControl = new CacheControlEphemeral(),
27012750 },
27022751 new TextBlockParam()
27032752 {
2704 Text = "# 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...]",
2753 Text = """
2754 # Knowledge Base Context
2755 
2756 Here are the relevant documents for this conversation:
2757 
2758 ## Document 1: Solar System Overview
2759 The solar system consists of the Sun and all objects that orbit it...
2760 
2761 ## Document 2: Planetary Characteristics
2762 Each planet has unique features. Mercury is the smallest planet...
2763 
2764 ## Document 3: Mars Exploration
2765 Mars has been a target of exploration for decades...
2766 
2767 [Additional documents...]
2768 """,
27052769 CacheControl = new CacheControlEphemeral(),
27062770 },
27072771 }),
from line 2821
27572821 ```
27582822 
27592823 ```go Go
2760 client := anthropic.NewClient()
2824 client := anthropic.NewClient()
27612825 
2762 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
2763 Model: anthropic.ModelClaudeOpus5_5,
2764 MaxTokens: 1024,
2765 Tools: []anthropic.ToolUnionParam{
2766 {OfTool: &anthropic.ToolParam{
2767 Name: "search_documents",
2768 Description: anthropic.String("Search through the knowledge base"),
2769 InputSchema: anthropic.ToolInputSchemaParam{
2770 Properties: map[string]any{
2771 "query": map[string]any{
2772 "type": "string",
2773 "description": "Search query",
2826 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
2827 Model: anthropic.ModelClaudeOpus5_5,
2828 MaxTokens: 1024,
2829 Tools: []anthropic.ToolUnionParam{
2830 {OfTool: &anthropic.ToolParam{
2831 Name: "search_documents",
2832 Description: anthropic.String("Search through the knowledge base"),
2833 InputSchema: anthropic.ToolInputSchemaParam{
2834 Properties: map[string]any{
2835 "query": map[string]any{
2836 "type": "string",
2837 "description": "Search query",
2838 },
27742839 },
2840 Required: []string{"query"},
27752841 },
2776 Required: []string{"query"},
2777 },
2778 }},
2779 {OfTool: &anthropic.ToolParam{
2780 Name: "get_document",
2781 Description: anthropic.String("Retrieve a specific document by ID"),
2782 InputSchema: anthropic.ToolInputSchemaParam{
2783 Properties: map[string]any{
2784 "doc_id": map[string]any{
2785 "type": "string",
2786 "description": "Document ID",
2842 }},
2843 {OfTool: &anthropic.ToolParam{
2844 Name: "get_document",
2845 Description: anthropic.String("Retrieve a specific document by ID"),
2846 InputSchema: anthropic.ToolInputSchemaParam{
2847 Properties: map[string]any{
2848 "doc_id": map[string]any{
2849 "type": "string",
2850 "description": "Document ID",
2851 },
27872852 },
2853 Required: []string{"doc_id"},
27882854 },
2789 Required: []string{"doc_id"},
2855 CacheControl: anthropic.NewCacheControlEphemeralParam(),
2856 }},
2857 },
2858 System: []anthropic.TextBlockParam{
2859 {
2860 Text: `You are a helpful research assistant with access to a document knowledge base.
2861 
2862 # Instructions
2863 - Always search for relevant documents before answering
2864 - Provide citations for your sources
2865 - Be objective and accurate in your responses
2866 - If multiple documents contain relevant information, synthesize them
2867 - Acknowledge when information is not available in the knowledge base`,
2868 CacheControl: anthropic.NewCacheControlEphemeralParam(),
27902869 },
2791 CacheControl: anthropic.NewCacheControlEphemeralParam(),
2792 }},
2793 },
2794 System: []anthropic.TextBlockParam{
2795 {
2796 Text: "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",
2797 CacheControl: anthropic.NewCacheControlEphemeralParam(),
2870 {
2871 Text: `# Knowledge Base Context
2872 
2873 Here are the relevant documents for this conversation:
2874 
2875 ## Document 1: Solar System Overview
2876 The solar system consists of the Sun and all objects that orbit it...
2877 
2878 ## Document 2: Planetary Characteristics
2879 Each planet has unique features. Mercury is the smallest planet...
2880 
2881 ## Document 3: Mars Exploration
2882 Mars has been a target of exploration for decades...
2883 
2884 [Additional documents...]`,
2885 CacheControl: anthropic.NewCacheControlEphemeralParam(),
2886 },
27982887 },
2799 {
2800 Text: "# 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...]",
2801 CacheControl: anthropic.NewCacheControlEphemeralParam(),
2888 Messages: []anthropic.MessageParam{
2889 anthropic.NewUserMessage(anthropic.NewTextBlock("Can you search for information about Mars rovers?")),
2890 anthropic.NewAssistantMessage(anthropic.NewToolUseBlock(
2891 "tool_1",
2892 map[string]any{"query": "Mars rovers"},
2893 "search_documents",
2894 )),
2895 anthropic.NewUserMessage(anthropic.NewToolResultBlock(
2896 "tool_1",
2897 "Found 3 relevant documents: Document 3 (Mars Exploration), Document 7 (Rover Technology), Document 9 (Mission History)",
2898 false,
2899 )),
2900 anthropic.NewAssistantMessage(anthropic.NewTextBlock("I found 3 relevant documents about Mars rovers. Let me get more details from the Mars Exploration document.")),
2901 anthropic.NewUserMessage(anthropic.ContentBlockParamUnion{OfText: &anthropic.TextBlockParam{
2902 Text: "Yes, please tell me about the Perseverance rover specifically.",
2903 CacheControl: anthropic.NewCacheControlEphemeralParam(),
2904 }}),
28022905 },
2803 },
2804 Messages: []anthropic.MessageParam{
2805 anthropic.NewUserMessage(anthropic.NewTextBlock("Can you search for information about Mars rovers?")),
2806 anthropic.NewAssistantMessage(anthropic.NewToolUseBlock(
2807 "tool_1",
2808 map[string]any{"query": "Mars rovers"},
2809 "search_documents",
2810 )),
2811 anthropic.NewUserMessage(anthropic.NewToolResultBlock(
2812 "tool_1",
2813 "Found 3 relevant documents: Document 3 (Mars Exploration), Document 7 (Rover Technology), Document 9 (Mission History)",
2814 false,
2815 )),
2816 anthropic.NewAssistantMessage(anthropic.NewTextBlock("I found 3 relevant documents about Mars rovers. Let me get more details from the Mars Exploration document.")),
2817 anthropic.NewUserMessage(anthropic.ContentBlockParamUnion{OfText: &anthropic.TextBlockParam{
2818 Text: "Yes, please tell me about the Perseverance rover specifically.",
2819 CacheControl: anthropic.NewCacheControlEphemeralParam(),
2820 }}),
2821 },
2822 })
2823 if err != nil {
2824 log.Fatal(err)
2825 }
2826 fmt.Println(response.Usage.RawJSON())
2906 })
2907 if err != nil {
2908 log.Fatal(err)
2909 }
2910 fmt.Println(response.Usage.RawJSON())
28272911 ```
28282912 
28292913 ```java Java
from line 2960
28762960 List.of(
28772961 TextBlockParam.builder()
28782962 .text(
2879 "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"
2963 """
2964 You are a helpful research assistant with access to a document knowledge base.
2965 
2966 # Instructions
2967 - Always search for relevant documents before answering
2968 - Provide citations for your sources
2969 - Be objective and accurate in your responses
2970 - If multiple documents contain relevant information, synthesize them
2971 - Acknowledge when information is not available in the knowledge base"""
28802972 )
28812973 .cacheControl(CacheControlEphemeral.builder().build())
28822974 .build(),
28832975 TextBlockParam.builder()
28842976 .text(
2885 "# 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...]"
2977 """
2978 # Knowledge Base Context
2979 
2980 Here are the relevant documents for this conversation:
2981 
2982 ## Document 1: Solar System Overview
2983 The solar system consists of the Sun and all objects that orbit it...
2984 
2985 ## Document 2: Planetary Characteristics
2986 Each planet has unique features. Mercury is the smallest planet...
2987 
2988 ## Document 3: Mars Exploration
2989 Mars has been a target of exploration for decades...
2990 
2991 [Additional documents...]"""
28862992 )
28872993 .cacheControl(CacheControlEphemeral.builder().build())
28882994 .build()
from line 3102
29963102 system: [
29973103 [
29983104 'type' => 'text',
2999 'text' => "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",
3105 'text' => <<<'TEXT'
3106 You are a helpful research assistant with access to a document knowledge base.
3107 
3108 # Instructions
3109 - Always search for relevant documents before answering
3110 - Provide citations for your sources
3111 - Be objective and accurate in your responses
3112 - If multiple documents contain relevant information, synthesize them
3113 - Acknowledge when information is not available in the knowledge base
3114 TEXT,
30003115 'cache_control' => ['type' => 'ephemeral']
30013116 ],
30023117 [
30033118 'type' => 'text',
3004 'text' => "# 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...]",
3119 'text' => <<<'TEXT'
3120 # Knowledge Base Context
3121 
3122 Here are the relevant documents for this conversation:
3123 
3124 ## Document 1: Solar System Overview
3125 The solar system consists of the Sun and all objects that orbit it...
3126 
3127 ## Document 2: Planetary Characteristics
3128 Each planet has unique features. Mercury is the smallest planet...
3129 
3130 ## Document 3: Mars Exploration
3131 Mars has been a target of exploration for decades...
3132 
3133 [Additional documents...]
3134 TEXT,
30053135 'cache_control' => ['type' => 'ephemeral']
30063136 ]
30073137 ],
from line 3211
30813211 system_: [
30823212 {
30833213 type: "text",
3084 text: "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",
3214 text: <<~TEXT.chomp,
3215 You are a helpful research assistant with access to a document knowledge base.
3216 
3217 # Instructions
3218 - Always search for relevant documents before answering
3219 - Provide citations for your sources
3220 - Be objective and accurate in your responses
3221 - If multiple documents contain relevant information, synthesize them
3222 - Acknowledge when information is not available in the knowledge base
3223 TEXT
30853224 cache_control: { type: "ephemeral" }
30863225 },
30873226 {
30883227 type: "text",
3089 text: "# 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...]",
3228 text: <<~TEXT.chomp,
3229 # Knowledge Base Context
3230 
3231 Here are the relevant documents for this conversation:
3232 
3233 ## Document 1: Solar System Overview
3234 The solar system consists of the Sun and all objects that orbit it...
3235 
3236 ## Document 2: Planetary Characteristics
3237 Each planet has unique features. Mercury is the smallest planet...
3238 
3239 ## Document 3: Mars Exploration
3240 Mars has been a target of exploration for decades...
3241 
3242 [Additional documents...]
3243 TEXT
30903244 cache_control: { type: "ephemeral" }
30913245 }
30923246 ],
from line 3432
32783432 </Accordion>
32793433 
32803434 <Accordion title="Can I manually clear the cache?">
3281 Currently, there’s no way to manually clear the cache. Cached prefixes automatically expire after a minimum of 5 minutes of inactivity.
3435 There’s no way to manually clear the cache. Cached prefixes automatically expire after a minimum of 5 minutes of inactivity.
32823436 </Accordion>
32833437 
32843438 <Accordion title="How can I track the effectiveness of my caching strategy?">
Feedback