microsoft/semantic-kernel · error · InvalidOperationException

AZURE_OPENAI_ENDPOINT is not set.

Error message

AZURE_OPENAI_ENDPOINT is not set.

What it means

The Concurrent Orchestration migration sample throws InvalidOperationException at startup when the AZURE_OPENAI_ENDPOINT environment variable is null. This sample compares Semantic Kernel's ConcurrentOrchestration against the Agent Framework's concurrent agent workflow. The endpoint is used with AzureCliCredential to construct an AzureOpenAIChatClient.

Source

Thrown at dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step01_Concurrent/Program.cs:14

// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.Orchestration;
using Microsoft.SemanticKernel.Agents.Orchestration.Concurrent;
using Microsoft.SemanticKernel.Agents.Runtime.InProcess;

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";

var agentInstructions = "You are a translation assistant who only responds in {0}. Respond to any input by outputting the name of the input language and then translating the input to {0}.";

// This sample compares running concurrent orchestrations using
// Semantic Kernel and the Agent Framework.
Console.WriteLine("=== Semantic Kernel Concurrent Orchestration ===");
await SKConcurrentOrchestration();

Console.WriteLine("\n=== Agent Framework Concurrent Agent Workflow ===");
await AFConcurrentAgentWorkflow();

# region SKConcurrentOrchestration
#pragma warning disable SKEXP0110 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
async Task SKConcurrentOrchestration()
{
    ConcurrentOrchestration orchestration = new([
        GetSKTranslationAgent("French"),

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set AZURE_OPENAI_ENDPOINT to your Azure OpenAI resource URL (e.g. https://my-resource.cognitiveservices.azure.com/)
  2. Optionally set AZURE_OPENAI_DEPLOYMENT_NAME (defaults to gpt-4o-mini)
  3. Ensure you are logged into Azure CLI (az login) since the sample uses AzureCliCredential
  4. On Windows use $env:AZURE_OPENAI_ENDPOINT = '...'; on bash/macOS use export AZURE_OPENAI_ENDPOINT='...'

Example fix

// before
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");

// after — helpful prompt with fallback
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrWhiteSpace(endpoint))
{
    Console.Write("Enter your Azure OpenAI endpoint: ");
    endpoint = Console.ReadLine()?.Trim() ?? throw new InvalidOperationException("Endpoint is required.");
}
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.");
    Console.Error.WriteLine("Example: https://<resource>.cognitiveservices.azure.com/");
    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);
    Console.Error.WriteLine("Set: export AZURE_OPENAI_ENDPOINT='https://<resource>.cognitiveservices.azure.com/'");
    return;
}

Prevention

When it happens

Trigger: Running dotnet run in AgentOrchestrations/Step01_Concurrent without setting AZURE_OPENAI_ENDPOINT in the environment. The null-coalescing throw fires immediately at line 14, before any orchestration logic executes.

Common situations: First run of the sample without reading the README's Environment Variables section; setting the variable in one terminal session but running in another; forgetting to export the variable in bash (set without export); .env file not loaded by the console host.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/96041099f512ed83. Report an issue: GitHub.