Skip to content

Commit bcd3d83

Browse files
marpulliDouweM
andauthored
Add document to allowed cacheable_types for anthropic (#3513)
Co-authored-by: Douwe Maan <[email protected]>
1 parent 8ef3c79 commit bcd3d83

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ def test_cache_control_unsupported_param_type():
427427

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

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

435435

0 commit comments

Comments
 (0)