From 1fbd1e9ce90580f801612d2016e9e2cc4ab553b5 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 24 Sep 2026 13:08:27 -0700 Subject: [PATCH] fix(bedrock): route unmapped openai family model ids to converse (#42713) * fix(bedrock): route unmapped openai family model ids to converse Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(bedrock): rename the e2e openai family backend constant global.openai.gpt-6-sol has a cost-map row now, so the constant no longer names an unmapped model --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com> --- litellm/llms/bedrock/common_utils.py | 2 ++ .../test_bedrock_provider_matrix_e2e.py | 19 ++++++++++++++++++- .../llms/bedrock/test_bedrock_common_utils.py | 19 ++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/litellm/llms/bedrock/common_utils.py b/litellm/llms/bedrock/common_utils.py index 9b52f531cbb..5f044897b2c 100644 --- a/litellm/llms/bedrock/common_utils.py +++ b/litellm/llms/bedrock/common_utils.py @@ -1218,6 +1218,8 @@ class BedrockModelInfo(BaseLLMModelInfo): alt_model: Final = BedrockModelInfo.get_non_litellm_routing_model_name(model=model) if base_model in litellm.bedrock_converse_models or alt_model in litellm.bedrock_converse_models: return "converse" + if _OPENAI_FAMILY_MODEL_RE.search(base_model): + return "converse" return "invoke" @staticmethod diff --git a/tests/e2e/llm_translation/test_bedrock_provider_matrix_e2e.py b/tests/e2e/llm_translation/test_bedrock_provider_matrix_e2e.py index 5f0a931109c..21333d39849 100644 --- a/tests/e2e/llm_translation/test_bedrock_provider_matrix_e2e.py +++ b/tests/e2e/llm_translation/test_bedrock_provider_matrix_e2e.py @@ -8,7 +8,8 @@ caller can hand AWS support the request id behind a completion. Regional inference-profile ids are the deployment shape most Bedrock customers run; a v1.90.0 regression timed them out, and the Converse route keeps them covered in test_chat_completions_regression_e2e.py, so the invoke route carries its own -rows here. +rows here. The file also covers Bedrock-native OpenAI model ids taking the +default (Converse) route with max_tokens. """ from __future__ import annotations @@ -26,6 +27,7 @@ pytestmark = pytest.mark.e2e CONVERSE_REGIONAL_BACKEND = "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0" INVOKE_REGIONAL_BACKEND = "bedrock/invoke/us.anthropic.claude-haiku-4-5-20251001-v1:0" +OPENAI_FAMILY_BACKEND = "bedrock/global.openai.gpt-6-sol" PROVIDER_HEADER_PREFIX = "llm_provider-" BEDROCK_REQUEST_ID_HEADER = "llm_provider-x-amzn-requestid" @@ -199,3 +201,18 @@ class TestBedrockInvokeRegionalModelIds: ) _assert_streamed_completion(result) + + +class TestBedrockOpenAIFamilyDefaultRoute: + @pytest.mark.covers("llm.chat_completions.bedrock_converse.basic.nonstream.works", exercised_on=[]) + def test_openai_family_model_id_completes_with_max_tokens( + self, client: PassthroughClient, resources: ResourceManager + ) -> None: + model = _register_bedrock_model( + client, resources, "e2e-bedrock-openai-family", OPENAI_FAMILY_BACKEND + ) + key = resources.key() + + response = unwrap(client.proxy.chat(key, ChatBody(model=model, messages=_prompt(), max_tokens=64))) + + _assert_completion(response) diff --git a/tests/test_litellm/llms/bedrock/test_bedrock_common_utils.py b/tests/test_litellm/llms/bedrock/test_bedrock_common_utils.py index 117814a41ff..e5118f90e44 100644 --- a/tests/test_litellm/llms/bedrock/test_bedrock_common_utils.py +++ b/tests/test_litellm/llms/bedrock/test_bedrock_common_utils.py @@ -346,7 +346,7 @@ def test_route_prefix_matched_as_path_segment_not_substring(): BedrockModelInfo.get_bedrock_route("bedrock_mantle/openai.gpt-5.5") != "mantle" ) assert ( - BedrockModelInfo.get_bedrock_route("bedrock_mantle/openai.gpt-5.4") == "invoke" + BedrockModelInfo.get_bedrock_route("bedrock_mantle/openai.gpt-5.4") == "converse" ) assert ( BedrockModelInfo._explicit_mantle_route("bedrock_mantle/openai.gpt-5.5") @@ -964,3 +964,20 @@ def test_s3_static_key_pair_is_none_without_a_full_pair(partial_s3_pair): from litellm.llms.bedrock.common_utils import s3_static_key_pair assert s3_static_key_pair({"aws_access_key_id": "bedrock-key", **partial_s3_pair}) is None + + +def test_unmapped_openai_family_model_routes_to_converse(): + """A Bedrock-native OpenAI model that is not in the cost map yet must not fall to the invoke route. + + The invoke ``openai`` provider is the imported-model path and sends ``max_tokens``, which Bedrock + rejects for these models; Converse maps it to ``inferenceConfig.maxTokens``. + """ + from typing import Final + + import litellm + + unmapped: Final = "bedrock/global.openai.gpt-99-unmapped" + assert unmapped.removeprefix("bedrock/") not in litellm.bedrock_converse_models + assert BedrockModelInfo.get_bedrock_route(unmapped) == "converse" + imported: Final = "bedrock/openai/arn:aws:bedrock:us-east-1:123456789012:imported-model/abc123" + assert BedrockModelInfo.get_bedrock_route(imported) == "openai"