microsoft/semantic-kernel · error · ServiceInitializationError

The Azure OpenAI text to image deployment name is required.

Error message

The Azure OpenAI text to image deployment name is required.

What it means

Raised by AzureTextToImage.__init__ after settings creation succeeds but text_to_image_deployment_name is empty or None. This field comes from the deployment_name constructor argument or the AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME environment variable. The image generation service needs a specific deployment to target the correct model (e.g. DALL-E).

Source

Thrown at python/semantic_kernel/connectors/ai/open_ai/services/azure_text_to_image.py:79

                environment variables. (Optional)
            env_file_encoding: The encoding of the environment settings file. (Optional)
            credential: The credential to use for authentication. (Optional)
        """
        try:
            azure_openai_settings = AzureOpenAISettings(
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
                api_key=api_key,
                text_to_image_deployment_name=deployment_name,
                endpoint=endpoint,
                base_url=base_url,
                api_version=api_version,
                token_endpoint=token_endpoint,
            )
        except ValidationError as exc:
            raise ServiceInitializationError(f"Invalid settings: {exc}") from exc
        if not azure_openai_settings.text_to_image_deployment_name:
            raise ServiceInitializationError("The Azure OpenAI text to image deployment name is required.")

        super().__init__(
            deployment_name=azure_openai_settings.text_to_image_deployment_name,
            endpoint=azure_openai_settings.endpoint,
            base_url=azure_openai_settings.base_url,
            api_version=azure_openai_settings.api_version,
            service_id=service_id,
            api_key=azure_openai_settings.api_key.get_secret_value() if azure_openai_settings.api_key else None,
            ad_token=ad_token,
            ad_token_provider=ad_token_provider,
            token_endpoint=azure_openai_settings.token_endpoint,
            default_headers=default_headers,
            ai_model_type=OpenAIModelTypes.TEXT_TO_IMAGE,
            client=async_client,
            credential=credential,
        )

    @classmethod

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass deployment_name= explicitly: AzureTextToImage(deployment_name='dall-e-3', ...).
  2. Set AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME in your environment or .env file.
  3. Verify the deployment exists in Azure Portal under Resource Management > Deployments and the name matches exactly.

Example fix

# before
service = AzureTextToImage(
    endpoint='https://myresource.openai.azure.com',
    api_key='...',
)
# after
service = AzureTextToImage(
    deployment_name='dall-e-3',
    endpoint='https://myresource.openai.azure.com',
    api_key='...',
)
Defensive patterns

Strategy: validation

Validate before calling

import os

deployment_name = os.environ.get('AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME')
if not deployment_name:
    raise ValueError(
        'AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME is not set. '
        'Set it in your environment or .env file, or pass deployment_name= to the constructor.'
    )

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError

try:
    service = AzureTextToImage(
        deployment_name=os.environ.get('AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME'),
        endpoint='https://myresource.openai.azure.com',
        api_key='...',
    )
except ServiceInitializationError as e:
    if 'text to image deployment name is required' in str(e):
        print('Set AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME or pass deployment_name=')
    raise

Prevention

When it happens

Trigger: Constructing AzureTextToImage without deployment_name= and without AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME in the environment or .env file. Endpoint and auth resolved, but the deployment identifier is missing.

Common situations: Using a chat deployment variable instead of the image-specific one; DALL-E deployment created in Azure Portal but env var not configured; .env file missing the text_to_image line; fresh deployment environment.

Related errors


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