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
Bedrock: add prompt caching support and verification
- Emit cache-point tool entries so Bedrock accepts cached tool definitions
- Document and test prompt caching (writes + reads) with cassette-body checks
- Refresh Bedrock cassettes and type annotations to align with the new flow
Bedrock supports [prompt caching](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html) on Anthropic models so you can reuse expensive context across requests. Pydantic AI exposes the same three strategies as Anthropic:
80
+
81
+
1.**Cache User Messages with [`CachePoint`][pydantic_ai.messages.CachePoint]**: Insert a `CachePoint` marker to cache everything before it in the current user message.
82
+
2.**Cache System Instructions**: Enable [`BedrockModelSettings.bedrock_cache_instructions`][pydantic_ai.models.bedrock.BedrockModelSettings.bedrock_cache_instructions] to append a cache point after the system prompt.
83
+
3.**Cache Tool Definitions**: Enable [`BedrockModelSettings.bedrock_cache_tool_definitions`][pydantic_ai.models.bedrock.BedrockModelSettings.bedrock_cache_tool_definitions] to cache your tool schemas.
84
+
85
+
> [!NOTE]
86
+
> AWS only serves cached content once a segment crosses the provider-specific minimum token thresholds (see the [Bedrock prompt caching docs](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html)). Short prompts or tool definitions below those limits will bypass the cache, so don't expect savings for tiny payloads.
87
+
88
+
You can combine all of them:
89
+
90
+
```python {test="skip"}
91
+
from pydantic_ai import Agent, CachePoint, RunContext
92
+
from pydantic_ai.models.bedrock import BedrockConverseModel, BedrockModelSettings
93
+
94
+
model = BedrockConverseModel('us.anthropic.claude-sonnet-4-5-20250929-v1:0')
You can provide a custom `BedrockProvider` via the `provider` argument. This is useful when you want to specify credentials directly or use a custom boto3 client:
0 commit comments