microsoft/semantic-kernel · critical · InvalidOperationException
Please provide valid AzureOpenAI configuration in appsetting
Error message
Please provide valid AzureOpenAI configuration in appsettings.Development.json file.
What it means
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.
Source
Thrown at dotnet/samples/Demos/CopilotAgentPlugins/CopilotAgentPluginsDemoSample/DemoCommand.cs:267
{
AllowStrictSchemaAdherence = true
}
)
});
#pragma warning restore SKEXP0001
}
private static (Kernel, PromptExecutionSettings) InitializeAzureOpenAiKernel(IConfiguration configuration, bool enableLogging)
{
var azureOpenAIConfig = configuration.GetSection("AzureOpenAI");
var apiKey = azureOpenAIConfig["ApiKey"];
var chatDeploymentName = azureOpenAIConfig["ChatDeploymentName"];
var chatModelId = azureOpenAIConfig["ChatModelId"];
var endpoint = azureOpenAIConfig["Endpoint"];
if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(chatDeploymentName) || string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))
{
throw new InvalidOperationException("Please provide valid AzureOpenAI configuration in appsettings.Development.json file.");
}
var builder = Kernel.CreateBuilder();
if (enableLogging)
{
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddFilter(level => true);
loggingBuilder.AddProvider(new SemanticKernelLoggerProvider());
});
}
return (builder.AddAzureOpenAIChatCompletion(
deploymentName: chatDeploymentName,
endpoint: endpoint,
serviceId: "AzureOpenAIChat",
apiKey: apiKey,
modelId: chatModelId).Build(),
#pragma warning disable SKEXP0001View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(chatDeploymentName) || string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))
throw new InvalidOperationException("Please provide valid AzureOpenAI configuration...");
// after (appsettings.Development.json)
{
"AzureOpenAI": {
"ApiKey": "<key>",
"ChatDeploymentName": "gpt-4o",
"ChatModelId": "gpt-4o",
"Endpoint": "https://<resource>.openai.azure.com/"
}
} Defensive patterns
Strategy: validation
Validate before calling
string[] required = { "ApiKey", "ChatDeploymentName", "ChatModelId", "Endpoint" };
var missing = required.Where(k => string.IsNullOrEmpty(configuration[$"AzureOpenAI:{k}"])).ToList();
if (missing.Count != 0)
throw new InvalidOperationException("Missing AzureOpenAI keys: " + string.Join(", ", missing)); Type guard
static bool HasAzureOpenAiConfig(IConfiguration c) =>
new[] { "ApiKey", "ChatDeploymentName", "ChatModelId", "Endpoint" }
.All(k => !string.IsNullOrEmpty(c[$"AzureOpenAI:{k}"])); Prevention
- Copy the deployment name exactly from Azure OpenAI Studio.
- Use the same resource's key and endpoint.
- Prefer user secrets for the ApiKey.
When it happens
Trigger: Any of configuration["AzureOpenAI:ApiKey"], ["ChatDeploymentName"], ["ChatModelId"], ["Endpoint"] is null or empty.
Common situations: 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.
Related errors
- Invalid kernel selection. {selectedKernelName} is not a vali
- Please provide valid Ollama configuration in appsettings.Dev
- Please provide valid OpenAI configuration in appsettings.Dev
- OpenAI/Azure OpenAI configuration was not found.
- AZURE_OPENAI_ENDPOINT is not set.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/75feba265ce17f54.
Report an issue: GitHub.