From 6e84ff0cb2a8fe8aba1cb7603268910c210b3eb3 Mon Sep 17 00:00:00 2001 From: yassin Date: Thu, 17 Sep 2026 20:57:28 +0000 Subject: [PATCH] fix(bedrock): keep raw SDK import failure out of the realtime client error Log the underlying ImportError server side and send the client only the installed version, the supported range and the install hint Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/llms/bedrock/realtime/handler.py | 3 ++- .../llms/bedrock/realtime/test_bedrock_realtime_handler.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/llms/bedrock/realtime/handler.py b/litellm/llms/bedrock/realtime/handler.py index fa9d4e3b850..fe3822629a7 100644 --- a/litellm/llms/bedrock/realtime/handler.py +++ b/litellm/llms/bedrock/realtime/handler.py @@ -139,11 +139,12 @@ def _installed_sdk_version() -> str | None: def _sdk_import_error(installed_version: str | None, cause: ImportError) -> ImportError: install_hint: Final = "pip install 'litellm[bedrock-realtime]'" requirement: Final = f"{BEDROCK_REALTIME_SDK_DISTRIBUTION}[awscrt]{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE}" + verbose_proxy_logger.error("Bedrock Realtime: SDK import failed (installed=%s): %s", installed_version, cause) if installed_version is None: return ImportError(f"Missing aws_sdk_bedrock_runtime: {install_hint} ({requirement})") return ImportError( f"{BEDROCK_REALTIME_SDK_DISTRIBUTION} {installed_version} is installed but Bedrock realtime needs " - f"[awscrt]{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE}: {install_hint}. Import failed with: {cause}" + f"[awscrt]{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE}: {install_hint}" ) diff --git a/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.py b/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.py index c2000e6cd50..21838759acd 100644 --- a/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.py +++ b/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.py @@ -995,6 +995,9 @@ class TestBedrockRealtimeSdkImportErrors: assert "aws-sdk-bedrock-runtime 0.7.0 is installed but" in message assert ">=0.10.0,<0.12.0" in message assert not message.startswith("Missing aws_sdk_bedrock_runtime") + assert isinstance(exc_info.value.__cause__, ImportError) + assert str(exc_info.value.__cause__) not in message + assert "cannot import name" not in message close_reason = message.encode()[:WEBSOCKET_CLOSE_REASON_MAX_BYTES].decode() assert "0.7.0 is installed" in close_reason assert BEDROCK_REALTIME_SDK_SUPPORTED_RANGE in close_reason