Skip to content

Conversation

@marpulli
Copy link
Contributor

@marpulli marpulli commented Nov 21, 2025

Document is an allowed type as per the Anthropic docs:

Images & Documents: Content blocks in the messages.content array, in user turns

This example now works

import pathlib from pydantic_ai import Agent, BinaryContent, CachePoint from pydantic_ai.models.anthropic import AnthropicModel from pydantic_ai.providers.anthropic import AnthropicProvider model = AnthropicModel( "claude-3-5-haiku-20241022", provider=AnthropicProvider(api_key=SETTINGS.anthropic_api_key), ) agent = Agent(model=model) binary_data = pathlib.Path("example.pdf").open("rb").read() user_prompt = [ BinaryContent( data=binary_data, media_type="application/pdf", ), CachePoint(), ] result = await agent.run( user_prompt=user_prompt, ) ```
@marpulli marpulli force-pushed the add-document-type-to-anthropic-cache-content-types branch from 0034cfb to 660b0d8 Compare November 21, 2025 17:41
@DouweM
Copy link
Collaborator

DouweM commented Nov 21, 2025

@marpulli Thanks Mark! Looks like the Cache control not supported for param type: error is now uncovered. Can you please either add a new test for a type that is still unsupported for cache control (assuming there is one you can easily create in Pydantic AI), or if not, add a # pragma: no cover comment to the line(s) in question?

@marpulli marpulli force-pushed the add-document-type-to-anthropic-cache-content-types branch from 660b0d8 to 3d1520e Compare November 21, 2025 18:41
@marpulli
Copy link
Contributor Author

Thanks for a speedy review @DouweM! I've changed the test to use the thinking type as thinking blocks don't support caching with cache_control param according to the anthropic docs

@DouweM DouweM changed the title Add document to allowed cacheable_types for anthropic Add document to allowed cacheable_types for anthropic Nov 21, 2025
@DouweM DouweM enabled auto-merge (squash) November 21, 2025 19:30
@DouweM DouweM merged commit bcd3d83 into pydantic:main Nov 21, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants