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_TEXT_MODEL_FOLDER' environment variable.

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_text_completion.py:58

        Args:
            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.
        """
        try:
            settings = OnnxGenAISettings(
                text_model_folder=ai_model_path,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as e:
            raise ServiceInitializationError(f"Invalid settings for OnnxGenAITextCompletion: {e}")

        if settings.text_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_TEXT_MODEL_FOLDER' environment variable."
            )

        if ai_model_id is None:
            ai_model_id = settings.text_model_folder

        super().__init__(
            ai_model_id=ai_model_id,
            ai_model_path=settings.text_model_folder,
        )

    @override
    async def _inner_get_text_contents(
        self,
        prompt: str,
        settings: PromptExecutionSettings,
    ) -> list[TextContent]:

View on GitHub (pinned to c028a0c7dc)

Solutions

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

Example fix

// before
text = OnnxGenAITextCompletion()
// after
text = OnnxGenAITextCompletion(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_TEXT_MODEL_FOLDER'):
    raise RuntimeError('ai_model_path not provided and ONNX_GEN_AI_TEXT_MODEL_FOLDER not set')

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

text = OnnxGenAITextCompletion(ai_model_path=model_path)

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError

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

Prevention

When it happens

Trigger: Constructing OnnxGenAITextCompletion() without ai_model_path while ONNX_GEN_AI_TEXT_MODEL_FOLDER is not set in the environment or .env file.

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

Related errors


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