Skip to content

AnthropicModel should auto-enable Files API beta for UploadedFile requests #5806

Description

@Zoe14

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

anthropicnative-or-locala.k.a. `provider adaptive` or `native fallback`pydanty:bugManaged by pydanty dogfooding automation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions