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
Add supports_native_websocket to handle providers who don't handle websocket
Sameer Kankutebe9c09e8d225
diff --git a/litellm/llms/base_llm/responses/transformation.py b/litellm/llms/base_llm/responses/transformation.pyindex 7a4da985528..4cc3583ed89 100644--- a/litellm/llms/base_llm/responses/transformation.py+++ b/litellm/llms/base_llm/responses/transformation.py@@ -218,6 +218,18 @@ class BaseResponsesAPIConfig(ABC):"""Returns True if litellm should fake a stream for the given model and stream value"""return False+ def supports_native_websocket(self) -> bool:+ """+ Returns True if the provider has a native WebSocket endpoint for Responses API.++ Providers with native websocket support can connect directly to wss:// endpoints.+ Providers without native support will use the ManagedResponsesWebSocketHandler+ which makes HTTP streaming calls and forwards events over the websocket.++ Default: False (use managed websocket handler)+ """+ return False+################################################################### CANCEL RESPONSE API TRANSFORMATION ###################################################################diff --git a/litellm/llms/chatgpt/responses/transformation.py b/litellm/llms/chatgpt/responses/transformation.pyindex bcb6edd39f9..66acd933416 100644--- a/litellm/llms/chatgpt/responses/transformation.py+++ b/litellm/llms/chatgpt/responses/transformation.py@@ -1,14 +1,14 @@import jsonfrom typing import Any, Optional-from litellm.exceptions import AuthenticationErrorfrom litellm.constants import STREAM_SSE_DONE_STRING+from litellm.exceptions import AuthenticationErrorfrom litellm.litellm_core_utils.core_helpers import process_response_headers-from litellm.llms.openai.common_utils import OpenAIError-from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfigfrom litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response import (_safe_convert_created_field,)+from litellm.llms.openai.common_utils import OpenAIError+from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfigfrom litellm.types.llms.openai import (ResponsesAPIResponse,ResponsesAPIStreamEvents,@@ -200,3 +200,7 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig):api_base = api_base or self.authenticator.get_api_base() or CHATGPT_API_BASEapi_base = api_base.rstrip("/")return f"{api_base}/responses"++ def supports_native_websocket(self) -> bool:+ """ChatGPT does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/databricks/responses/transformation.py b/litellm/llms/databricks/responses/transformation.pyindex 0d9f433bfd2..090fef5ac82 100644--- a/litellm/llms/databricks/responses/transformation.py+++ b/litellm/llms/databricks/responses/transformation.py@@ -98,3 +98,7 @@ class DatabricksResponsesAPIConfig(DatabricksBase, OpenAIResponsesAPIConfig):litellm_params=litellm_params,headers=headers,)++ def supports_native_websocket(self) -> bool:+ """Databricks does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/github_copilot/responses/transformation.py b/litellm/llms/github_copilot/responses/transformation.pyindex e19fabc17c7..73240d46512 100644--- a/litellm/llms/github_copilot/responses/transformation.py+++ b/litellm/llms/github_copilot/responses/transformation.py@@ -22,8 +22,8 @@ from litellm.types.utils import LlmProvidersfrom ..authenticator import Authenticatorfrom ..common_utils import (- GetAPIKeyError,GITHUB_COPILOT_API_BASE,+ GetAPIKeyError,get_copilot_default_headers,)@@ -329,3 +329,7 @@ class GithubCopilotResponsesAPIConfig(OpenAIResponsesAPIConfig):)return False++ def supports_native_websocket(self) -> bool:+ """GitHub Copilot does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/hosted_vllm/responses/transformation.py b/litellm/llms/hosted_vllm/responses/transformation.pyindex 4dfead0d980..4d44eeda9f9 100644--- a/litellm/llms/hosted_vllm/responses/transformation.py+++ b/litellm/llms/hosted_vllm/responses/transformation.py@@ -69,3 +69,7 @@ class HostedVLLMResponsesAPIConfig(OpenAIResponsesAPIConfig):return f"{api_base}/responses"return f"{api_base}/v1/responses"++ def supports_native_websocket(self) -> bool:+ """Hosted vLLM does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/litellm_proxy/responses/transformation.py b/litellm/llms/litellm_proxy/responses/transformation.pyindex 0b81d8be7d8..a122b768751 100644--- a/litellm/llms/litellm_proxy/responses/transformation.py+++ b/litellm/llms/litellm_proxy/responses/transformation.py@@ -46,3 +46,7 @@ class LiteLLMProxyResponsesAPIConfig(OpenAIResponsesAPIConfig):api_base = api_base.rstrip("/")return f"{api_base}/responses"++ def supports_native_websocket(self) -> bool:+ """LiteLLM Proxy does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/manus/responses/transformation.py b/litellm/llms/manus/responses/transformation.pyindex fbbed19f8d4..bf1a6fab503 100644--- a/litellm/llms/manus/responses/transformation.py+++ b/litellm/llms/manus/responses/transformation.py@@ -247,6 +247,10 @@ class ManusResponsesAPIConfig(OpenAIResponsesAPIConfig):response._hidden_params["headers"] = raw_response_headersreturn response+ def supports_native_websocket(self) -> bool:+ """Manus does not support native WebSocket for Responses API"""+ return False+def transform_get_response_api_request(self,response_id: str,diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.pyindex 3e089682097..2988e0970a3 100644--- a/litellm/llms/openai/responses/transformation.py+++ b/litellm/llms/openai/responses/transformation.py@@ -344,6 +344,10 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):)return False+ def supports_native_websocket(self) -> bool:+ """OpenAI supports native WebSocket for Responses API"""+ return True+################################################################### DELETE RESPONSE API TRANSFORMATION #######################################################################diff --git a/litellm/llms/openrouter/responses/transformation.py b/litellm/llms/openrouter/responses/transformation.pyindex ddce6fd3844..864e1549274 100644--- a/litellm/llms/openrouter/responses/transformation.py+++ b/litellm/llms/openrouter/responses/transformation.py@@ -75,3 +75,7 @@ class OpenRouterResponsesAPIConfig(OpenAIResponsesAPIConfig):api_base = api_base.rstrip("/")return f"{api_base}/responses"++ def supports_native_websocket(self) -> bool:+ """OpenRouter does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/perplexity/responses/transformation.py b/litellm/llms/perplexity/responses/transformation.pyindex 6d2ed51600c..b6feb4ae498 100644--- a/litellm/llms/perplexity/responses/transformation.py+++ b/litellm/llms/perplexity/responses/transformation.py@@ -490,3 +490,7 @@ class PerplexityResponsesConfig(OpenAIResponsesAPIConfig):verbose_logger.debug("Failed to transform Perplexity cost object: %s", e)return chunk++ def supports_native_websocket(self) -> bool:+ """Perplexity does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/volcengine/responses/transformation.py b/litellm/llms/volcengine/responses/transformation.pyindex 872c8dcf118..f9ed93f680c 100644--- a/litellm/llms/volcengine/responses/transformation.py+++ b/litellm/llms/volcengine/responses/transformation.py@@ -16,16 +16,17 @@ from pydantic import fields as pyd_fieldsimport litellmfrom litellm._logging import verbose_logger-from litellm.types.llms.openai import ResponseInputParam, ResponsesAPIStreamingResponse-from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfigfrom litellm.litellm_core_utils.core_helpers import process_response_headersfrom litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response import (_safe_convert_created_field,)+from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfigfrom litellm.secret_managers.main import get_secret_strfrom litellm.types.llms.openai import (+ ResponseInputParam,ResponsesAPIOptionalRequestParams,ResponsesAPIResponse,+ ResponsesAPIStreamingResponse,)from litellm.types.responses.main import DeleteResponseResultfrom litellm.types.router import GenericLiteLLMParams@@ -555,3 +556,7 @@ class VolcEngineResponsesAPIConfig(OpenAIResponsesAPIConfig):# Fall back to the first candidatereturn candidates[0]++ def supports_native_websocket(self) -> bool:+ """VolcEngine does not support native WebSocket for Responses API"""+ return Falsediff --git a/litellm/llms/xai/responses/transformation.py b/litellm/llms/xai/responses/transformation.pyindex 95873aab846..3c69b7d08b7 100644--- a/litellm/llms/xai/responses/transformation.py+++ b/litellm/llms/xai/responses/transformation.py@@ -252,3 +252,7 @@ class XAIResponsesAPIConfig(OpenAIResponsesAPIConfig):return f"{api_base}/responses"+ def supports_native_websocket(self) -> bool:+ """XAI does not support native WebSocket for Responses API"""+ return False+