From 9afa4629668c66322d7df99fe642f7104ccf0a76 Mon Sep 17 00:00:00 2001 From: DhruvaMyakeri Date: Fri, 28 Aug 2026 14:38:21 +0530 Subject: [PATCH] fix(azure/realtime): use byte-aware close reason for transcription socket errors Greptile flagged that reason[:120] truncates by characters, so a multibyte Azure error can push the close frame past the 123-byte WebSocket limit and turn the readable 1008 close into a generic 1011. Route both close reasons through websocket_close_reason. --- litellm/llms/azure/realtime/handler.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/litellm/llms/azure/realtime/handler.py b/litellm/llms/azure/realtime/handler.py index 044bae14bf6..0555718e25e 100644 --- a/litellm/llms/azure/realtime/handler.py +++ b/litellm/llms/azure/realtime/handler.py @@ -19,6 +19,7 @@ from litellm.constants import ( from litellm.types.realtime import RealtimeQueryParams from ....litellm_core_utils.litellm_logging import Logging as LiteLLMLogging +from ....litellm_core_utils.realtime_errors import websocket_close_reason from ....litellm_core_utils.realtime_streaming import ( RealTimeStreaming, ScopedWebSocket, @@ -242,7 +243,12 @@ class AzureOpenAIRealtime(AzureChatCompletion): else None ) if isinstance(minted, _EphemeralMintError): - await websocket.close(code=1008, reason=_redact_string(minted.reason)[:120]) + await websocket.close( + code=1008, + reason=websocket_close_reason( + _redact_string(minted.reason), fallback="Realtime transcription session error" + ), + ) return url: Final = self._construct_url( @@ -280,6 +286,9 @@ class AzureOpenAIRealtime(AzureChatCompletion): await realtime_streaming.bidirectional_forward() except websockets.exceptions.InvalidStatusCode as e: - await websocket.close(code=e.status_code, reason=_redact_string(str(e))) + await websocket.close( + code=e.status_code, + reason=websocket_close_reason(_redact_string(str(e)), fallback="Invalid status code"), + ) except Exception: verbose_proxy_logger.exception("Error in AzureOpenAIRealtime.async_realtime")