microsoft/semantic-kernel · error · ServiceInitializationError
Invalid settings: {exc}
Error message
Invalid settings: {exc} What it means
Raised by AzureTextToAudio.__init__ when AzureOpenAISettings construction throws a pydantic ValidationError. The settings model validates endpoint (HttpsUrl), base_url (Url), api_key (SecretStr), api_version (str). The text-to-audio service defaults api_version to '2024-10-01-preview'. Any field failing type coercion produces this wrapped error.
Source
Thrown at python/semantic_kernel/connectors/ai/open_ai/services/azure_text_to_audio.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_audio_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_audio_deployment_name:
raise ServiceInitializationError("The Azure OpenAI text to audio deployment name is required.")
super().__init__(
deployment_name=azure_openai_settings.text_to_audio_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_AUDIO,
client=async_client,
credential=credential,
)View on GitHub (pinned to c028a0c7dc)
Solutions
- Read the chained ValidationError for the specific field and constraint that failed.
- Ensure endpoint is a full https:// URL (e.g. 'https://myresource.openai.azure.com').
- Verify .env file syntax and that environment variables are correctly formatted.
- Pass api_version as a string (default is '2024-10-01-preview').
Example fix
# before
service = AzureTextToAudio(
deployment_name='tts',
endpoint='myresource.openai.azure.com',
api_key='...',
)
# after
service = AzureTextToAudio(
deployment_name='tts',
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 = AzureTextToAudio(
deployment_name='tts',
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
- Always use https:// for Azure OpenAI endpoints.
- Validate endpoint URL format before constructing the service.
- Read the chained ValidationError (__cause__) for the specific field that failed.
- Pass api_version as a string (default is '2024-10-01-preview').
When it happens
Trigger: Constructing AzureTextToAudio with a non-HTTPS endpoint, malformed base_url, or invalid AZURE_OPENAI_ENDPOINT environment variable value. Passing api_version as a non-string type (e.g. a float or date object) also triggers it.
Common situations: Passing 'http://...' for endpoint; bare hostname without scheme; .env file with broken endpoint value; env_file_path pointing to a file with invalid dotenv syntax; passing api_version as a non-string.
Related errors
- Failed to create OpenAI settings.
- Invalid settings: {ex}
- Invalid settings: {exc}
- Invalid settings: {exc}
- Failed to create Azure OpenAI settings: {exc}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/3386f2d56c1e98a4.
Report an issue: GitHub.