Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(bedrock): keep realtime SDK error range inside websocket close reason

yassinbb9ff8cb2c49
diff --git a/litellm/llms/bedrock/realtime/handler.py b/litellm/llms/bedrock/realtime/handler.py
index 2841dc0e071..fa9d4e3b850 100644
--- a/litellm/llms/bedrock/realtime/handler.py
+++ b/litellm/llms/bedrock/realtime/handler.py
@@ -137,15 +137,13 @@ def _installed_sdk_version() -> str | None:
def _sdk_import_error(installed_version: str | None, cause: ImportError) -> ImportError:
- install_hint: Final = (
- "Install with: pip install 'litellm[bedrock-realtime]' "
- f"(pins {BEDROCK_REALTIME_SDK_DISTRIBUTION}[awscrt]{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE})"
- )
+ install_hint: Final = "pip install 'litellm[bedrock-realtime]'"
+ requirement: Final = f"{BEDROCK_REALTIME_SDK_DISTRIBUTION}[awscrt]{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE}"
if installed_version is None:
- return ImportError(f"Missing aws_sdk_bedrock_runtime for Bedrock realtime. {install_hint}")
+ 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 supports "
- f"{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE} with the awscrt transport: {cause}. {install_hint}"
+ 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}"
)
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 c16db836748..c2000e6cd50 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
@@ -8,7 +8,11 @@ from unittest.mock import MagicMock
import pytest
import litellm
-from litellm.constants import REALTIME_SESSION_SUCCESS_LOGGED_KEY
+from litellm.constants import (
+ BEDROCK_REALTIME_SDK_SUPPORTED_RANGE,
+ REALTIME_SESSION_SUCCESS_LOGGED_KEY,
+ WEBSOCKET_CLOSE_REASON_MAX_BYTES,
+)
from litellm.llms.bedrock.common_utils import BedrockError
from litellm.llms.bedrock.realtime.handler import BedrockRealtime
from litellm.llms.bedrock.realtime.transformation import BedrockRealtimeConfig
@@ -969,6 +973,9 @@ class TestBedrockRealtimeSdkImportErrors:
assert message.startswith("Missing aws_sdk_bedrock_runtime")
assert "litellm[bedrock-realtime]" in message
assert "is installed but" not in message
+ close_reason = message.encode()[:WEBSOCKET_CLOSE_REASON_MAX_BYTES].decode()
+ assert BEDROCK_REALTIME_SDK_SUPPORTED_RANGE in close_reason
+ assert "pip install 'litellm[bedrock-realtime]'" in close_reason
@pytest.mark.asyncio
async def test_incompatible_sdk_names_installed_version_and_supported_range(self, monkeypatch):
@@ -988,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")
+ 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
if __name__ == "__main__":
diff --git a/tests/test_litellm/test_dockerfile_bedrock_realtime_extra.py b/tests/test_litellm/test_dockerfile_bedrock_realtime_extra.py
index 84e5e9e2af2..e157c982105 100644
--- a/tests/test_litellm/test_dockerfile_bedrock_realtime_extra.py
+++ b/tests/test_litellm/test_dockerfile_bedrock_realtime_extra.py
@@ -4,7 +4,7 @@ Static checks that every proxy Docker image installs the `bedrock-realtime` extr
Bedrock Nova Sonic speech-to-speech (`/v1/realtime`) needs `aws-sdk-bedrock-runtime`,
which only ships in the `bedrock-realtime` extra. An image whose `uv sync` stages
omit the extra fails every Nova Sonic realtime session with
-"Missing aws_sdk_bedrock_runtime for Bedrock realtime".
+"Missing aws_sdk_bedrock_runtime: pip install 'litellm[bedrock-realtime]' ...".
"""
import os