{"record":{"id":"2a36491d5ed4565f","repo":"microsoft/semantic-kernel","slug":"ai-model-path-is-not-provided-please-provide-the-2a3649","errorCode":null,"errorMessage":"AI model path is not provided. Please provide the 'ai_model_path' parameter in the constructor. OR set the 'ONNX_GEN_AI_TEXT_MODEL_FOLDER' environment variable.","messagePattern":"AI model path is not provided\\. Please provide the 'ai_model_path' parameter in the constructor\\. OR set the 'ONNX_GEN_AI_TEXT_MODEL_FOLDER' environment variable\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_text_completion.py","lineNumber":58,"sourceCode":"\n        Args:\n            ai_model_path : Local path to the ONNX model Folder.\n            ai_model_id : The ID of the AI model. Defaults to None.\n            env_file_path : Use the environment settings file as a fallback\n                to environment variables.\n            env_file_encoding : The encoding of the environment settings file.\n        \"\"\"\n        try:\n            settings = OnnxGenAISettings(\n                text_model_folder=ai_model_path,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as e:\n            raise ServiceInitializationError(f\"Invalid settings for OnnxGenAITextCompletion: {e}\")\n\n        if settings.text_model_folder is None:\n            raise ServiceInitializationError(\n                \"AI model path is not provided. Please provide the 'ai_model_path' parameter in the constructor. \"\n                \"OR set the 'ONNX_GEN_AI_TEXT_MODEL_FOLDER' environment variable.\"\n            )\n\n        if ai_model_id is None:\n            ai_model_id = settings.text_model_folder\n\n        super().__init__(\n            ai_model_id=ai_model_id,\n            ai_model_path=settings.text_model_folder,\n        )\n\n    @override\n    async def _inner_get_text_contents(\n        self,\n        prompt: str,\n        settings: PromptExecutionSettings,\n    ) -> list[TextContent]:","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_text_completion.py#L40-L76","documentation":"Raised by the OnnxGenAITextCompletion constructor when settings.text_model_folder resolves to None — meaning neither the ai_model_path constructor argument nor the ONNX_GEN_AI_TEXT_MODEL_FOLDER environment variable was provided. The service needs a local path to the ONNX model folder. Raised as ServiceInitializationError.","triggerScenarios":"Constructing OnnxGenAITextCompletion() without ai_model_path while ONNX_GEN_AI_TEXT_MODEL_FOLDER is not set in the environment or .env file.","commonSituations":"First-time setup without a model downloaded; env var unset in deployment; confusing ONNX_GEN_AI_CHAT_MODEL_FOLDER (for chat) with ONNX_GEN_AI_TEXT_MODEL_FOLDER (for text); model not yet downloaded.","solutions":["Pass ai_model_path explicitly: OnnxGenAITextCompletion(ai_model_path='/path/to/model_folder')","Set the env var: export ONNX_GEN_AI_TEXT_MODEL_FOLDER=/path/to/model_folder","Ensure the path points to a folder containing genai_config.json and model files"],"exampleFix":"// before\ntext = OnnxGenAITextCompletion()\n// after\ntext = OnnxGenAITextCompletion(ai_model_path='/models/phi-3-mini-4k-instruct-onnx/cpu_and_mobile/cpu-int4-rationale')","handlingStrategy":"validation","validationCode":"import os\n\nmodel_path = '/path/to/onnx/model_folder'\nif not model_path and not os.environ.get('ONNX_GEN_AI_TEXT_MODEL_FOLDER'):\n    raise RuntimeError('ai_model_path not provided and ONNX_GEN_AI_TEXT_MODEL_FOLDER not set')\n\nif not os.path.isdir(model_path):\n    raise RuntimeError(f'Model path does not exist: {model_path}')\n\ntext = OnnxGenAITextCompletion(ai_model_path=model_path)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    text = OnnxGenAITextCompletion()\nexcept ServiceInitializationError as e:\n    if 'AI model path is not provided' in str(e):\n        text = OnnxGenAITextCompletion(ai_model_path=os.environ['ONNX_TEXT_MODEL_PATH'])\n    else:\n        raise","preventionTips":["Set ONNX_GEN_AI_TEXT_MODEL_FOLDER in your environment or .env","Do not confuse ONNX_GEN_AI_CHAT_MODEL_FOLDER with the text variant","Verify the model folder exists and contains genai_config.json before constructing"],"tags":["onnx","configuration","model-path","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}