microsoft/semantic-kernel · error · ServiceInitializationError
The OpenAI text to audio model ID is required.
Error message
The OpenAI text to audio model ID is required.
What it means
Raised while constructing an OpenAITextToAudio service. After OpenAISettings resolves (argument + OPENAI_* env vars), if openai_settings.text_to_audio_model_id is still falsy the service cannot synthesize audio and throws ServiceInitializationError. This is the missing-model guard, distinct from the ValidationError wrapper.
Source
Thrown at python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_audio.py:60
default_headers: The default headers mapping of string keys to
string values for HTTP requests. (Optional)
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)
"""
try:
openai_settings = OpenAISettings(
api_key=api_key,
org_id=org_id,
text_to_audio_model_id=ai_model_id,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as ex:
raise ServiceInitializationError("Failed to create OpenAI settings.", ex) from ex
if not openai_settings.text_to_audio_model_id:
raise ServiceInitializationError("The OpenAI text to audio model ID is required.")
super().__init__(
ai_model_id=openai_settings.text_to_audio_model_id,
api_key=openai_settings.api_key.get_secret_value() if openai_settings.api_key else None,
ai_model_type=OpenAIModelTypes.TEXT_TO_AUDIO,
org_id=openai_settings.org_id,
service_id=service_id,
default_headers=default_headers,
client=async_client,
)
@classmethod
def from_dict(cls: type[T_], settings: dict[str, Any]) -> T_:
"""Initialize an Open AI service from a dictionary of settings.
Args:
settings: A dictionary of settings for the service.
"""
return cls(View on GitHub (pinned to c028a0c7dc)
Solutions
- Pass ai_model_id explicitly: OpenAITextToAudio(ai_model_id='tts-1', api_key='sk-...')
- Set the environment variable: export OPENAI_TEXT_TO_AUDIO_MODEL_ID=tts-1
- Add OPENAI_TEXT_TO_AUDIO_MODEL_ID to your .env and pass env_file_path
- Verify the exact variable name OPENAI_TEXT_TO_AUDIO_MODEL_ID
Example fix
# before service = OpenAITextToAudio(api_key="sk-...") # raises ServiceInitializationError: The OpenAI text to audio model ID is required. # after service = OpenAITextToAudio(ai_model_id="tts-1", api_key="sk-...")
Defensive patterns
Strategy: validation
Validate before calling
import os
from semantic_kernel.connectors.ai.open_ai.settings.open_ai_settings import OpenAISettings
s = OpenAISettings()
if not s.text_to_audio_model_id:
raise ValueError("OPENAI_TEXT_TO_AUDIO_MODEL_ID is required before building OpenAITextToAudio") Type guard
import os
def has_tts_model(ai_model_id: str | None) -> bool:
return bool(ai_model_id or os.getenv("OPENAI_TEXT_TO_AUDIO_MODEL_ID")) Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError
try:
service = OpenAITextToAudio()
except ServiceInitializationError as e:
if "text to audio model ID is required" in str(e):
raise SystemExit("Set OPENAI_TEXT_TO_AUDIO_MODEL_ID or pass ai_model_id") from e
raise Prevention
- Set OPENAI_TEXT_TO_AUDIO_MODEL_ID in your environment
- Pass ai_model_id explicitly in code
- Confirm the exact variable name
When it happens
Trigger: Calling OpenAITextToAudio() with no ai_model_id argument AND no OPENAI_TEXT_TO_AUDIO_MODEL_ID environment variable set.
Common situations: The text-to-audio env var was never added to the deployment config; .env file path is incorrect so the variable is never read; the developer assumed the chat model id covers TTS, which it does not.
Related errors
- The OpenAI text model ID is required.
- The OpenAI embedding model ID is required.
- The OpenAI text to image model ID is required.
- Failed to create OpenAI settings.
- Failed to create OpenAI settings.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/c97e2c9fadc0e477.
Report an issue: GitHub.