{"record":{"id":"bc1ee22a9cd22593","repo":"BerriAI/litellm","slug":"api-key-is-required-for-openai-realtime-calls","errorCode":null,"errorMessage":"api_key is required for OpenAI realtime calls","messagePattern":"api_key is required for OpenAI realtime calls","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/realtime/handler.py","lineNumber":127,"sourceCode":"        model: str,\n        websocket: Any,\n        logging_obj: LiteLLMLogging,\n        api_base: str | None = None,\n        api_key: str | None = None,\n        client: Any | None = None,\n        timeout: float | None = None,\n        query_params: RealtimeQueryParams | None = None,\n        user_api_key_dict: Any | None = None,\n        litellm_metadata: dict | None = None,\n        **kwargs: Any,\n    ):\n        import websockets\n        from websockets.asyncio.client import ClientConnection\n\n        if api_base is None:\n            api_base = self._get_default_api_base()\n        if api_key is None:\n            raise ValueError(\"api_key is required for OpenAI realtime calls\")\n\n        # Use all query params if provided, else fallback to just model\n        if query_params is None:\n            query_params = {\"model\": model}\n        url: Final = self._construct_url(api_base, query_params)\n\n        try:\n            # Get provider-specific SSL configuration\n            ssl_config: Final = self._get_ssl_config(url)\n\n            openai_beta_realtime: Final = client_sent_openai_beta_realtime_header(websocket)\n            if not openai_beta_realtime:\n                verbose_logger.debug(\n                    \"OpenAI Realtime: connecting with GA protocol (no OpenAI-Beta header). \"\n                    \"If your client expects beta event names, add 'OpenAI-Beta: realtime=v1' \"\n                    \"to the WebSocket headers sent to the LiteLLM proxy.\"\n                )\n            headers: Final = self._get_additional_headers(api_key, openai_beta_realtime=openai_beta_realtime)","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openai/realtime/handler.py#L109-L145","documentation":"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.","triggerScenarios":"Thrown at litellm/llms/openai/realtime/handler.py:127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass api_key='...' or set OPENAI_API_KEY before making realtime calls."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}