microsoft/semantic-kernel · error · ServiceInitializationError

Invalid settings: {exc}

Error message

Invalid settings: {exc}

What it means

Raised by AzureTextToImage.__init__ when AzureOpenAISettings construction throws a pydantic ValidationError. The settings model validates endpoint (HttpsUrl), base_url (Url), api_key (SecretStr), api_version (str). Any field value that fails type coercion produces this wrapped error.

Source

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

            async_client: An existing client to use. (Optional)
            env_file_path: Use the environment settings file as a fallback to
                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,
        )

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect the chained ValidationError for the specific failing field and constraint.
  2. Ensure endpoint is a valid https:// URL ending in openai.azure.com.
  3. Verify .env file syntax and environment variable formatting.
  4. Pass api_version as a string.

Example fix

# before
service = AzureTextToImage(
    deployment_name='dall-e-3',
    endpoint='http://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: try-catch

Validate before calling

from urllib.parse import urlparse

def validate_azure_endpoint(endpoint: str | None) -> str:
    if endpoint is None:
        raise ValueError('endpoint is required')
    parsed = urlparse(endpoint)
    if parsed.scheme != 'https':
        raise ValueError(f'endpoint must use https:// scheme, got {parsed.scheme}://')
    return endpoint

validate_azure_endpoint(os.environ.get('AZURE_OPENAI_ENDPOINT'))

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError

try:
    service = AzureTextToImage(
        deployment_name='dall-e-3',
        endpoint='https://myresource.openai.azure.com',
        api_key='...',
    )
except ServiceInitializationError as e:
    cause = e.__cause__
    if cause:
        print(f'Settings validation failed: {cause}')
    raise

Prevention

When it happens

Trigger: Constructing AzureTextToImage with a non-HTTPS endpoint, a malformed base_url, or an invalid AZURE_OPENAI_ENDPOINT environment variable. Passing api_version as a non-string type also triggers it.

Common situations: Passing endpoint='http://...' (HttpsUrl rejects http); bare hostname without scheme; .env file with corrupted endpoint value; CI environment with an improperly set secret.

Related errors


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