{"record":{"id":"874320fa77b43ec1","repo":"microsoft/semantic-kernel","slug":"failed-to-create-openai-settings-874320","errorCode":null,"errorMessage":"Failed to create OpenAI settings.","messagePattern":"Failed to create OpenAI settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/azure_realtime.py","lineNumber":124,"sourceCode":"                kernel (Kernel): the kernel to use for function calls\n                plugins (list[object] or dict[str, object]): the plugins to use for function calls\n                settings (OpenAIRealtimeExecutionSettings): the settings to use for the session\n                chat_history (ChatHistory): the chat history to use for the session\n                Otherwise they can also be passed to the context manager.\n        \"\"\"\n        try:\n            azure_openai_settings = AzureOpenAISettings(\n                api_key=api_key,\n                base_url=base_url,\n                endpoint=endpoint,\n                realtime_deployment_name=deployment_name,\n                api_version=api_version,\n                token_endpoint=token_endpoint,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create OpenAI settings.\", ex) from ex\n        if not azure_openai_settings.realtime_deployment_name:\n            raise ServiceInitializationError(\"The OpenAI realtime model ID is required.\")\n        super().__init__(\n            api_key=azure_openai_settings.api_key.get_secret_value() if azure_openai_settings.api_key else None,\n            audio_output_callback=audio_output_callback,\n            deployment_name=azure_openai_settings.realtime_deployment_name,\n            endpoint=azure_openai_settings.endpoint,\n            base_url=azure_openai_settings.base_url,\n            api_version=azure_openai_settings.api_version,\n            ad_token=ad_token,\n            ad_token_provider=ad_token_provider,\n            token_endpoint=azure_openai_settings.token_endpoint,\n            ai_model_type=OpenAIModelTypes.REALTIME,\n            service_id=service_id,\n            default_headers=default_headers,\n            client=async_client,\n            websocket_base_url=websocket_base_url,\n            credential=credential,","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/azure_realtime.py#L106-L142","documentation":"Raised by AzureRealtimeWebsocket.__init__ when AzureOpenAISettings construction throws a pydantic ValidationError. The settings class (a pydantic-settings BaseSettings subclass) validates fields like endpoint (must be HttpsUrl), base_url (must be Url), api_key (must be SecretStr), and api_version (must be str). If any field receives a value that fails type coercion, pydantic raises ValidationError which this code wraps as ServiceInitializationError.","triggerScenarios":"Constructing AzureRealtimeWebsocket with an endpoint value that is not a valid HTTPS URL (e.g. 'http://...' or a bare hostname), passing api_version as a non-string type, or having an AZURE_OPENAI_ENDPOINT environment variable containing a malformed URL. The env_file_path pointing to an unreadable file with invalid syntax can also trigger it.","commonSituations":"Passing endpoint='http://myresource.openai.azure.com' (http instead of https); passing a bare hostname without the scheme; .env file with unquoted special characters that corrupt the endpoint value; upgrading semantic_kernel and the endpoint field type changed from str to HttpsUrl.","solutions":["Inspect the chained ValidationError (passed as the second argument) — it lists each invalid field and the expected type.","Ensure endpoint uses the https:// scheme and a fully-qualified URL: 'https://myresource.openai.azure.com'.","If using a .env file, quote values containing special characters and verify the file is valid dotenv syntax.","Pass api_version as a plain string (e.g. '2024-10-01-preview'), not a date object or None where the field requires str."],"exampleFix":"# before\nservice = AzureRealtimeWebsocket(\n    deployment_name='gpt-4o-realtime',\n    endpoint='myresource.openai.azure.com',  # missing scheme\n    api_key='...',\n)\n# after\nservice = AzureRealtimeWebsocket(\n    deployment_name='gpt-4o-realtime',\n    endpoint='https://myresource.openai.azure.com',\n    api_key='...',\n)","handlingStrategy":"try-catch","validationCode":"from urllib.parse import urlparse\n\ndef validate_azure_endpoint(endpoint: str | None) -> str:\n    if endpoint is None:\n        raise ValueError('endpoint is required')\n    parsed = urlparse(endpoint)\n    if parsed.scheme != 'https':\n        raise ValueError(f'endpoint must use https:// scheme, got {parsed.scheme}://')\n    if not parsed.hostname or 'openai.azure.com' not in parsed.hostname:\n        raise ValueError(f'endpoint must be an Azure OpenAI resource URL, got {endpoint}')\n    return endpoint\n\n# Use before constructing AzureRealtimeWebsocket\nvalidate_azure_endpoint(os.environ.get('AZURE_OPENAI_ENDPOINT'))","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    service = AzureRealtimeWebsocket(\n        deployment_name='gpt-4o-realtime',\n        endpoint='https://myresource.openai.azure.com',\n        api_key='...',\n    )\nexcept ServiceInitializationError as e:\n    cause = e.__cause__  # the original ValidationError\n    if cause:\n        print(f'Settings validation failed: {cause}')\n    raise","preventionTips":["Always use https:// for Azure OpenAI endpoints — HttpsUrl rejects http://.","Validate endpoint URL format before passing to constructors.","Keep .env files clean — quote values with special characters.","Read the chained ValidationError (__cause__) for the specific field that failed."],"tags":["azure-openai","realtime","pydantic","settings-validation","websocket"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}