{"record":{"id":"75feba265ce17f54","repo":"microsoft/semantic-kernel","slug":"please-provide-valid-azureopenai-configuration-in","errorCode":null,"errorMessage":"Please provide valid AzureOpenAI configuration in appsettings.Development.json file.","messagePattern":"Please provide valid AzureOpenAI configuration in appsettings\\.Development\\.json file\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"dotnet/samples/Demos/CopilotAgentPlugins/CopilotAgentPluginsDemoSample/DemoCommand.cs","lineNumber":267,"sourceCode":"                    {\n                        AllowStrictSchemaAdherence = true\n                    }\n                )\n                });\n#pragma warning restore SKEXP0001\n    }\n\n    private static (Kernel, PromptExecutionSettings) InitializeAzureOpenAiKernel(IConfiguration configuration, bool enableLogging)\n    {\n        var azureOpenAIConfig = configuration.GetSection(\"AzureOpenAI\");\n        var apiKey = azureOpenAIConfig[\"ApiKey\"];\n        var chatDeploymentName = azureOpenAIConfig[\"ChatDeploymentName\"];\n        var chatModelId = azureOpenAIConfig[\"ChatModelId\"];\n        var endpoint = azureOpenAIConfig[\"Endpoint\"];\n\n        if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(chatDeploymentName) || string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))\n        {\n            throw new InvalidOperationException(\"Please provide valid AzureOpenAI configuration in appsettings.Development.json file.\");\n        }\n\n        var builder = Kernel.CreateBuilder();\n        if (enableLogging)\n        {\n            builder.Services.AddLogging(loggingBuilder =>\n                {\n                    loggingBuilder.AddFilter(level => true);\n                    loggingBuilder.AddProvider(new SemanticKernelLoggerProvider());\n                });\n        }\n        return (builder.AddAzureOpenAIChatCompletion(\n                deploymentName: chatDeploymentName,\n                endpoint: endpoint,\n                serviceId: \"AzureOpenAIChat\",\n                apiKey: apiKey,\n                modelId: chatModelId).Build(),\n#pragma warning disable SKEXP0001","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/CopilotAgentPlugins/CopilotAgentPluginsDemoSample/DemoCommand.cs#L249-L285","documentation":"InitializeAzureOpenAiKernel requires all four AzureOpenAI values (ApiKey, ChatDeploymentName, ChatModelId, Endpoint) and throws InvalidOperationException if any is null/empty. Deployment name is Azure-specific (distinct from model id) and is mandatory because Azure OpenAI is addressed by deployment, not raw model name.","triggerScenarios":"Any of configuration[\"AzureOpenAI:ApiKey\"], [\"ChatDeploymentName\"], [\"ChatModelId\"], [\"Endpoint\"] is null or empty.","commonSituations":"AzureOpenAI section absent, deployment created in Azure but name not copied into config, or using a key/endpoint from a different resource than the deployment.","solutions":["Populate the full AzureOpenAI section in appsettings.Development.json (all four keys).","Confirm ChatDeploymentName matches the deployment you created in Azure OpenAI Studio exactly.","Validate Endpoint is the full https://<resource>.openai.azure.com/ form.","Use a key from the same Azure OpenAI resource that hosts the deployment."],"exampleFix":"// before\nif (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(chatDeploymentName) || string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))\n    throw new InvalidOperationException(\"Please provide valid AzureOpenAI configuration...\");\n\n// after (appsettings.Development.json)\n{\n  \"AzureOpenAI\": {\n    \"ApiKey\": \"<key>\",\n    \"ChatDeploymentName\": \"gpt-4o\",\n    \"ChatModelId\": \"gpt-4o\",\n    \"Endpoint\": \"https://<resource>.openai.azure.com/\"\n  }\n}","handlingStrategy":"validation","validationCode":"string[] required = { \"ApiKey\", \"ChatDeploymentName\", \"ChatModelId\", \"Endpoint\" };\nvar missing = required.Where(k => string.IsNullOrEmpty(configuration[$\"AzureOpenAI:{k}\"])).ToList();\nif (missing.Count != 0)\n    throw new InvalidOperationException(\"Missing AzureOpenAI keys: \" + string.Join(\", \", missing));","typeGuard":"static bool HasAzureOpenAiConfig(IConfiguration c) =>\n    new[] { \"ApiKey\", \"ChatDeploymentName\", \"ChatModelId\", \"Endpoint\" }\n        .All(k => !string.IsNullOrEmpty(c[$\"AzureOpenAI:{k}\"]));","tryCatchPattern":null,"preventionTips":["Copy the deployment name exactly from Azure OpenAI Studio.","Use the same resource's key and endpoint.","Prefer user secrets for the ApiKey."],"tags":["configuration","azure-openai","kernel","samples"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}