Skip to content

Commit 660b0d8

Browse files
committed
Add document to allowed cacheable_types for anthropic
1 parent e61bb5e commit 660b0d8

File tree

2 files changed

+1
-15
lines changed

2 files changed

+1
-15
lines changed

pydantic_ai_slim/pydantic_ai/models/anthropic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ def _add_cache_control_to_last_param(params: list[BetaContentBlockParam], ttl: L
776776

777777
# Only certain types support cache_control
778778
# See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#what-can-be-cached
779-
cacheable_types = {'text', 'tool_use', 'server_tool_use', 'image', 'tool_result'}
779+
cacheable_types = {'text', 'tool_use', 'server_tool_use', 'image', 'tool_result', 'document'}
780780
# Cast needed because BetaContentBlockParam is a union including response Block types (Pydantic models)
781781
# that don't support dict operations, even though at runtime we only have request Param types (TypedDicts).
782782
last_param = cast(dict[str, Any], params[-1])

tests/models/test_anthropic.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,6 @@ async def test_cache_point_in_otel_message_parts(allow_model_requests: None):
419419
)
420420

421421

422-
def test_cache_control_unsupported_param_type():
423-
"""Test that cache control raises error for unsupported param types."""
424-
425-
from pydantic_ai.exceptions import UserError
426-
from pydantic_ai.models.anthropic import AnthropicModel
427-
428-
# Create a list with an unsupported param type (document)
429-
# We'll use a mock document block param
430-
params: list[dict[str, Any]] = [{'type': 'document', 'source': {'data': 'test'}}]
431-
432-
with pytest.raises(UserError, match='Cache control not supported for param type: document'):
433-
AnthropicModel._add_cache_control_to_last_param(params) # type: ignore[arg-type] # Testing internal method
434-
435-
436422
async def test_anthropic_cache_tools(allow_model_requests: None):
437423
"""Test that anthropic_cache_tool_definitions adds cache_control to last tool."""
438424
c = completion_message(

0 commit comments

Comments
 (0)