diff --git a/litellm/llms/base_llm/realtime/transformation.py b/litellm/llms/base_llm/realtime/transformation.py index d5531a532b9..22768110be9 100644 --- a/litellm/llms/base_llm/realtime/transformation.py +++ b/litellm/llms/base_llm/realtime/transformation.py @@ -69,6 +69,20 @@ class BaseRealtimeConfig(ABC): ) -> Optional[str]: # message sent to setup the realtime session return None + def transform_session_created_event( + self, + model: str, + logging_session_id: str, + session_configuration_request: Optional[str] = None, + ) -> Optional[dict]: + """ + Optional hook for providers that defer session setup until client `session.update`. + + Return an OpenAI-compatible `session.created` payload when the proxy should + emit a synthetic event immediately after backend websocket connection. + """ + return None + @abstractmethod def transform_realtime_response( self, diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index 1a73002f1b4..270aaaa84da 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -5156,20 +5156,19 @@ class BaseLLMHTTPHandler: if _session_config: realtime_streaming.session_configuration_request = _session_config - # For Gemini/Vertex AI: if no initial setup sent (waiting for client's session.update), - # send synthetic session.created to unblock client - if not provider_config.requires_session_configuration() and hasattr( - provider_config, 'transform_session_created_event' - ): + # For providers that defer setup until client session.update, optionally + # send synthetic session.created to unblock clients waiting on connect. + if not provider_config.requires_session_configuration(): synthetic_session = provider_config.transform_session_created_event( model=model, logging_session_id=logging_obj.litellm_trace_id, session_configuration_request=None, ) - await websocket.send_text(json.dumps(synthetic_session)) - verbose_logger.debug( - "Sent synthetic session.created to client to unblock connection" - ) + if synthetic_session is not None: + await websocket.send_text(json.dumps(synthetic_session)) + verbose_logger.debug( + "Sent synthetic session.created to client to unblock connection" + ) await realtime_streaming.bidirectional_forward()