{"record":{"id":"7d0a4d24e15f6bbd","repo":"run-llama/llama_index","slug":"could-not-load-openai-embedding-model-if","errorCode":null,"errorMessage":"\n******\nCould not load OpenAI embedding model. If you intended to use OpenAI, please check your OPENAI_API_KEY.\nOriginal error:\n{e!s}\nConsider using embed_model='local'.\nVisit our documentation for more embedding options: https://developers.llamaindex.ai/python/framework/module_guides/models/embeddings/\n******","messagePattern":"\n\\*\\*\\*\\*\\*\\*\nCould not load OpenAI embedding model\\. If you intended to use OpenAI, please check your OPENAI_API_KEY\\.\nOriginal error:\n(.+?)\nConsider using embed_model='local'\\.\nVisit our documentation for more embedding options: https://developers\\.llamaindex\\.ai/python/framework/module_guides/models/embeddings/\n\\*\\*\\*\\*\\*\\*","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"llama-index-core/llama_index/core/embeddings/utils.py","lineNumber":65,"sourceCode":"\n        try:\n            from llama_index.embeddings.openai import (\n                OpenAIEmbedding,\n            )  # pants: no-infer-dep\n\n            from llama_index.embeddings.openai.utils import (\n                validate_openai_api_key,\n            )  # pants: no-infer-dep\n\n            embed_model = OpenAIEmbedding()\n            validate_openai_api_key(embed_model.api_key)  # type: ignore\n        except ImportError:\n            raise ImportError(\n                \"`llama-index-embeddings-openai` package not found, \"\n                \"please run `pip install llama-index-embeddings-openai`\"\n            )\n        except ValueError as e:\n            raise ValueError(\n                \"\\n******\\n\"\n                \"Could not load OpenAI embedding model. \"\n                \"If you intended to use OpenAI, please check your OPENAI_API_KEY.\\n\"\n                \"Original error:\\n\"\n                f\"{e!s}\"\n                \"\\nConsider using embed_model='local'.\\n\"\n                \"Visit our documentation for more embedding options: \"\n                \"https://developers.llamaindex.ai/python/framework/module_guides/\"\n                \"models/embeddings/\"\n                \"\\n******\"\n            )\n    # for image multi-modal embeddings\n    elif isinstance(embed_model, str) and embed_model.startswith(\"clip\"):\n        try:\n            from llama_index.embeddings.clip import ClipEmbedding  # pants: no-infer-dep\n\n            clip_model_name = (\n                embed_model.split(\":\")[1] if \":\" in embed_model else \"ViT-B/32\"","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/embeddings/utils.py#L47-L83","documentation":"While building the default OpenAI embedding, validate_openai_api_key() raised a ValueError (typically 'No API key found' or 'Incorrect API key provided') which resolve_embed_model() re-raises with remediation text. The OpenAI integration IS installed; the OPENAI_API_KEY is missing, empty, or rejected by the API.","triggerScenarios":"Constructing an index without embed_model while OPENAI_API_KEY is unset, set to an invalid/revoked key, or uses wrong env var name; key loaded too late (dotenv imported after llama-index call); a placeholder key like 'sk-...' in a template .env.","commonSituations":"Forgetting export OPENAI_API_KEY in shell/CI/Docker; rotated or revoked keys; copy-pasting example code without setting the env var; .env not loaded before Settings resolution.","solutions":["Set a valid key: export OPENAI_API_KEY=sk-... and verify with a direct OpenAI call","If you never intended OpenAI, pass embed_model='local:<model>' (HuggingFace) or any BaseEmbedding instance explicitly","Load .env before llama-index imports/usage (from dotenv import load_dotenv; load_dotenv())"],"exampleFix":"// before\nindex = VectorStoreIndex.from_documents(docs)  # no OPENAI_API_KEY set\n\n// after\nexport OPENAI_API_KEY=sk-...\nindex = VectorStoreIndex.from_documents(docs)\n# or fully local:\nindex = VectorStoreIndex.from_documents(\n    docs, embed_model=\"local:BAAI/bge-small-en-v1.5\"\n)","handlingStrategy":"validation","validationCode":"import os\nif embed_model in (None, \"default\") and not os.environ.get(\"OPENAI_API_KEY\"):\n    raise RuntimeError(\"OPENAI_API_KEY not set; set it or pass embed_model='local:...'\")","typeGuard":null,"tryCatchPattern":"try:\n    index = VectorStoreIndex.from_documents(docs)\nexcept ValueError as e:\n    if \"OPENAI_API_KEY\" in str(e):\n        raise RuntimeError(\"missing/invalid OpenAI key; export OPENAI_API_KEY or use local embeddings\") from e\n    raise","preventionTips":["Call load_dotenv() before any llama-index Settings/index usage","Smoke-test the key at startup with a one-token embeddings request","Default to 'local:' embeddings in offline deployments so no key is needed"],"tags":["embeddings","openai","api-key","authentication","environment"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}