You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/models/anthropic.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,8 +83,8 @@ agent = Agent(model)
83
83
Anthropic supports [prompt caching](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching) to reduce costs by caching parts of your prompts. Pydantic AI provides three ways to use prompt caching:
84
84
85
85
1.**Cache User Messages with [`CachePoint`][pydantic_ai.messages.CachePoint]**: Insert a `CachePoint` marker in your user messages to cache everything before it
86
-
2.**Cache System Instructions**: Enable the [`AnthropicModelSettings.anthropic_cache_instructions`][pydantic_ai.models.anthropic.AnthropicModelSettings.anthropic_cache_instructions][model setting](../agents.md#model-run-settings) to cache your system prompt
87
-
3.**Cache Tool Definitions**: Enable the [`AnthropicModelSettings.anthropic_cache_tool_definitions`][pydantic_ai.models.anthropic.AnthropicModelSettings.anthropic_cache_tool_definitions][model setting](../agents.md#model-run-settings) to cache your tool definitions
86
+
2.**Cache System Instructions**: Set [`AnthropicModelSettings.anthropic_cache_instructions`][pydantic_ai.models.anthropic.AnthropicModelSettings.anthropic_cache_instructions]to `True` (uses 5m TTL by default) or specify `'5m'` / `'1h'` directly
87
+
3.**Cache Tool Definitions**: Set [`AnthropicModelSettings.anthropic_cache_tool_definitions`][pydantic_ai.models.anthropic.AnthropicModelSettings.anthropic_cache_tool_definitions]to `True` (uses 5m TTL by default) or specify `'5m'` / `'1h'` directly
88
88
89
89
You can combine all three strategies for maximum savings:
90
90
@@ -96,8 +96,9 @@ agent = Agent(
96
96
'anthropic:claude-sonnet-4-5',
97
97
system_prompt='Detailed instructions...',
98
98
model_settings=AnthropicModelSettings(
99
+
# Use True for default 5m TTL, or specify '5m' / '1h' directly
99
100
anthropic_cache_instructions=True,
100
-
anthropic_cache_tool_definitions=True,
101
+
anthropic_cache_tool_definitions='1h', # Longer cache for tool definitions
0 commit comments