microsoft/semantic-kernel · error · ServiceInitializationError

AI model path is not provided. Please provide the 'ai_model_

Error message

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.

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py:74

            template : The chat template configuration.
            ai_model_path : Local path to the ONNX model Folder.
            ai_model_id : The ID of the AI model. Defaults to None.
            env_file_path : Use the environment settings file as a fallback
                to environment variables.
            env_file_encoding : The encoding of the environment settings file.
            kwargs : Additional arguments.
        """
        try:
            settings = OnnxGenAISettings(
                chat_model_folder=ai_model_path,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as e:
            raise ServiceInitializationError(f"Error creating OnnxGenAISettings: {e}") from e

        if settings.chat_model_folder is None:
            raise ServiceInitializationError(
                "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."
            )

        if ai_model_id is None:
            ai_model_id = settings.chat_model_folder

        super().__init__(ai_model_id=ai_model_id, ai_model_path=settings.chat_model_folder, template=template, **kwargs)

        if self.enable_multi_modality and template is None:
            raise ServiceInitializationError(
                "When using a multi-modal model, a template must be specified."
                " Please provide a ONNXTemplate in the constructor."
            )

    @override
    async def _inner_get_chat_message_contents(
        self,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass ai_model_path explicitly: OnnxGenAIChatCompletion(ai_model_path='/path/to/model_folder')
  2. Set the env var: export ONNX_GEN_AI_CHAT_MODEL_FOLDER=/path/to/model_folder
  3. Ensure the path points to a folder containing genai_config.json and model files

Example fix

// before
chat = OnnxGenAIChatCompletion()
// after
chat = OnnxGenAIChatCompletion(ai_model_path='/models/phi-3-mini-4k-instruct-onnx/cpu_and_mobile/cpu-int4-rationale')
Defensive patterns

Strategy: validation

Validate before calling

import os

model_path = '/path/to/onnx/model_folder'
if not model_path and not os.environ.get('ONNX_GEN_AI_CHAT_MODEL_FOLDER'):
    raise RuntimeError('ai_model_path not provided and ONNX_GEN_AI_CHAT_MODEL_FOLDER not set')

if not os.path.isdir(model_path):
    raise RuntimeError(f'Model path does not exist: {model_path}')

chat = OnnxGenAIChatCompletion(ai_model_path=model_path)

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError

try:
    chat = OnnxGenAIChatCompletion()
except ServiceInitializationError as e:
    if 'AI model path is not provided' in str(e):
        chat = OnnxGenAIChatCompletion(ai_model_path=os.environ['ONNX_CHAT_MODEL_PATH'])
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/7dd7c80d9c604584. Report an issue: GitHub.