BerriAI/litellm · error · ValueError

api_key is required for OpenAI realtime calls

Error message

api_key is required for OpenAI realtime calls

What it means

Guard in the OpenAI Realtime websocket handler: the api_key parameter is None and no OPENAI_API_KEY is available, so the wss:// connection to OpenAI realtime cannot be authenticated. The handler refuses to open the socket rather than failing mid-handshake.

Source

Thrown at litellm/llms/openai/realtime/handler.py:127

        model: str,
        websocket: Any,
        logging_obj: LiteLLMLogging,
        api_base: str | None = None,
        api_key: str | None = None,
        client: Any | None = None,
        timeout: float | None = None,
        query_params: RealtimeQueryParams | None = None,
        user_api_key_dict: Any | None = None,
        litellm_metadata: dict | None = None,
        **kwargs: Any,
    ):
        import websockets
        from websockets.asyncio.client import ClientConnection

        if api_base is None:
            api_base = self._get_default_api_base()
        if api_key is None:
            raise ValueError("api_key is required for OpenAI realtime calls")

        # Use all query params if provided, else fallback to just model
        if query_params is None:
            query_params = {"model": model}
        url: Final = self._construct_url(api_base, query_params)

        try:
            # Get provider-specific SSL configuration
            ssl_config: Final = self._get_ssl_config(url)

            openai_beta_realtime: Final = client_sent_openai_beta_realtime_header(websocket)
            if not openai_beta_realtime:
                verbose_logger.debug(
                    "OpenAI Realtime: connecting with GA protocol (no OpenAI-Beta header). "
                    "If your client expects beta event names, add 'OpenAI-Beta: realtime=v1' "
                    "to the WebSocket headers sent to the LiteLLM proxy."
                )
            headers: Final = self._get_additional_headers(api_key, openai_beta_realtime=openai_beta_realtime)

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Pass api_key='...' or set OPENAI_API_KEY before making realtime calls.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/llms/openai/realtime/handler.py:127 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/bc1ee22a9cd22593. Report an issue: GitHub.