From 48cf730230f3d02b35b26ca9aa161f1d3d9b5f8d Mon Sep 17 00:00:00 2001 From: Leonardo Freitas dos Santos Date: Tue, 15 Sep 2026 18:30:51 +0200 Subject: [PATCH] fix(bedrock): build the Responses endpoint from the region's partition suffix get_complete_url hardcoded amazonaws.com in an f-string, so every non-commercial partition got the wrong host: cn-north-1 resolved to amazonaws.com instead of amazonaws.com.cn, and GovCloud/ISO regions were wrong the same way. Defer to BaseAWSLLM._select_default_endpoint_url, which this config already inherits and which resolves the suffix per partition. test_no_fstring_hardcodes_the_commercial_dns_suffix scans the whole tree, so it caught this even though it is not one of this PR's test files. Register the config in ENDPOINT_BUILDERS so the cn/GovCloud endpoint sweep covers this surface from now on rather than only the f-string guard. Co-Authored-By: Claude Opus 5 --- litellm/llms/bedrock/responses/transformation.py | 8 ++++++-- litellm/llms/bedrock_mantle/responses/transformation.py | 1 - .../test_litellm/litellm_core_utils/test_aws_partition.py | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/litellm/llms/bedrock/responses/transformation.py b/litellm/llms/bedrock/responses/transformation.py index a2996c97a10..7b735dd0b29 100644 --- a/litellm/llms/bedrock/responses/transformation.py +++ b/litellm/llms/bedrock/responses/transformation.py @@ -1,7 +1,7 @@ """Amazon Bedrock Runtime - native OpenAI Responses API. AWS serves the OpenAI models on ``bedrock-runtime`` through an OpenAI-compatible -surface at ``https://bedrock-runtime.{region}.amazonaws.com/openai/v1/responses``, +surface at ``https://bedrock-runtime.{region}.{dns_suffix}/openai/v1/responses``, alongside Converse. Without this config the ``bedrock`` provider has no Responses config at all, so ``/v1/responses`` falls back to the Chat Completions bridge and the request is translated into Converse. A realistic Codex session does not @@ -86,7 +86,11 @@ class BedrockOpenAIResponsesConfig(BaseAWSLLM, OpenAIResponsesAPIConfig): or litellm_params.get("aws_bedrock_runtime_endpoint") or get_secret_str("AWS_BEDROCK_RUNTIME_ENDPOINT") ) - host: Final = (override or f"https://bedrock-runtime.{region}.amazonaws.com").rstrip("/") + # Partition-aware: bedrock-runtime is amazonaws.com.cn in China, and other + # suffixes in GovCloud/ISO, so defer to the shared endpoint builder. + host: Final = ( + override or self._select_default_endpoint_url(endpoint_type="runtime", aws_region_name=region) + ).rstrip("/") if host.endswith(BEDROCK_RUNTIME_OPENAI_RESPONSES_PATH): return host base: Final = next( diff --git a/litellm/llms/bedrock_mantle/responses/transformation.py b/litellm/llms/bedrock_mantle/responses/transformation.py index 79a5789c151..0ab8467d222 100644 --- a/litellm/llms/bedrock_mantle/responses/transformation.py +++ b/litellm/llms/bedrock_mantle/responses/transformation.py @@ -59,7 +59,6 @@ _BEDROCK_MANTLE_SUPPORTED_SERVICE_TIERS: Final = frozenset({"auto", "default"}) _BEDROCK_MANTLE_OPENAI_PATH_SUPPORTED_REASONING_SUMMARIES: Final = frozenset({"auto"}) - class BedrockMantleResponsesAPIConfig(BedrockMantleAuthMixin, OpenAIResponsesAPIConfig): def __init__( self, diff --git a/tests/test_litellm/litellm_core_utils/test_aws_partition.py b/tests/test_litellm/litellm_core_utils/test_aws_partition.py index 3594d3c354c..b7f99cf0f18 100644 --- a/tests/test_litellm/litellm_core_utils/test_aws_partition.py +++ b/tests/test_litellm/litellm_core_utils/test_aws_partition.py @@ -21,6 +21,7 @@ from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM from litellm.llms.bedrock.batches.transformation import BedrockBatchesConfig from litellm.llms.bedrock.chat.agentcore.transformation import AmazonAgentCoreConfig from litellm.llms.bedrock.common_utils import init_bedrock_client +from litellm.llms.bedrock.responses.transformation import BedrockOpenAIResponsesConfig from litellm.llms.sagemaker.chat.transformation import SagemakerChatConfig @@ -152,6 +153,10 @@ ENDPOINT_BUILDERS: Final = { litellm_params={}, stream=True, ), + "bedrock_openai_responses": lambda region: BedrockOpenAIResponsesConfig().get_complete_url( + api_base=None, + litellm_params={"aws_region_name": region}, + ), "s3_object_url": _s3_object_url, }