{"record":{"id":"37fc770b866f2133","repo":"run-llama/llama_index","slug":"llama-index-llms-openai-package-not-found-pleas","errorCode":null,"errorMessage":"`llama-index-llms-openai` package not found, please run `pip install llama-index-llms-openai`","messagePattern":"`llama-index-llms-openai` package not found, please run `pip install llama-index-llms-openai`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/llms/utils.py","lineNumber":59,"sourceCode":"        # if testing return mock llm\n        if os.getenv(\"IS_TESTING\"):\n            from llama_index.core.llms.mock import MockLLM\n\n            llm = MockLLM()\n            llm.callback_manager = callback_manager or Settings.callback_manager\n            return llm\n\n        # return default OpenAI model. If it fails, return LlamaCPP\n        try:\n            from llama_index.llms.openai import OpenAI  # pants: no-infer-dep\n            from llama_index.llms.openai.utils import (\n                validate_openai_api_key,\n            )  # pants: no-infer-dep\n\n            llm = OpenAI()\n            validate_openai_api_key(llm.api_key)  # type: ignore\n        except ImportError:\n            raise ImportError(\n                \"`llama-index-llms-openai` package not found, \"\n                \"please run `pip install llama-index-llms-openai`\"\n            )\n        except ValueError as e:\n            raise ValueError(\n                \"\\n******\\n\"\n                \"Could not load OpenAI model. \"\n                \"If you intended to use OpenAI, please check your OPENAI_API_KEY.\\n\"\n                \"Original error:\\n\"\n                f\"{e!s}\"\n                \"\\n******\"\n            )\n\n    if isinstance(llm, str):\n        splits = llm.split(\":\", 1)\n        is_local = splits[0]\n        model_path = splits[1] if len(splits) > 1 else None\n        if is_local != \"local\":","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/llms/utils.py#L41-L77","documentation":"Thrown by resolve_llm (llama_index.core.llms.utils) when no explicit LLM was configured and llama-index falls back to its default OpenAI LLM, but the optional llama-index-llms-openai integration is not installed. Because core deliberately keeps provider packages optional, the ImportError tells you exactly which package to install.","triggerScenarios":"Constructing any component that auto-resolves an LLM (Settings.llm, VectorStoreIndex(...), from_documents, from_defaults without llm=) in an environment where llama-index-llms-openai is absent — e.g. installing only llama-index-core instead of the llama-index meta-package.","commonSituations":"Slim installs with just llama-index-core to save dependencies; Docker/CI images trimmed of extras; upgrading from old monolithic llama-index versions where OpenAI came bundled.","solutions":["pip install llama-index-llms-openai (or install the llama-index meta-package which includes it).","Pass an explicit LLM you already have installed: Settings.llm = MyOtherLLM() or llm=... to the component.","For tests/offline, set an explicitly available LLM such as MockLLM to avoid the OpenAI default path."],"exampleFix":"# before\nindex = VectorStoreIndex.from_documents(docs)  # no LLM set -> tries OpenAI default\n# after\npip install llama-index-llms-openai\n# or\nfrom llama_index.core.llms.mock import MockLLM\nSettings.llm = MockLLM()","handlingStrategy":"validation","validationCode":"def has_openai_integration() -> bool:\n    try:\n        import llama_index.llms.openai  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nif not has_openai_integration():\n    from llama_index.core.llms.mock import MockLLM\n    Settings.llm = MockLLM()  # or another installed LLM","typeGuard":"def is_resolvable_llm(llm) -> bool:\n    from llama_index.core.llms import LLM\n    return isinstance(llm, LLM)","tryCatchPattern":"try:\n    index = VectorStoreIndex.from_documents(docs)\nexcept ImportError as e:\n    if \"llama-index-llms-openai\" in str(e):\n        raise SystemExit(\"Install it: pip install llama-index-llms-openai\") from e\n    raise","preventionTips":["Always set Settings.llm explicitly at app startup instead of relying on the OpenAI default.","Pin llama-index-llms-openai in requirements alongside llama-index-core.","Add an import smoke test in CI for the integrations your app resolves."],"tags":["llama-index","install","integration","openai","import-error"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}