Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(e2e): cover the Anthropic web_search server tool on Bedrock (#36443)

Yassin Kortam1d3b64c66f0b
diff --git a/tests/e2e/coverage_registry/llm_claude_code_compat.yaml b/tests/e2e/coverage_registry/llm_claude_code_compat.yaml
index 6edf890f7ec..c2c17a6e764 100644
--- a/tests/e2e/coverage_registry/llm_claude_code_compat.yaml
+++ b/tests/e2e/coverage_registry/llm_claude_code_compat.yaml
@@ -106,5 +106,5 @@
- {id: llm.messages.anthropic.web_search.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: anthropic, capability: web_search, streaming: nonstream, assertions: [works], source: "claude_code compat matrix", rationale: "Web search server tool over Anthropic direct"}
- {id: llm.messages.azure_foundry.web_search.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: azure_foundry, capability: web_search, streaming: nonstream, assertions: [works], source: "claude_code compat matrix", rationale: "Web search server tool over Azure AI Foundry"}
- {id: llm.messages.bedrock_converse.web_search.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: bedrock_converse, capability: web_search, streaming: nonstream, assertions: [works], source: "claude_code compat matrix", rationale: "Web search server tool over Bedrock Converse"}
-- {id: llm.messages.bedrock_invoke.web_search.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: bedrock_invoke, capability: web_search, streaming: nonstream, assertions: [works], source: "claude_code compat matrix", rationale: "Web search server tool over Bedrock Invoke"}
+- {id: llm.messages.bedrock_invoke.web_search.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: bedrock_invoke, capability: web_search, streaming: nonstream, assertions: [works], source: "claude_code compat matrix", rationale: "Claude Code's client-side WebSearch tool over Bedrock Invoke; the Anthropic-managed web_search server tool is covered by llm.messages.bedrock_invoke.web_search_server_tool.nonstream.works"}
- {id: llm.messages.vertex.web_search.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: vertex, capability: web_search, streaming: nonstream, assertions: [works], source: "claude_code compat matrix", rationale: "Web search server tool over Vertex AI"}
diff --git a/tests/e2e/coverage_registry/llm_conversational.yaml b/tests/e2e/coverage_registry/llm_conversational.yaml
index e8fc8067ee0..8163866abd1 100644
--- a/tests/e2e/coverage_registry/llm_conversational.yaml
+++ b/tests/e2e/coverage_registry/llm_conversational.yaml
@@ -51,6 +51,7 @@
- {id: llm.messages.anthropic.thinking.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: anthropic, capability: thinking, streaming: nonstream, assertions: [works], source: "model_prices json", rationale: "Extended thinking via Messages API"}
- {id: llm.messages.bedrock_invoke.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py", rationale: "Flagged Claude 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (#32578/#32831/#32882)", fail_before_fix: proven}
- {id: llm.messages.bedrock_invoke.mid_conversation_system.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: mid_conversation_system, streaming: nonstream, assertions: [works], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py", rationale: "Claude <= 4.7 rejects role system inside messages; unflagged models must hoist reminders into top-level system or every Claude Code session 400s (#32831)", fail_before_fix: proven}
+- {id: llm.messages.bedrock_invoke.web_search_server_tool.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: web_search_server_tool, streaming: nonstream, assertions: [works], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py", rationale: "Bedrock hosts no web_search server tool, so this only works because interception rewrites it before the upstream call and the agentic loop feeds the results back in native shape; a regression that short-circuits or forwards it instead yields raw text or AWS's 400", fail_before_fix: unproven}
- {id: llm.messages.azure_foundry.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: azure_foundry, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/azure_ai/anthropic/messages_transformation.py", rationale: "Azure Foundry serves Claude on the native Anthropic contract, so flagged 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (customer RCA gap)", fail_before_fix: proven}
- {id: llm.messages.azure_foundry.mid_conversation_system.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: azure_foundry, capability: mid_conversation_system, streaming: nonstream, assertions: [works], source: "llms/azure_ai/anthropic/messages_transformation.py", rationale: "Azure Foundry Claude <= 4.7 rejects role system inside messages; unflagged models must hoist reminders into top-level system or every Claude Code session 400s (customer RCA gap)", fail_before_fix: proven}
- {id: llm.messages.vertex.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: vertex, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py", rationale: "Vertex serves Claude on the native Anthropic contract, so flagged 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (customer RCA gap)", fail_before_fix: proven}
diff --git a/tests/e2e/coverage_registry/schema.py b/tests/e2e/coverage_registry/schema.py
index d17ea0e1e5e..2d921014f0e 100644
--- a/tests/e2e/coverage_registry/schema.py
+++ b/tests/e2e/coverage_registry/schema.py
@@ -73,6 +73,7 @@ LlmCapability = Literal[
"tool_use",
"vision",
"web_search",
+ "web_search_server_tool",
]
diff --git a/tests/e2e/llm_translation/test_bedrock_web_search_server_tool_e2e.py b/tests/e2e/llm_translation/test_bedrock_web_search_server_tool_e2e.py
new file mode 100644
index 00000000000..7ff4b5f594a
--- /dev/null
+++ b/tests/e2e/llm_translation/test_bedrock_web_search_server_tool_e2e.py
@@ -0,0 +1,102 @@
+"""Live e2e: the Anthropic web_search server tool over Bedrock Invoke.
+
+Bedrock hosts none of Anthropic's ``web_search_*`` server tools, so a
+``/v1/messages`` request carrying one is rejected outright with
+400 "The provided request is not valid" if it reaches AWS unchanged. What makes
+it work is web-search interception: the hooks rewrite the native tool into
+LiteLLM's own search tool before the upstream call, Bedrock calls that tool, the
+gateway runs the search, and the agentic loop feeds the results back for the
+model to synthesize. The response is then rebuilt in the native shape, so a
+client's citations panel sees ``server_tool_use`` and ``web_search_tool_result``
+exactly as it would from Anthropic direct.
+
+This cell pins that whole path. Nothing else covers it: the ``web_search`` cells
+in the Claude Code compat matrix drive the CLI's *client-side* ``WebSearch``
+tool, an ordinary custom tool the CLI executes and feeds back as a
+``tool_result``, and the CLI never emits a ``web_search_20250305`` definition.
+
+Prerequisites beyond AWS credentials: the proxy config must switch interception
+on and declare a search backend. The callback entry is load-bearing; the params
+block alone does not activate it.
+
+ litellm_settings:
+ callbacks: ["websearch_interception"]
+ websearch_interception_params:
+ enabled_providers: ["bedrock"]
+ search_tool_name: e2e-search
+ search_tools:
+ - search_tool_name: e2e-search
+ litellm_params:
+ search_provider: searxng
+ api_base: http://127.0.0.1:8391
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from e2e_config import unique_marker
+from e2e_http import unwrap
+from endpoints_client import EndpointsClient
+from lifecycle import ResourceManager
+from models import (
+ AnthropicMessagesBody,
+ AnthropicWebSearchTool,
+ ChatMessage,
+ LiteLLMParamsBody,
+)
+
+pytestmark = pytest.mark.e2e
+
+BEDROCK_INVOKE_BACKEND = "bedrock/invoke/us.anthropic.claude-haiku-4-5-20251001-v1:0"
+
+WEB_SEARCH_TOOL = AnthropicWebSearchTool(
+ type="web_search_20250305",
+ name="web_search",
+ max_uses=3,
+)
+
+SEARCH_PROMPT = "Use web search to tell me one recent news headline about Anthropic."
+
+
+class TestBedrockWebSearchServerTool:
+ @pytest.mark.covers("llm.messages.bedrock_invoke.web_search_server_tool.nonstream.works")
+ def test_web_search_server_tool_is_served(
+ self, endpoints_client: EndpointsClient, resources: ResourceManager
+ ) -> None:
+ """A bedrock deployment must answer a web_search server-tool request
+ instead of handing the tool to AWS and returning its 400."""
+ model = f"e2e-bedrock-websearch-{unique_marker()}"
+ model_id = endpoints_client.create_model(
+ model,
+ LiteLLMParamsBody(
+ model=BEDROCK_INVOKE_BACKEND,
+ aws_region_name="us-east-1",
+ ),
+ )
+ resources.defer(lambda: endpoints_client.delete_model(model_id))
+ key = resources.key()
+
+ response = unwrap(
+ endpoints_client.proxy.messages(
+ key,
+ AnthropicMessagesBody(
+ model=model,
+ max_tokens=512,
+ tools=[WEB_SEARCH_TOOL],
+ messages=[ChatMessage(role="user", content=SEARCH_PROMPT)],
+ ),
+ )
+ )
+
+ assert response.content, f"no content blocks in response: {response}"
+ block_types = [block.type for block in response.content]
+ assert "web_search_tool_result" in block_types, (
+ "the answer carries no web_search_tool_result block, so the search "
+ "either never ran or its results were not returned in the native shape "
+ f"a citations panel reads. blocks={block_types}"
+ )
+ assert "text" in block_types, (
+ "the model never synthesized an answer over the search results, so the "
+ f"agentic loop stopped early. blocks={block_types}"
+ )
diff --git a/tests/e2e/models.py b/tests/e2e/models.py
index f1c0ede0e85..bef199cdd16 100644
--- a/tests/e2e/models.py
+++ b/tests/e2e/models.py
@@ -347,23 +347,35 @@ class ToolInputSchema(BaseModel):
required: list[str] = []
-class AnthropicToolSearchTool(BaseModel):
- """The tool_search discovery tool. `type` carries the SDK-version-pinned
- suffix (e.g. ``tool_search_tool_regex_20251119``) that LiteLLM keys its
- per-provider beta-header translation on; `name` is the unsuffixed
- canonical name the upstream accepts."""
+class AnthropicServerTool(BaseModel):
+ """An Anthropic-managed tool the upstream executes itself. It carries no
+ `input_schema`; `type` is the SDK-version-pinned identifier LiteLLM keys its
+ per-provider translation on, and `name` is the unsuffixed canonical name the
+ upstream accepts."""
type: str
name: str
+class AnthropicToolSearchTool(AnthropicServerTool):
+ """The tool_search discovery tool, e.g. ``tool_search_tool_regex_20251119``."""
+
+
+class AnthropicWebSearchTool(AnthropicServerTool):
+ """The web_search server tool, e.g. ``web_search_20250305``. Distinct from
+ Claude Code's client-side ``WebSearch`` tool, which is an ordinary custom
+ tool the CLI executes and feeds back as a tool_result."""
+
+ max_uses: int | None = None
+
+
class AnthropicCustomTool(BaseModel):
name: str
description: str
input_schema: ToolInputSchema
-type AnthropicTool = AnthropicToolSearchTool | AnthropicCustomTool
+type AnthropicTool = AnthropicToolSearchTool | AnthropicWebSearchTool | AnthropicCustomTool
class AnthropicMessagesBody(BaseModel):