{"record":{"id":"09258cbe99d4a6cd","repo":"microsoft/semantic-kernel","slug":"openai-azure-openai-configuration-was-not-found","errorCode":null,"errorMessage":"OpenAI/Azure OpenAI configuration was not found.","messagePattern":"OpenAI/Azure OpenAI configuration was not found\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"dotnet/samples/Demos/FunctionInvocationApproval/Program.cs","lineNumber":192,"sourceCode":"            .Build();\n\n        var openAIOptions = config.GetSection(OpenAIOptions.SectionName).Get<OpenAIOptions>();\n        var azureOpenAIOptions = config.GetSection(AzureOpenAIOptions.SectionName).Get<AzureOpenAIOptions>();\n\n        if (openAIOptions is not null && openAIOptions.IsValid)\n        {\n            builder.AddOpenAIChatCompletion(openAIOptions.ChatModelId, openAIOptions.ApiKey);\n        }\n        else if (azureOpenAIOptions is not null && azureOpenAIOptions.IsValid)\n        {\n            builder.AddAzureOpenAIChatCompletion(\n                azureOpenAIOptions.ChatDeploymentName,\n                azureOpenAIOptions.Endpoint,\n                azureOpenAIOptions.ApiKey);\n        }\n        else\n        {\n            throw new Exception(\"OpenAI/Azure OpenAI configuration was not found.\");\n        }\n    }\n\n    #endregion\n}\n","sourceCodeStart":174,"sourceCodeEnd":198,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/FunctionInvocationApproval/Program.cs#L174-L198","documentation":"The Function Invocation Approval sample tries OpenAI options first, then Azure OpenAI options, and throws a plain Exception if neither set is valid. This is the 'no chat-completion backend configured at all' terminal branch — neither OpenAIOptions nor AzureOpenAIOptions.IsValid passed.","triggerScenarios":"openAIOptions is null/invalid AND azureOpenAIOptions is null or azureOpenAIOptions.IsValid is false.","commonSituations":"Neither OpenAI nor AzureOpenAI section configured, IsValid returns false because required sub-fields are missing, or the env is missing both sets of variables.","solutions":["Configure at least one of OpenAI or AzureOpenAI options fully so its IsValid is true.","Check the IsValid implementation to see which fields each option requires and supply them.","Set the relevant environment variables if not using appsettings.","Pick exactly one provider to avoid ambiguous precedence."],"exampleFix":"// before\nelse\n{\n    throw new Exception(\"OpenAI/Azure OpenAI configuration was not found.\");\n}\n\n// after (actionable message + typed exception)\nelse\n{\n    throw new InvalidOperationException(\n        \"No chat completion backend configured. Set either OpenAI (ApiKey+ChatModelId) \" +\n        \"or AzureOpenAI (ApiKey+Endpoint+ChatDeploymentName). \" +\n        $\"openAIValid={openAIOptions?.IsValid ?? false}, azureValid={azureOpenAIOptions?.IsValid ?? false}.\");\n}","handlingStrategy":"validation","validationCode":"bool openAiValid = openAIOptions is not null && openAIOptions.IsValid;\nbool azureValid = azureOpenAIOptions is not null && azureOpenAIOptions.IsValid;\nif (!openAiValid && !azureValid)\n    throw new InvalidOperationException(\n        $\"No chat backend configured. openAIValid={openAiValid}, azureValid={azureValid}.\");","typeGuard":"static bool HasAnyBackend(OpenAiOptions? o, AzureOpenAiOptions? a) =>\n    (o?.IsValid ?? false) || (a?.IsValid ?? false);","tryCatchPattern":null,"preventionTips":["Inspect IsValid to see which fields each option requires.","Configure exactly one provider fully to avoid precedence ambiguity.","Add a startup config-health check."],"tags":["configuration","openai","azure-openai","samples"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}