Skip to content

Default anthropic-beta feature set by AnthropicModel incompatible with other providers #2543

@jerry-reevo

Description

@jerry-reevo

Initial Checks

Description

Starting with pydantic-ai version 0.6.2 it seems that the AnthropicModel now sets anthropic-beta with code-execution-2025-05-22.

This seems to unintentionally introduce behavior changes to existing Anthropic agents and is not supported by all providers. This causes an AnthropicModel using the AsyncAnthropicVertex (for GCP VertexAI) to error out with:

pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: claude-sonnet-4@20250514, body: {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'Unexpected value(s) `code-execution-2025-05-22` for the `anthropic-beta` header. Please consult our documentation at docs.anthropic.com or try again without the header.'}}

Workaround is to explicitly set anthropic-beta to an empty string, i.e. extra_headers={"anthropic-beta": ""}

Default is being set here: https://github.com/pydantic/pydantic-ai/blob/main/pydantic_ai_slim/pydantic_ai/models/anthropic.py#L268

Example Code

AnthropicModel(
    "claude-sonnet-4@20250514",
    provider=AnthropicProvider(
        anthropic_client=anthropic_vertex,  # type: ignore
    ),
    # This is now required for use with Vertex AI
    settings=AnthropicModelSettings(
        extra_headers={"anthropic-beta": ""},
    ),
)

Python, Pydantic AI & LLM client version

pydantic-ai 0.7.1
Python 3.12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions