-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
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