{"record":{"id":"91ea5642db0fbb15","repo":"openai/openai-python","slug":"you-need-to-install-openai-realtime-to-use-this-91ea56","errorCode":null,"errorMessage":"You need to install `openai[realtime]` to use this method","messagePattern":"You need to install `openai\\[realtime\\]` to use this method","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"src/openai/resources/responses/responses.py","lineNumber":4414,"sourceCode":"            initial_delay=self.__initial_delay,\n            max_delay=self.__max_delay,\n            extra_query=self.__extra_query,\n            extra_headers=self.__extra_headers,\n            send_queue=self.__send_queue,\n        )\n\n        self.__event_handler_registry.merge_into(self.__connection._event_handler_registry)\n        await self.__connection._flush_send_queue()\n\n        return self.__connection\n\n    enter = __aenter__\n\n    async def _connect_ws(self, extra_query: Query, extra_headers: Headers) -> AsyncWebSocketConnection:\n        try:\n            from ...lib._websocket import _WebSocketConnect as connect\n        except ImportError as exc:\n            raise OpenAIError(\"You need to install `openai[realtime]` to use this method\") from exc\n\n        url = self._prepare_url().copy_with(\n            params={\n                **self.__client.base_url.params,\n                **extra_query,\n            },\n        )\n        log.debug(\"Connecting to WebSocket API\")\n        if self.__websocket_connection_options:\n            log.debug(\"Custom WebSocket connection options provided\")\n\n        return await connect(\n            str(url),\n            user_agent_header=self.__client.user_agent,\n            additional_headers=_merge_mappings(\n                {\n                    **self.__client.auth_headers,\n                },","sourceCodeStart":4396,"sourceCodeEnd":4432,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/resources/responses/responses.py#L4396-L4432","documentation":"Raised by _connect_ws when importing the WebSocket transport (openai.lib._websocket) fails because the `websockets` dependency is not installed. The realtime-style Responses WebSocket API is an optional extra, so the SDK tells you to install openai[realtime].","triggerScenarios":"Calling client.responses.websocket or any WS-connecting method in an environment where `pip install openai` was done without extras and no websockets package is present.","commonSituations":"Slim Docker images installing only openai; deploying to serverless/Lambda layers that strip optional deps; CI environments missing extras; upgrading the SDK and adopting the WS API without adding the extra.","solutions":["Install the extra: pip install 'openai[realtime]' (or uv add 'openai[realtime]')","Add websockets to requirements/pyproject alongside openai","Rebuild the Docker image/deployment package to include the extra"],"exampleFix":"# before\npip install openai\n# after\npip install 'openai[realtime]'","handlingStrategy":"validation","validationCode":"try:\n    import websockets  # noqa: F401\n    ws_ok = True\nexcept ImportError:\n    ws_ok = False\nif not ws_ok:\n    raise RuntimeError(\"install 'openai[realtime]' before using WebSocket APIs\")","typeGuard":"def realtime_available() -> bool:\n    try:\n        import websockets  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"from openai import OpenAIError\ntry:\n    conn = await client.responses._connect_ws(q, h)\nexcept OpenAIError as e:\n    if 'openai[realtime]' in str(e):\n        raise SystemExit(\"Run: pip install 'openai[realtime]'\") from e\n    raise","preventionTips":["Declare openai[realtime] in project dependencies when using WS APIs","Include extras in Docker/deployment installs","Add an import-time capability check before enabling realtime features"],"tags":["websocket","realtime","missing-dependency","installation","python"],"backgroundTag":"missing-optional-dependency","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}