microsoft/semantic-kernel · error · NotImplementedError

Model type {self.ai_model_type} is not supported

Error message

Model type {self.ai_model_type} is not supported

What it means

Raised in OpenAIHandler._send_request as a NotImplementedError when self.ai_model_type does not match any of the known OpenAIModelTypes branches (CHAT, TEXT, EMBEDDING, TEXT_TO_IMAGE, AUDIO_TO_TEXT, TEXT_TO_AUDIO). This is a defensive guard indicating an unhandled or newly introduced model type.

Source

Thrown at python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py:74

    async def _send_request(self, settings: PromptExecutionSettings) -> RESPONSE_TYPE:
        """Send a request to the OpenAI API."""
        if self.ai_model_type == OpenAIModelTypes.TEXT or self.ai_model_type == OpenAIModelTypes.CHAT:
            assert isinstance(settings, OpenAIPromptExecutionSettings)  # nosec
            return await self._send_completion_request(settings)
        if self.ai_model_type == OpenAIModelTypes.EMBEDDING:
            assert isinstance(settings, OpenAIEmbeddingPromptExecutionSettings)  # nosec
            return await self._send_embedding_request(settings)
        if self.ai_model_type == OpenAIModelTypes.TEXT_TO_IMAGE:
            assert isinstance(settings, OpenAITextToImageExecutionSettings)  # nosec
            return await self._send_text_to_image_request(settings)
        if self.ai_model_type == OpenAIModelTypes.AUDIO_TO_TEXT:
            assert isinstance(settings, OpenAIAudioToTextExecutionSettings)  # nosec
            return await self._send_audio_to_text_request(settings)
        if self.ai_model_type == OpenAIModelTypes.TEXT_TO_AUDIO:
            assert isinstance(settings, OpenAITextToAudioExecutionSettings)  # nosec
            return await self._send_text_to_audio_request(settings)

        raise NotImplementedError(f"Model type {self.ai_model_type} is not supported")

    async def _send_completion_request(
        self,
        settings: OpenAIPromptExecutionSettings,
    ) -> ChatCompletion | Completion | AsyncStream[ChatCompletionChunk] | AsyncStream[Completion]:
        """Execute the appropriate call to OpenAI models."""
        try:
            settings_dict = settings.prepare_settings_dict()
            if self.ai_model_type == OpenAIModelTypes.CHAT:
                assert isinstance(settings, OpenAIChatPromptExecutionSettings)  # nosec
                self._handle_structured_output(settings, settings_dict)
                if settings.tools is None:
                    settings_dict.pop("parallel_tool_calls", None)
                response = await self.client.chat.completions.create(**settings_dict)
            else:
                response = await self.client.completions.create(**settings_dict)

            self.store_usage(response)

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Use a supported OpenAIModelTypes value: CHAT, TEXT, EMBEDDING, TEXT_TO_IMAGE, AUDIO_TO_TEXT, or TEXT_TO_AUDIO
  2. If you subclassed OpenAIHandler, override _send_request to handle your custom model type
  3. Check the Semantic Kernel changelog for newly added model types and upgrade if needed

Example fix

# before — custom subclass with unsupported type
class MyHandler(OpenAIHandler):
    ai_model_type = MyCustomModelTypes.SOMETHING_NEW
# after — override the dispatcher
class MyHandler(OpenAIHandler):
    async def _send_request(self, settings):
        if self.ai_model_type == MyCustomModelTypes.SOMETHING_NEW:
            return await self._send_custom_request(settings)
        return await super()._send_request(settings)
Defensive patterns

Strategy: try-catch

Validate before calling

from semantic_kernel.connectors.ai.open_ai.services.open_ai_model_types import OpenAIModelTypes

SUPPORTED = {OpenAIModelTypes.CHAT, OpenAIModelTypes.TEXT, OpenAIModelTypes.EMBEDDING,
             OpenAIModelTypes.TEXT_TO_IMAGE, OpenAIModelTypes.AUDIO_TO_TEXT,
             OpenAIModelTypes.TEXT_TO_AUDIO}
if service.ai_model_type not in SUPPORTED:
    raise ValueError(f'Unsupported model type: {service.ai_model_type}')

Type guard

from semantic_kernel.connectors.ai.open_ai.services.open_ai_model_types import OpenAIModelTypes

def is_supported_model_type(model_type) -> bool:
    return model_type in {
        OpenAIModelTypes.CHAT, OpenAIModelTypes.TEXT, OpenAIModelTypes.EMBEDDING,
        OpenAIModelTypes.TEXT_TO_IMAGE, OpenAIModelTypes.AUDIO_TO_TEXT,
        OpenAIModelTypes.TEXT_TO_AUDIO,
    }

Try / catch

try:
    response = await service._send_request(settings)
except NotImplementedError:
    logger.error(f'Model type {service.ai_model_type} not supported by this handler')
    raise

Prevention

When it happens

Trigger: Constructing a service with an ai_model_type that is not covered by the request dispatcher — typically from subclassing OpenAIHandler with a custom OpenAIModelTypes enum member, or from a future model-type value that this version of Semantic Kernel does not yet support.

Common situations: Subclassing OpenAIHandler to add a custom endpoint type without overriding _send_request; using an internal or experimental model type that was added to the enum but not yet handled in the dispatcher; version mismatch where the enum has more members than the handler knows about.

Related errors


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