microsoft/semantic-kernel · error · InvalidOperationException
AZURE_OPENAI_ENDPOINT is not set.
Error message
AZURE_OPENAI_ENDPOINT is not set.
What it means
The Azure OpenAI ToolCall_WithOpenAPI migration sample throws InvalidOperationException when AZURE_OPENAI_ENDPOINT is null. This sample shows agents using tools provided via an OpenAPI specification, comparing SK's plugin system (importing OpenAPI documents into the Kernel) with AF's direct tool registration. The endpoint backs the AzureOpenAIChatClient for both paths.
Source
Thrown at dotnet/samples/AgentFrameworkMigration/AzureOpenAI/Step04_ToolCall_WithOpenAPI/Program.cs:14
// Copyright (c) Microsoft. All rights reserved.
// This sample demonstrates how to use an Agent with function tools provided via an OpenAPI spec with both Semantic Kernel and Agent Framework.
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Plugins.OpenApi;
using OpenAI.Chat;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
await SKAgent();
await AFAgent();
async Task SKAgent()
{
Console.WriteLine("\n=== SK Agent ===\n");
// Create a kernel with an Azure OpenAI chat client.
var kernel = Kernel.CreateBuilder().AddAzureOpenAIChatClient(deploymentName, endpoint, new AzureCliCredential()).Build();
// Load the OpenAPI Spec from a file.
var plugin = await kernel.ImportPluginFromOpenApiAsync("github", "OpenAPISpec.json");
// Create the agent, and provide the kernel with the OpenAPI function tools to the agent.
var agent = new ChatCompletionAgent()
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Set AZURE_OPENAI_ENDPOINT to your Azure OpenAI resource URL
- Optionally set AZURE_OPENAI_DEPLOYMENT_NAME (defaults to gpt-4o-mini)
- Ensure az login is current for AzureCliCredential
- Verify the model deployment supports function calling for OpenAPI-based tools
Example fix
// before
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
// after
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrWhiteSpace(endpoint))
throw new InvalidOperationException(
"AZURE_OPENAI_ENDPOINT is not set. Required for Azure OpenAI samples."); Defensive patterns
Strategy: validation
Validate before calling
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrWhiteSpace(endpoint))
{
Console.Error.WriteLine("AZURE_OPENAI_ENDPOINT is not set. Required for OpenAPI tool samples.");
return;
} Type guard
static bool IsAzureOpenAIEndpointConfigured() =>
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")); Try / catch
try
{
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
}
catch (InvalidOperationException ex) when (ex.Message.Contains("AZURE_OPENAI_ENDPOINT"))
{
Console.Error.WriteLine(ex.Message);
return;
} Prevention
- Verify the OpenAPI spec URL is reachable in addition to setting the endpoint
- Ensure the deployed model supports function calling for OpenAPI-based tools
- Note this sample defaults to gpt-4o-mini, not gpt-4o like other AzureOpenAI samples
- Run az login before executing
When it happens
Trigger: Running AzureOpenAI/Step04_ToolCall_WithOpenAPI without AZURE_OPENAI_ENDPOINT. The throw at line 14 fires before the OpenAPI document is loaded or any agent invokes a tool.
Common situations: The OpenAPI URL in the sample is unreachable (separate network issue masked by the env-var error that fires first); forgetting this sample uses Azure OpenAI rather than plain OpenAI (the OpenAI/ samples use OPENAI_API_KEY instead); az login expired.
Related errors
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/349f1f901a447149.
Report an issue: GitHub.