{"record":{"id":"7dd7c80d9c604584","repo":"microsoft/semantic-kernel","slug":"ai-model-path-is-not-provided-please-provide-the","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_CHAT_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_CHAT_MODEL_FOLDER' environment variable\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py","lineNumber":74,"sourceCode":"            template : The chat template configuration.\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            kwargs : Additional arguments.\n        \"\"\"\n        try:\n            settings = OnnxGenAISettings(\n                chat_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\"Error creating OnnxGenAISettings: {e}\") from e\n\n        if settings.chat_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_CHAT_MODEL_FOLDER' environment variable.\"\n            )\n\n        if ai_model_id is None:\n            ai_model_id = settings.chat_model_folder\n\n        super().__init__(ai_model_id=ai_model_id, ai_model_path=settings.chat_model_folder, template=template, **kwargs)\n\n        if self.enable_multi_modality and template is None:\n            raise ServiceInitializationError(\n                \"When using a multi-modal model, a template must be specified.\"\n                \" Please provide a ONNXTemplate in the constructor.\"\n            )\n\n    @override\n    async def _inner_get_chat_message_contents(\n        self,","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py#L56-L92","documentation":"Raised by the OnnxGenAIChatCompletion constructor when settings.chat_model_folder resolves to None — meaning neither the ai_model_path constructor argument nor the ONNX_GEN_AI_CHAT_MODEL_FOLDER environment variable was provided. The service needs a local filesystem path to the ONNX model folder to load the model. Raised as ServiceInitializationError.","triggerScenarios":"Constructing OnnxGenAIChatCompletion() without ai_model_path while ONNX_GEN_AI_CHAT_MODEL_FOLDER is not set. Also when env_file_path does not contain the key.","commonSituations":"First-time setup without model downloaded; env var unset in the deployment environment; model path provided as a positional arg in the wrong slot; forgetting to download the ONNX model before constructing the service.","solutions":["Pass ai_model_path explicitly: OnnxGenAIChatCompletion(ai_model_path='/path/to/model_folder')","Set the env var: export ONNX_GEN_AI_CHAT_MODEL_FOLDER=/path/to/model_folder","Ensure the path points to a folder containing genai_config.json and model files"],"exampleFix":"// before\nchat = OnnxGenAIChatCompletion()\n// after\nchat = OnnxGenAIChatCompletion(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_CHAT_MODEL_FOLDER'):\n    raise RuntimeError('ai_model_path not provided and ONNX_GEN_AI_CHAT_MODEL_FOLDER not set')\n\nif not os.path.isdir(model_path):\n    raise RuntimeError(f'Model path does not exist: {model_path}')\n\nchat = OnnxGenAIChatCompletion(ai_model_path=model_path)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    chat = OnnxGenAIChatCompletion()\nexcept ServiceInitializationError as e:\n    if 'AI model path is not provided' in str(e):\n        chat = OnnxGenAIChatCompletion(ai_model_path=os.environ['ONNX_CHAT_MODEL_PATH'])\n    else:\n        raise","preventionTips":["Set ONNX_GEN_AI_CHAT_MODEL_FOLDER in your environment or .env","Verify the model folder exists and contains genai_config.json before constructing","Use a startup config validator that checks all required paths exist"],"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"}