{"record":{"id":"52171569af6275b9","repo":"openai/openai-python","slug":"you-need-to-install-openai-realtime-to-use-this-521715","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/realtime/realtime.py","lineNumber":687,"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        await self.__client._refresh_api_key()\n        auth_headers = self.__client.auth_headers\n        if self.__call_id is not omit:\n            extra_query = {**extra_query, \"call_id\": self.__call_id}\n        if is_async_azure_client(self.__client):\n            from ...lib._azure_websocket import _AzureWebSocketConnect as connect\n\n            model = self.__model\n            if not model:\n                raise OpenAIError(\"`model` is required for Azure Realtime API\")\n            else:\n                url, auth_headers = await self.__client._configure_realtime(model, extra_query)\n        else:\n            url = self._prepare_url().copy_with(\n                params={\n                    **self.__client.base_url.params,\n                    **({\"model\": self.__model} if self.__model is not omit else {}),","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/resources/realtime/realtime.py#L669-L705","documentation":"Raised when the async Realtime websocket connect cannot import the optional `websockets` dependency. The Realtime API requires the `openai[realtime]` extra; without it, _connect_ws raises OpenAIError with install instructions.","triggerScenarios":"Entering `async with client.beta.realtime.connect(...)` (or lower-level Realtime context managers) on an environment where openai was installed without the [realtime] extra.","commonSituations":"Fresh environments with plain `pip install openai`, CI images, slim Docker containers, or upgrading from a setup that previously had websockets installed transitively.","solutions":["Install the extra: pip install \"openai[realtime]\" (or uv add \"openai[realtime]\" / poetry add \"openai[realtime]\")","Verify with `python -c \"import websockets\"` that the dependency now resolves","Pin the extra in requirements.txt/pyproject so environments stay consistent"],"exampleFix":"# before\npip install openai\n# after\npip install \"openai[realtime]\"","handlingStrategy":"validation","validationCode":"try:\n    import websockets  # noqa: F401\n    has_realtime = True\nexcept ImportError:\n    has_realtime = False\nif not has_realtime:\n    raise RuntimeError(\"install openai[realtime] before using Realtime\")","typeGuard":null,"tryCatchPattern":"try:\n    async with client.beta.realtime.connect(model=m) as conn: ...\nexcept OpenAIError as e:\n    if \"openai[realtime]\" in str(e):\n        subprocess check / install instructions","preventionTips":["Declare the [realtime] extra in pyproject/requirements","Verify websockets import in environment smoke tests","Pin dependency extras in Docker/CI images"],"tags":["realtime","missing-dependency","async","installation"],"backgroundTag":"missing-optional-dependency","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}