diff --git a/pydantic_ai_slim/pydantic_ai/models/anthropic.py b/pydantic_ai_slim/pydantic_ai/models/anthropic.py index de33a08f7a..e32888a439 100644 --- a/pydantic_ai_slim/pydantic_ai/models/anthropic.py +++ b/pydantic_ai_slim/pydantic_ai/models/anthropic.py @@ -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]) diff --git a/tests/models/test_anthropic.py b/tests/models/test_anthropic.py index 86ba5a68d3..1d0d64918f 100644 --- a/tests/models/test_anthropic.py +++ b/tests/models/test_anthropic.py @@ -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