Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pydantic_ai_slim/pydantic_ai/models/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def _add_cache_control_to_last_param(params: list[BetaContentBlockParam], ttl: L

# Only certain types support cache_control
# See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#what-can-be-cached
cacheable_types = {'text', 'tool_use', 'server_tool_use', 'image', 'tool_result'}
cacheable_types = {'text', 'tool_use', 'server_tool_use', 'image', 'tool_result', 'document'}
# Cast needed because BetaContentBlockParam is a union including response Block types (Pydantic models)
# that don't support dict operations, even though at runtime we only have request Param types (TypedDicts).
last_param = cast(dict[str, Any], params[-1])
Expand Down
4 changes: 2 additions & 2 deletions tests/models/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ def test_cache_control_unsupported_param_type():

# Create a list with an unsupported param type (document)
# We'll use a mock document block param
params: list[dict[str, Any]] = [{'type': 'document', 'source': {'data': 'test'}}]
params: list[dict[str, Any]] = [{'type': 'thinking', 'source': {'data': 'test'}}]

with pytest.raises(UserError, match='Cache control not supported for param type: document'):
with pytest.raises(UserError, match='Cache control not supported for param type: thinking'):
AnthropicModel._add_cache_control_to_last_param(params) # type: ignore[arg-type] # Testing internal method


Expand Down