diff --git a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py index fad7e7558c2..9a6fdf78090 100644 --- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py +++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py @@ -372,8 +372,9 @@ class AmazonAnthropicClaudeMessagesConfig( """ Check if the model supports tool search on Bedrock. - On Amazon Bedrock, server-side tool search is supported on Claude Opus 4.5 - and Claude Sonnet 4.5 with the tool-search-tool-2025-10-19 beta header. + On Amazon Bedrock, server-side tool search is supported on Claude + Opus 4.5/4.6/4.7, Sonnet 4.5/4.6, and Haiku 4.5 with the + tool-search-tool-2025-10-19 beta header. Ref: https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool @@ -407,10 +408,17 @@ class AmazonAnthropicClaudeMessagesConfig( "sonnet_4.6", "sonnet-4-6", "sonnet_4_6", - # NOTE: Opus 4.7 on Bedrock does not support server-side tool search - # as of launch (2026-04-16). Bedrock rejects the tool type with: - # "tool type 'tool_search_tool_..._20251119' is not supported for this model". - # Re-add the opus-4.7 patterns here once AWS announces support. + # Opus 4.7 (unsupported at its 2026-04-16 launch; verified live + # 2026-08-11 that Bedrock now accepts the beta on it) + "opus-4.7", + "opus_4.7", + "opus-4-7", + "opus_4_7", + # Haiku 4.5 + "haiku-4.5", + "haiku_4.5", + "haiku-4-5", + "haiku_4_5", ] return any(pattern in model_lower for pattern in supported_patterns) @@ -426,11 +434,10 @@ class AmazonAnthropicClaudeMessagesConfig( """ Adjust tool search beta header for Bedrock. - Bedrock requires a different beta header for tool search on Opus 4 models - when tool search is used without programmatic tool calling or input examples. - - Note: On Amazon Bedrock, server-side tool search is only supported on Claude Opus 4 - with the `tool-search-tool-2025-10-19` beta header. + Bedrock requires a different beta header for tool search than the + Anthropic API when tool search is used without programmatic tool + calling or input examples: `tool-search-tool-2025-10-19`, and only on + the models listed in `_supports_tool_search_on_bedrock`. Ref: https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool diff --git a/tests/e2e/claude_code/tool_search/test_bedrock_invoke.py b/tests/e2e/claude_code/tool_search/test_bedrock_invoke.py index 12f8909e3e8..c4735c78f0c 100644 --- a/tests/e2e/claude_code/tool_search/test_bedrock_invoke.py +++ b/tests/e2e/claude_code/tool_search/test_bedrock_invoke.py @@ -59,10 +59,6 @@ BEDROCK_INVOKE_MODELS = [ ] -@pytest.mark.skip( - reason="product bug LIT-4522: Bedrock Invoke /v1/messages does not normalize " - "tool_search_tool_regex_20251119; re-enable when messages path matches chat path" -) @pytest.mark.covers("llm.messages.bedrock_invoke.tool_search.nonstream.works") def test_tool_search_bedrock_invoke(compat_result): """Probe `/v1/messages` with a `tool_search_tool_regex_20251119` diff --git a/tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py b/tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py index 2d1a5bc4c2a..67409cc6cd0 100644 --- a/tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py +++ b/tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py @@ -2474,6 +2474,55 @@ def test_filter_and_transform_beta_headers_passes_context_management_for_bedrock assert out_converse == [] +@pytest.mark.parametrize( + "model", + [ + "us.anthropic.claude-haiku-4-5-20251001-v1:0", + "us.anthropic.claude-sonnet-4-5-20250929-v1:0", + "us.anthropic.claude-opus-4-7", + ], +) +def test_bedrock_messages_tool_search_adds_beta_header(local_beta_headers_config, model): + """ + LIT-4522: Bedrock InvokeModel only admits ``tool_search_tool_*`` tool types + when the request body carries the ``tool-search-tool-2025-10-19`` beta; + without it Bedrock 400s with "Input tag 'tool_search_tool_regex_20251119' + ... does not match any of the expected tags". The allowlist in + ``_supports_tool_search_on_bedrock`` previously omitted Haiku 4.5 and + Opus 4.7, so the beta was silently dropped for those models and every + tool-search request failed. Verified live 2026-08-11: Bedrock returns 200 + with ``server_tool_use`` for all three models once the beta is sent. + """ + from litellm.types.router import GenericLiteLLMParams + + cfg = AmazonAnthropicClaudeMessagesConfig() + messages = [{"role": "user", "content": [{"type": "text", "text": "Hi"}]}] + optional_params = { + "max_tokens": 64, + "tools": [ + {"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"}, + { + "name": "add_numbers", + "description": "Add two integers", + "input_schema": { + "type": "object", + "properties": {"a": {"type": "integer"}, "b": {"type": "integer"}}, + "required": ["a", "b"], + }, + }, + ], + } + + result = cfg.transform_anthropic_messages_request( + model=model, + messages=messages, + anthropic_messages_optional_request_params=optional_params, + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + + assert "tool-search-tool-2025-10-19" in (result.get("anthropic_beta") or []) + def test_bedrock_messages_thinking_shape_follows_exact_bedrock_entry_flag( local_model_cost_map, monkeypatch