{"record":{"id":"a53a131703a39be0","repo":"openai/codex","slug":"asynccodex-is-not-initialized-yet-prefer-async-w","errorCode":null,"errorMessage":"AsyncCodex is not initialized yet. Prefer `async with AsyncCodex()`; initialization also happens on first awaited API use.","messagePattern":"AsyncCodex is not initialized yet\\. Prefer `async with AsyncCodex\\(\\)`; initialization also happens on first awaited API use\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdk/python/src/openai_codex/api.py","lineNumber":330,"sourceCode":"            return\n        async with self._init_lock:\n            if self._initialized:\n                return\n            try:\n                await self._client.start()\n                payload = await self._client.initialize()\n                self._init = validate_initialize_metadata(payload)\n                self._initialized = True\n            except Exception:\n                await self._client.close()\n                self._init = None\n                self._initialized = False\n                raise\n\n    @property\n    def metadata(self) -> InitializeResponse:\n        if self._init is None:\n            raise RuntimeError(\n                \"AsyncCodex is not initialized yet. Prefer `async with AsyncCodex()`; \"\n                \"initialization also happens on first awaited API use.\"\n            )\n        return self._init\n\n    async def close(self) -> None:\n        await self._client.close()\n        self._init = None\n        self._initialized = False\n\n    async def login_api_key(self, api_key: str) -> None:\n        \"\"\"Authenticate Codex with an API key.\"\"\"\n        await self._ensure_initialized()\n        await self._client.account_login_start(\n            LoginAccountParams(\n                root=ApiKeyLoginAccountParams(\n                    api_key=api_key,\n                    type=\"apiKey\",","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/sdk/python/src/openai_codex/api.py#L312-L348","documentation":"Error \"AsyncCodex is not initialized yet. Prefer `async with AsyncCodex()`; initialization also happens on first awaited API use.\" thrown in openai/codex.","triggerScenarios":"Thrown at sdk/python/src/openai_codex/api.py:330 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use async with AsyncCodex() or await an API call so initialization completes before this operation."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}