{"record":{"id":"a22ee5c9e3fed2a8","repo":"microsoft/semantic-kernel","slug":"the-openai-embedding-model-id-is-required","errorCode":null,"errorMessage":"The OpenAI embedding model ID is required.","messagePattern":"The OpenAI embedding model ID is required\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_embedding.py","lineNumber":65,"sourceCode":"            default_headers (Mapping[str,str] | None): The default headers mapping of string keys to\n                string values for HTTP requests. (Optional)\n            async_client (Optional[AsyncOpenAI]): An existing client to use. (Optional)\n            env_file_path (str | None): Use the environment settings file as\n                a fallback to environment variables. (Optional)\n            env_file_encoding (str | None): The encoding of the environment settings file. (Optional)\n        \"\"\"\n        try:\n            openai_settings = OpenAISettings(\n                api_key=api_key,\n                org_id=org_id,\n                embedding_model_id=ai_model_id,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create OpenAI settings.\", ex) from ex\n        if not openai_settings.embedding_model_id:\n            raise ServiceInitializationError(\"The OpenAI embedding model ID is required.\")\n        super().__init__(\n            ai_model_id=openai_settings.embedding_model_id,\n            api_key=openai_settings.api_key.get_secret_value() if openai_settings.api_key else None,\n            ai_model_type=OpenAIModelTypes.EMBEDDING,\n            org_id=openai_settings.org_id,\n            service_id=service_id,\n            default_headers=default_headers,\n            client=async_client,\n        )\n\n    @classmethod\n    def from_dict(cls: type[T_], settings: dict[str, Any]) -> T_:\n        \"\"\"Initialize an Open AI service from a dictionary of settings.\n\n        Args:\n            settings: A dictionary of settings for the service.\n        \"\"\"\n        return cls(","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_embedding.py#L47-L83","documentation":"Raised while constructing an OpenAITextEmbedding service. After OpenAISettings is built (merging the ai_model_id argument with OPENAI_* env vars), if openai_settings.embedding_model_id is still falsy the service cannot generate embeddings and throws ServiceInitializationError. This is a missing-config guard, separate from the settings ValidationError wrapper.","triggerScenarios":"Calling OpenAITextEmbedding() with no ai_model_id argument AND no OPENAI_EMBEDDING_MODEL_ID environment variable. The constructor only falls through to this error when both sources are empty.","commonSituations":"OPENAI_EMBEDDING_MODEL_ID is unset in production/CI; the .env file is not loaded because env_file_path is wrong or missing; the developer set OPENAI_CHAT_MODEL_ID but not the embedding variable; switching from ada-002 to text-embedding-3-small and forgetting to update the env var name.","solutions":["Pass ai_model_id explicitly: OpenAITextEmbedding(ai_model_id='text-embedding-3-small', api_key='sk-...')","Set the environment variable: export OPENAI_EMBEDDING_MODEL_ID=text-embedding-3-small","Add OPENAI_EMBEDDING_MODEL_ID to your .env and pass env_file_path to the constructor","Confirm the variable name exactly matches OPENAI_EMBEDDING_MODEL_ID (note: embedding, not embed)"],"exampleFix":"# before\nservice = OpenAITextEmbedding(api_key=\"sk-...\")\n# raises ServiceInitializationError: The OpenAI embedding model ID is required.\n\n# after\nservice = OpenAITextEmbedding(ai_model_id=\"text-embedding-3-small\", api_key=\"sk-...\")","handlingStrategy":"validation","validationCode":"import os\nfrom semantic_kernel.connectors.ai.open_ai.settings.open_ai_settings import OpenAISettings\n\ns = OpenAISettings()\nif not s.embedding_model_id:\n    raise ValueError(\"OPENAI_EMBEDDING_MODEL_ID is required before building OpenAITextEmbedding\")","typeGuard":"import os\n\n\ndef has_embedding_model(ai_model_id: str | None) -> bool:\n    return bool(ai_model_id or os.getenv(\"OPENAI_EMBEDDING_MODEL_ID\"))","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    service = OpenAITextEmbedding()\nexcept ServiceInitializationError as e:\n    if \"embedding model ID is required\" in str(e):\n        raise SystemExit(\"Set OPENAI_EMBEDDING_MODEL_ID or pass ai_model_id\") from e\n    raise","preventionTips":["Set OPENAI_EMBEDDING_MODEL_ID in your .env and load it at startup","Pass ai_model_id explicitly for clarity","Distinguish the embedding var name from chat/text vars"],"tags":["openai","configuration","initialization","embeddings","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}