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.
This commit is contained in:
Saicharan Ramineni 2026-06-21 23:50:21 -04:00
parent 84c1414aef
commit f53353ae12
2 changed files with 34 additions and 4 deletions

View file

@ -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.)

View file

@ -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()