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(passthrough): hoist websocket forwarded header set
shivam7bcf848b3988
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.pyindex 1c4f8d59c9c..186318dccc1 100644--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py@@ -2159,6 +2159,9 @@ def _upstream_close_to_relay(task_results: Iterable[object]) -> Close | None:return upstream_close+_WEBSOCKET_FORWARDED_HEADERS: Final = frozenset(("authorization", "x-api-key", "x-goog-user-project"))++async def websocket_passthrough_request(websocket: WebSocket,target: str,@@ -2183,6 +2186,7 @@ async def websocket_passthrough_request(cost_per_request: Optional field - cost per request to the target endpointsetup_model_rewriter: Optional rewrite of the setup frame's model before it reaches the upstream"""+ from litellm.integrations.otel.plumbing.context import inject_trace_contextfrom litellm.litellm_core_utils.litellm_logging import Loggingfrom litellm.proxy.proxy_server import proxy_config, proxy_logging_objfrom litellm.types.passthrough_endpoints.pass_through_endpoints import (@@ -2201,22 +2205,16 @@ async def websocket_passthrough_request(await websocket.accept()verbose_proxy_logger.debug("WebSocket passthrough (%s): WebSocket connection accepted", endpoint)- from litellm.integrations.otel.plumbing.context import inject_trace_context-- incoming_headers: Final = dict(websocket.headers) # mutable-ok: websocket headers are copied for context extraction- forwarded_headers: Final = { # mutable-ok: assembled as the upstream header carrier+ incoming_headers: Final = dict(websocket.headers) # mutable-ok: propagator carrier+ forwarded_headers: Final = { # mutable-ok: propagator carrier**custom_headers,**{header_name: header_valuefor header_name, header_value in incoming_headers.items()- if forward_headers- and header_name.lower() in frozenset(("authorization", "x-api-key", "x-goog-user-project"))+ if forward_headers and header_name.lower() in _WEBSOCKET_FORWARDED_HEADERS},}- upstream_headers: Final = inject_trace_context(- forwarded_headers,- inbound_headers=incoming_headers,- )+ upstream_headers: Final = inject_trace_context(forwarded_headers, inbound_headers=incoming_headers)# Initialize logging object similar to HTTP passthroughteam_callbacks: Final = _resolve_team_callback_wiring(