From ead8aa82ef19a82b0554d7e93ca920790a227132 Mon Sep 17 00:00:00 2001 From: shrey Date: Sat, 31 Oct 2026 15:49:59 -0700 Subject: [PATCH] fix(passthrough): fit the Deepgram listen unpriced refusal in a WebSocket close frame (#49502) --- .../llm_passthrough_endpoints.py | 4 +++- .../test_deepgram_ws_passthrough_routes.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py index f7f0cf2ab3b..c7983f40aec 100644 --- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py @@ -3614,7 +3614,9 @@ async def deepgram_listen_websocket_route( if not deepgram_listen_is_priced(target): await websocket.close( code=1008, - reason=_DEEPGRAM_WS_UNPRICED_REASON.format(registry_key=deepgram_listen_registry_key(target)), + reason=truncated_close_reason( + _DEEPGRAM_WS_UNPRICED_REASON.format(registry_key=deepgram_listen_registry_key(target)) + ), ) return diff --git a/tests/unit/proxy/pass_through_endpoints/test_deepgram_ws_passthrough_routes.py b/tests/unit/proxy/pass_through_endpoints/test_deepgram_ws_passthrough_routes.py index b21a5e6c337..5e31906a4b9 100644 --- a/tests/unit/proxy/pass_through_endpoints/test_deepgram_ws_passthrough_routes.py +++ b/tests/unit/proxy/pass_through_endpoints/test_deepgram_ws_passthrough_routes.py @@ -286,6 +286,20 @@ async def test_deepgram_listen_refuses_sessions_it_cannot_price(query, missing_k assert "dg-provider-key" not in websocket.closed[1] +@pytest.mark.asyncio +async def test_deepgram_listen_refusal_for_a_long_unpriced_model_fits_a_close_frame( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.delenv("DEEPGRAM_API_BASE", raising=False) + monkeypatch.setenv("DEEPGRAM_API_KEY", "dg-provider-key") + websocket: Final = _FakeWebSocket("/deepgram/v1/listen", "model=" + "%C3%A9" * 100) + + relay: Final = await _serve(websocket) + + assert relay.calls == [] + assert websocket.closed == (1008, "No streaming price for 'deepgram/streaming/" + "é" * 40) + + @pytest.mark.asyncio async def test_deepgram_listen_relays_once_the_operator_prices_the_model(monkeypatch): monkeypatch.delenv("DEEPGRAM_API_BASE", raising=False)