{"record":{"id":"8c7b5f7ce7e64001","repo":"microsoft/semantic-kernel","slug":"onnxruntime-genai-is-not-installed","errorCode":null,"errorMessage":"onnxruntime-genai is not installed.","messagePattern":"onnxruntime-genai is not installed\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_completion_base.py","lineNumber":40,"sourceCode":"    \"\"\"Base class for OnnxGenAI Completion services.\"\"\"\n\n    model: Any\n    tokenizer: Any\n    tokenizer_stream: Any\n    enable_multi_modality: bool = False\n\n    def __init__(self, ai_model_path: str, **kwargs) -> None:\n        \"\"\"Creates a new instance of the OnnxGenAICompletionBase class, loads model & tokenizer.\n\n        Args:\n            ai_model_path : Path to Onnx Model.\n            **kwargs: Additional keyword arguments.\n\n        Raises:\n            ServiceInitializationError: When model cannot be loaded\n        \"\"\"\n        if not ready:\n            raise ImportError(\"onnxruntime-genai is not installed.\")\n        try:\n            json_gen_ai_config = os.path.join(ai_model_path + \"/genai_config.json\")\n            with open(json_gen_ai_config) as file:\n                config: dict = json.load(file)\n                enable_multi_modality = \"vision\" in config.get(\"model\", {})\n                model = OnnxRuntimeGenAi.Model(ai_model_path)\n                if enable_multi_modality:\n                    tokenizer = model.create_multimodal_processor()\n                else:\n                    tokenizer = OnnxRuntimeGenAi.Tokenizer(model)\n                tokenizer_stream = tokenizer.create_stream()\n        except Exception as ex:\n            raise ServiceInitializationError(\"Failed to initialize OnnxCompletion service\", ex) from ex\n\n        super().__init__(\n            model=model,\n            tokenizer=tokenizer,\n            tokenizer_stream=tokenizer_stream,","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_completion_base.py#L22-L58","documentation":"Raised as a plain ImportError (not a ServiceInitializationError) by the OnnxGenAICompletionBase constructor when the optional onnxruntime-genai package could not be imported at module load time. The module-level try/except sets ready=False on import failure, and __init__ checks this flag before proceeding. No model loading is attempted.","triggerScenarios":"Constructing OnnxGenAIChatCompletion or OnnxGenAITextCompletion in an environment where onnxruntime-genai is not installed. The __init__ method checks the module-level 'ready' flag and raises ImportError immediately.","commonSituations":"Installing semantic_kernel without the onnx extra (pip install semantic_kernel instead of pip install semantic_kernel[onnx]); fresh virtualenv; onnxruntime-genai not yet released for the platform/architecture (e.g. some ARM builds); package uninstalled during dependency cleanup.","solutions":["Install the ONNX runtime genai package: pip install onnxruntime-genai","Install semantic_kernel with the onnx extra: pip install semantic_kernel[onnx]","Verify the install: python -c 'import onnxruntime_genai'"],"exampleFix":"// before (missing dependency)\nchat = OnnxGenAIChatCompletion(ai_model_path='/models/phi3')\n// after\n// pip install onnxruntime-genai\nchat = OnnxGenAIChatCompletion(ai_model_path='/models/phi3')","handlingStrategy":"validation","validationCode":"try:\n    import onnxruntime_genai  # noqa: F401\n    ready = True\nexcept ImportError:\n    ready = False\n\nif not ready:\n    raise RuntimeError('onnxruntime-genai is not installed. Run: pip install onnxruntime-genai')\n\nchat = OnnxGenAIChatCompletion(ai_model_path='/models/phi3')","typeGuard":null,"tryCatchPattern":"try:\n    chat = OnnxGenAIChatCompletion(ai_model_path=model_path)\nexcept ImportError as e:\n    if 'onnxruntime-genai' in str(e):\n        logger.error('Install the dependency: pip install onnxruntime-genai')\n    raise","preventionTips":["Add onnxruntime-genai to your requirements.txt or pyproject.toml","Install semantic_kernel with the onnx extra: pip install semantic_kernel[onnx]","Run a startup import check before constructing ONNX services"],"tags":["onnx","dependency","import-error","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}