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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(responses): type the websocket test parameters and suppress the error-frame send explicitly
mateo-berri9662b2a35c0a
diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.pyindex 1b1fc466046..b3d6a928a78 100644--- a/litellm/proxy/response_api_endpoints/endpoints.py+++ b/litellm/proxy/response_api_endpoints/endpoints.py@@ -1,4 +1,5 @@import asyncio+import contextlibimport jsonimport timefrom collections.abc import AsyncIterator, Awaitable, Mapping@@ -1585,10 +1586,8 @@ async def responses_websocket_endpoint()except Exception as e:verbose_proxy_logger.exception("Responses WebSocket error")- try:+ with contextlib.suppress(Exception):await websocket.send_text(_responses_ws_failure_frame(e))- except Exception:- passawait proxy_logging_obj.post_call_failure_hook(user_api_key_dict=user_api_key_dict,original_exception=e,diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.pyindex 91c334692ee..836ac42e1f5 100644--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py@@ -1069,7 +1069,7 @@ async def test_arealtime_marks_litellm_params_async(monkeypatch):@pytest.mark.asyncio-async def test_aresponses_websocket_hands_back_the_provider_failure_without_a_success_log(monkeypatch):+async def test_aresponses_websocket_hands_back_the_provider_failure_without_a_success_log(monkeypatch: pytest.MonkeyPatch):from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKERfrom litellm.responses.main import base_llm_http_handlerdiff --git a/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py b/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.pyindex 8c3bf27c88d..1560b7c32a6 100644--- a/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py+++ b/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py@@ -513,7 +513,9 @@ class TestResponsesWSFirstFrameModelAuth:@pytest.mark.asyncio@pytest.mark.parametrize("nested", [False, True])@pytest.mark.parametrize("query_model", [None, "gpt-4o-mini"])- async def test_endpoint_routes_on_first_frame_input_and_previous_response_id(self, nested, query_model):+ async def test_endpoint_routes_on_first_frame_input_and_previous_response_id(+ self, nested: bool, query_model: str | None+ ):from litellm.proxy.response_api_endpoints.endpoints import (responses_websocket_endpoint,)@@ -572,7 +574,7 @@ class TestResponsesWSFirstFrameModelAuth:@pytest.mark.asyncio@pytest.mark.parametrize("provider_rejected", [True, False])- async def test_endpoint_books_a_provider_rejected_connection_as_a_failed_request(self, provider_rejected):+ async def test_endpoint_books_a_provider_rejected_connection_as_a_failed_request(self, provider_rejected: bool):from litellm.proxy.response_api_endpoints.endpoints import (responses_websocket_endpoint,)diff --git a/tests/test_litellm/responses/test_responses_api_request_body.py b/tests/test_litellm/responses/test_responses_api_request_body.pyindex 6c1348f2350..6b5aab932ec 100644--- a/tests/test_litellm/responses/test_responses_api_request_body.py+++ b/tests/test_litellm/responses/test_responses_api_request_body.py@@ -457,7 +457,7 @@ _ORIGINAL_WS_INPUT = [@pytest.mark.asyncio@pytest.mark.parametrize("nested", [False, True])-async def test_aresponses_websocket_forwards_the_routed_input_in_the_first_frame(nested): # test-quality-ok: the first frame handed to the relay is the only place the routed input is observable before the provider socket+async def test_aresponses_websocket_forwards_the_routed_input_in_the_first_frame(nested: bool): # test-quality-ok: the first frame handed to the relay is the only place the routed input is observable before the provider socketfrom unittest.mock import MagicMockfrom litellm.responses.main import _aresponses_websocketdiff --git a/tests/test_litellm/responses/test_responses_websocket_all_providers.py b/tests/test_litellm/responses/test_responses_websocket_all_providers.pyindex b6d4d9e93a6..2fe9f231f14 100644--- a/tests/test_litellm/responses/test_responses_websocket_all_providers.py+++ b/tests/test_litellm/responses/test_responses_websocket_all_providers.py@@ -1503,7 +1503,9 @@ class TestNativeWebSocketDeploymentDefaults:assert dict(request_defaults.overrides) == {"provider_default": "configured"}@pytest.mark.asyncio- async def test_aresponses_websocket_keeps_first_frame_routing_hints_out_of_the_defaults(self, monkeypatch):+ async def test_aresponses_websocket_keeps_first_frame_routing_hints_out_of_the_defaults(+ self, monkeypatch: pytest.MonkeyPatch+ ):import importlibfrom unittest.mock import AsyncMock@@ -2976,7 +2978,7 @@ class TestNativeWebSocketEncryptedContentAffinity:@pytest.mark.asyncio@pytest.mark.parametrize("nested", [False, True])- async def test_client_to_backend_restores_wrapped_ids(self, nested):+ async def test_client_to_backend_restores_wrapped_ids(self, nested: bool):from unittest.mock import AsyncMockfrom litellm.responses.utils import ResponsesAPIRequestUtils@@ -3138,7 +3140,9 @@ class TestNativeWebSocketEncryptedContentAffinity:),],)- async def test_backend_to_client_books_failure_frames_as_failures(self, failure_frame, expected_status):+ async def test_backend_to_client_books_failure_frames_as_failures(+ self, failure_frame: dict[str, object], expected_status: int+ ):import asynciofrom unittest.mock import AsyncMock