{"record":{"id":"733079c159b9a6c7","repo":"microsoft/semantic-kernel","slug":"failed-to-create-azure-openai-settings-exc-733079","errorCode":null,"errorMessage":"Failed to create Azure OpenAI settings: {exc}","messagePattern":"Failed to create Azure OpenAI settings: (.+?)","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"critical","filePath":"python/semantic_kernel/agents/open_ai/azure_responses_agent.py","lineNumber":106,"sourceCode":"            credential: The credential to use for authentication.\n            kwargs: Additional keyword arguments\n\n        Returns:\n            An Azure OpenAI client instance and the configured deployment name (model)\n        \"\"\"\n        try:\n            azure_openai_settings = AzureOpenAISettings(\n                api_key=api_key,\n                base_url=base_url,\n                endpoint=endpoint,\n                responses_deployment_name=deployment_name,\n                api_version=api_version,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n                token_endpoint=token_scope,\n            )\n        except ValidationError as exc:\n            raise AgentInitializationException(f\"Failed to create Azure OpenAI settings: {exc}\") from exc\n\n        if (\n            azure_openai_settings.api_key is None\n            and ad_token_provider is None\n            and ad_token is None\n            and azure_openai_settings.token_endpoint\n            and credential\n        ):\n            ad_token = get_entra_auth_token(credential, azure_openai_settings.token_endpoint)\n\n        # If we still have no credentials, we can't proceed\n        if not azure_openai_settings.api_key and not ad_token and not ad_token_provider and not credential:\n            raise AgentInitializationException(\n                \"Please provide either an api_key, ad_token, ad_token_provider or credential for authentication.\"\n            )\n\n        merged_headers = dict(copy(default_headers)) if default_headers else {}\n        if default_headers:","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/azure_responses_agent.py#L88-L124","documentation":"Raised by AzureResponsesAgent's client builder when constructing AzureOpenAISettings(...) raises a pydantic ValidationError. This is a hard fail during initialization; the wrapped ValidationError message in {exc} details which field failed validation (e.g. malformed endpoint URL, invalid type).","triggerScenarios":"Calling AzureResponsesAgent creation with values that fail AzureOpenAISettings validation: a non-HTTPS endpoint, a base_url that is not a valid Url, an api_version of the wrong type, or conflicting env-file values.","commonSituations":"Setting AZURE_OPENAI_ENDPOINT to a URL without https:// or with a typo; providing endpoint as a pydantic Url that fails HttpsUrl parsing; mixing base_url and endpoint incorrectly; corrupted .env file values.","solutions":["Read the wrapped ValidationError message: it names the failing field and reason.","Ensure endpoint is a full HTTPS URL (e.g. https://<resource>.openai.azure.com/).","Validate env values (AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_BASE_URL) are well-formed before constructing the agent.","If passing api_version explicitly, pass a valid API version string."],"exampleFix":"# before\nAzureResponsesAgent(endpoint=\"myresource.openai.azure.com\")  # missing https://\n# after\nAzureResponsesAgent(endpoint=\"https://myresource.openai.azure.com/\")","handlingStrategy":"try-catch","validationCode":"from pydantic import ValidationError\nfrom semantic_kernel.connectors.ai.open_ai.settings import AzureOpenAISettings\n\ntry:\n    settings = AzureOpenAISettings(\n        endpoint=endpoint, base_url=base_url, api_key=api_key,\n        responses_deployment_name=deployment_name, api_version=api_version,\n    )\nexcept ValidationError as exc:\n    raise ValueError(f\"Invalid Azure OpenAI settings: {exc}\") from exc","typeGuard":null,"tryCatchPattern":"from pydantic import ValidationError\nfrom semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\n\ntry:\n    agent = AzureResponsesAgent(endpoint=endpoint, deployment_name=name, api_key=key)\nexcept AgentInitializationException as e:\n    if \"Failed to create Azure OpenAI settings\" in str(e):\n        # inspect e.__cause__ which is the ValidationError\n        for err in e.__cause__.errors():\n            logging.error(\"settings field %s: %s\", err.get('loc'), err.get('msg'))\n    raise","preventionTips":["Validate endpoint/base_url are HTTPS URLs before constructing settings.","Run a config sanity check at app startup that constructs AzureOpenAISettings and reports errors.","Keep env_file_path accurate so the intended .env is loaded."],"tags":["azure-openai","configuration","semantic-kernel","agents","pydantic","validation","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}