From f53353ae121e105081bc2864d276c799ddda9ce4 Mon Sep 17 00:00:00 2001 From: Saicharan Ramineni Date: Sun, 21 Jun 2026 23:50:21 -0400 Subject: [PATCH] fix(bedrock): detect Nova 2 models on all cross-region inference profiles _is_nova_2_model stripped only the us./eu./apac. cross-region prefixes before matching the Nova 2 model id, so a Nova 2 model invoked through a global., jp., au., or us-gov. inference profile was not recognized as Nova 2. That misrouted reasoning_effort to Anthropic's thinking parameter instead of Nova's reasoningConfig, dropped reasoning_effort from the model's supported params, and applied the wrong token-budgeting path. Strip the prefix using get_bedrock_cross_region_inference_regions, the same source of truth the rest of the Bedrock code uses, so detection stays correct as AWS adds regions. --- .../bedrock/chat/converse_transformation.py | 9 +++--- .../test_converse_transformation_nova_2.py | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py index bb261ec85b2..56fdd51a234 100644 --- a/litellm/llms/bedrock/chat/converse_transformation.py +++ b/litellm/llms/bedrock/chat/converse_transformation.py @@ -77,6 +77,7 @@ from ..common_utils import ( BedrockError, BedrockModelInfo, get_anthropic_beta_from_headers, + get_bedrock_cross_region_inference_regions, get_bedrock_tool_name, is_claude_4_5_on_bedrock, normalize_bedrock_opus_output_config_effort, @@ -321,10 +322,10 @@ class AmazonConverseConfig(BaseConfig): model_without_region = model_without_region[len(routing_prefix) :] break - # Remove regional prefix if present (us., eu., apac.) - for prefix in ["us.", "eu.", "apac."]: - if model_without_region.startswith(prefix): - model_without_region = model_without_region[len(prefix) :] + # Remove cross-region inference prefix if present (us., eu., apac., global., jp., ...) + for region in get_bedrock_cross_region_inference_regions(): + if model_without_region.startswith(f"{region}."): + model_without_region = model_without_region[len(region) + 1 :] break # Check if the model is a Nova 2 model (matches nova-2-lite, nova-2-pro, etc.) diff --git a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation_nova_2.py b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation_nova_2.py index bac7aa08a04..9d0da9b3553 100644 --- a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation_nova_2.py +++ b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation_nova_2.py @@ -222,6 +222,24 @@ class TestNova2ParameterMapping: assert result["reasoningConfig"]["type"] == "enabled" assert result["reasoningConfig"]["maxReasoningEffort"] == "high" + @pytest.mark.parametrize("region", ["global", "jp", "au", "us-gov"]) + def test_nova_2_cross_region_variant_mapping(self, region): + """Cross-region inference profiles beyond us/eu/apac must still map reasoning_effort to reasoningConfig.""" + config = AmazonConverseConfig() + + model = f"{region}.amazon.nova-2-lite-v1:0" + result = config.map_openai_params( + non_default_params={"reasoning_effort": "high"}, + optional_params={}, + model=model, + drop_params=False, + ) + + assert "reasoningConfig" in result + assert result["reasoningConfig"]["type"] == "enabled" + assert result["reasoningConfig"]["maxReasoningEffort"] == "high" + assert "thinking" not in result + def test_nova_2_with_other_params(self): """Test that Nova 2 reasoning works alongside other parameters.""" config = AmazonConverseConfig() @@ -308,6 +326,17 @@ class TestNova15SupportedParameters: # Verify thinking is NOT in supported params assert "thinking" not in supported_params + @pytest.mark.parametrize("region", ["global", "jp", "au", "us-gov"]) + def test_nova_2_cross_region_variant_supported_params(self, region): + """Cross-region inference profiles beyond us/eu/apac must still report reasoning_effort, not thinking.""" + config = AmazonConverseConfig() + + model = f"{region}.amazon.nova-2-lite-v1:0" + supported_params = config.get_supported_openai_params(model) + + assert "reasoning_effort" in supported_params + assert "thinking" not in supported_params + def test_nova_2_has_standard_params(self): """Test that Nova 2 still has all standard supported params.""" config = AmazonConverseConfig()