Description
AnthropicModel already serializes UploadedFile(provider_name='anthropic', ...) into Messages API content blocks with source={"type": "file", "file_id": ...} for both user prompts and tool returns. However, those request bodies require Anthropic's Files API beta header (files-api-2025-04-14), and the model adapter currently only sends that beta when users pass it manually through anthropic_betas or extra_headers.
This makes uploaded-file requests fail unless users know to add the beta themselves. The docs currently show the manual header workaround, but the adapter could infer it from the presence of Anthropic UploadedFile parts.
Reproduction
On current main (837b03e3 when checked):
pydantic_ai_slim/pydantic_ai/models/anthropic.py maps Anthropic UploadedFile to BetaFileImageSourceParam(..., type='file') / BetaFileDocumentSourceParam(..., type='file').
_messages_create() and _messages_count_tokens() merge settings betas, header betas, native-tool betas, task-budget/compaction/fast-mode betas, but do not add files-api-2025-04-14 for uploaded files.
Expected behavior
When the normalized messages contain an Anthropic UploadedFile, AnthropicModel should add files-api-2025-04-14 to the request betas for both message creation and token counting.
This should be gated on actual Anthropic UploadedFile usage, not added unconditionally, to avoid leaking Anthropic beta headers to compatible/proxy providers that do not accept them.
Description
AnthropicModelalready serializesUploadedFile(provider_name='anthropic', ...)into Messages API content blocks withsource={"type": "file", "file_id": ...}for both user prompts and tool returns. However, those request bodies require Anthropic's Files API beta header (files-api-2025-04-14), and the model adapter currently only sends that beta when users pass it manually throughanthropic_betasorextra_headers.This makes uploaded-file requests fail unless users know to add the beta themselves. The docs currently show the manual header workaround, but the adapter could infer it from the presence of Anthropic
UploadedFileparts.Reproduction
On current
main(837b03e3when checked):pydantic_ai_slim/pydantic_ai/models/anthropic.pymaps AnthropicUploadedFiletoBetaFileImageSourceParam(..., type='file')/BetaFileDocumentSourceParam(..., type='file')._messages_create()and_messages_count_tokens()merge settings betas, header betas, native-tool betas, task-budget/compaction/fast-mode betas, but do not addfiles-api-2025-04-14for uploaded files.Expected behavior
When the normalized messages contain an Anthropic
UploadedFile,AnthropicModelshould addfiles-api-2025-04-14to the request betas for both message creation and token counting.This should be gated on actual Anthropic
UploadedFileusage, not added unconditionally, to avoid leaking Anthropic beta headers to compatible/proxy providers that do not accept them.