Support Anthropic `web_search_20260318` and `web_fetch_20260318` via `provider_settings`
Second of three stacked PRs, on top of #7633, which adds provider_settings. #7807 builds on this one.
What this adds
Anthropic's newer web tools have options no other provider has, so they go in provider_settings:
WebSearchTool(provider_settings={'anthropic': {'response_inclusion': 'excluded'}})
WebFetchTool(provider_settings={'anthropic': {'use_cache': False, 'response_inclusion': 'excluded'}})
use_cache=False makes Anthropic fetch fresh content. response_inclusion='excluded' leaves out results that code execution already used. WebFetchTool gets its provider_settings field here, since Anthropic is its only provider with extra options.
Does user behaviour change?
Not for existing code. Nothing changes unless you set one of these options. If you do:
- The request uses the
20260318web tool, even if you set an option to its default value.response_inclusionneeds that version, anduse_cacheneedsweb_fetch_20260309or later, so one version covers both. The defaults areresponse_inclusion='full'anduse_cache=True. - Models without dynamic filtering stay on direct calls. The
20260318tools otherwise run through code execution, which these models don't opt into in Pydantic AI, so we sendallowed_callers=['direct'].anthropic_web_tools_allowed_callersstill overrides this. - Citations route the
20260318tools to direct calls, the same as the20260209tools today. response_inclusiononly picks the newer version when it can matter. It only changes results that code execution consumes. On a model without dynamic filtering, which includes every model on Vertex, the web tools are called directly, soresponse_inclusionkeeps the older version there unlessanthropic_web_tools_allowed_callersnames a code execution caller. That keeps it from moving Vertex ontoweb_search_20260318, which Vertex rejected when we checked.use_cacheaffects direct calls too, so it still selectsweb_fetch_20260318everywhere. We don't raise our own error for any client, because a provider can add a version without a Pydantic AI release. The Bedrock clients, and web fetch on Vertex, still raise aUserErroras they do today.
Testing
Recorded cassettes cover both 20260318 tools, including allowed_callers and citation routing. The option table from #7633 now also sends every Anthropic option through a real mocked request. The cassette tests check that code execution's results come back and the excluded web_search and web_fetch results don't.
I also ran live calls against Anthropic: streaming, multi-turn history, direct calls on a model without dynamic filtering, token counting, and use alongside CodeExecutionTool.
Vertex was checked live on Sonnet 4.6 and Sonnet 5.5 in the global region. Vertex rejects web_search_20260209, web_search_20260318 and every web fetch version with "does not match any of the expected tags", and lists web_search_20250305 as its only web tool. Foundry wasn't tested live, since we have no credentials for it. Bedrock is unchanged: web search and web fetch raise a UserError there, as on main.
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. (Not applicable.)
- PR title is fit for the release changelog.
š¤ Generated with Claude Code
Summary by cubic
Adds Anthropic provider_settings for WebSearchTool and WebFetchTool, exposing response_inclusion and use_cache ā options only available on Anthropic's web_search_20260318 and web_fetch_20260318 tool versions. This builds on the provider_settings support from #7633; WebFetchTool gains a provider_settings field since Anthropic is its only provider with extra options.
use_cacheselectsweb_fetch_20260318everywhere, since it also affects direct calls.response_inclusiononly selects the20260318versions where code execution may call the tool; models without dynamic filtering keep the older versions unlessanthropic_web_tools_allowed_callersnames a code execution caller.- Citations route the
20260318tools to direct calls; Bedrock clients still raiseUserError. - No client-specific errors: the version is sent and the provider's API decides.