{"record":{"id":"25d780fe2dad2cdf","repo":"microsoft/semantic-kernel","slug":"failed-to-validate-azure-ai-inference-settings-e","errorCode":null,"errorMessage":"Failed to validate Azure AI Inference settings: {e}","messagePattern":"Failed to validate Azure AI Inference settings: (.+?)","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/azure_ai_inference/services/azure_ai_inference_base.py","lineNumber":92,"sourceCode":"            instruction_role (str | None): The role to use for 'instruction' messages. (Optional)\n            credential: The credential to use for authentication. (Optional)\n            **kwargs: Additional keyword arguments.\n\n        Raises:\n            ServiceInitializationError: If an error occurs during initialization.\n        \"\"\"\n        managed_client = client is None\n        if not client:\n            try:\n                azure_ai_inference_settings = AzureAIInferenceSettings(\n                    api_key=api_key,\n                    endpoint=endpoint,\n                    api_version=api_version,\n                    env_file_path=env_file_path,\n                    env_file_encoding=env_file_encoding,\n                )\n            except ValidationError as e:\n                raise ServiceInitializationError(f\"Failed to validate Azure AI Inference settings: {e}\") from e\n\n            endpoint = str(azure_ai_inference_settings.endpoint)\n            if azure_ai_inference_settings.api_key is not None:\n                client = AzureAIInferenceClientType.get_client_class(client_type)(\n                    endpoint=endpoint,\n                    credential=AzureKeyCredential(azure_ai_inference_settings.api_key.get_secret_value()),\n                    user_agent=SEMANTIC_KERNEL_USER_AGENT,\n                    api_version=azure_ai_inference_settings.api_version,\n                )\n            else:\n                if credential is None:\n                    raise ServiceInitializationError(\"The 'credential' parameter is required for authentication.\")\n\n                client = AzureAIInferenceClientType.get_client_class(client_type)(\n                    endpoint=endpoint,\n                    credential=credential,\n                    user_agent=SEMANTIC_KERNEL_USER_AGENT,\n                    api_version=azure_ai_inference_settings.api_version,","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/azure_ai_inference/services/azure_ai_inference_base.py#L74-L110","documentation":"Raised during Azure AI Inference service construction when AzureAIInferenceSettings (api_key, endpoint, api_version from args/env) fails Pydantic validation. This is a ServiceInitializationError surfaced before any client is built; the original ValidationError is chained so the exact missing/invalid field is visible.","triggerScenarios":"No endpoint configured (AZURE_AI_INFERENCE_ENDPOINT missing and no endpoint arg), malformed endpoint URL, invalid api_version format, or env file not found when relying on env_file_path. The settings model requires a valid endpoint.","commonSituations":"Missing or misnamed environment variables (AZURE_AI_INFERENCE_ENDPOINT / AZURE_AI_INFERENCE_API_KEY / AZURE_AI_INFERENCE_API_VERSION); wrong .env path; endpoint set to a non-URL string; deploying without seeding env vars in CI.","solutions":["Inspect the chained ValidationError (e.__cause__) to see which field failed.","Set AZURE_AI_INFERENCE_ENDPOINT to a valid https URL (and AZURE_AI_INFERENCE_API_KEY / API_VERSION as needed), or pass endpoint= explicitly.","Verify env_file_path points to an existing .env with the required keys."],"exampleFix":"# before\nservice = AzureAIInferenceChatCompletion(model_id=\"gpt-4o\")  # no endpoint env → error\n\n# after\nexport AZURE_AI_INFERENCE_ENDPOINT=https://my-endpoint.services.ai.azure.com/models\nexport AZURE_AI_INFERENCE_API_KEY=...\nservice = AzureAIInferenceChatCompletion(model_id=\"gpt-4o\")","handlingStrategy":"validation","validationCode":"import os\n\nendpoint = os.getenv(\"AZURE_AI_INFERENCE_ENDPOINT\")\nassert endpoint and endpoint.startswith(\"https://\"), \\\n    \"Set AZURE_AI_INFERENCE_ENDPOINT to a valid https URL before constructing the service.\"","typeGuard":"def has_valid_endpoint(endpoint: str | None) -> bool:\n    return bool(endpoint) and str(endpoint).startswith(\"https://\")","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    service = AzureAIInferenceChatCompletion(model_id=model_id)\nexcept ServiceInitializationError as e:\n    print(\"Settings error:\", e.__cause__)","preventionTips":["Always set AZURE_AI_INFERENCE_ENDPOINT (and API_KEY/API_VERSION) in env or .env.","Validate endpoint URL format before construction.","In CI, seed env vars as a deployment step."],"tags":["azure-ai-inference","configuration","env-vars","service-init","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}