microsoft/autogen · error · Exception
Please set AZURE_OPENAI_ENDPOINT environment variable.
Error message
Please set AZURE_OPENAI_ENDPOINT environment variable.
What it means
Second guard in LLMConfiguration.GetAzureOpenAIGPT3_5_Turbo(): after the API key, it requires AZURE_OPENAI_ENDPOINT because AzureOpenAIConfig needs the resource endpoint URL (e.g. https://<resource>.openai.azure.com) to route requests. Seeing this exact message means AZURE_OPENAI_API_KEY was present but the endpoint variable was not.
Source
Thrown at dotnet/samples/AgentChat/AutoGen.Basic.Sample/LLMConfiguration.cs:22
using OpenAI;
using OpenAI.Chat;
namespace AutoGen.Basic.Sample;
internal static class LLMConfiguration
{
public static ChatClient GetOpenAIGPT4o_mini()
{
var openAIKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new Exception("Please set OPENAI_API_KEY environment variable.");
var modelId = "gpt-4o-mini";
return new OpenAIClient(openAIKey).GetChatClient(modelId);
}
public static AzureOpenAIConfig GetAzureOpenAIGPT3_5_Turbo(string? deployName = null)
{
var azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? throw new Exception("Please set AZURE_OPENAI_API_KEY environment variable.");
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new Exception("Please set AZURE_OPENAI_ENDPOINT environment variable.");
deployName = deployName ?? Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOY_NAME") ?? throw new Exception("Please set AZURE_OPENAI_DEPLOY_NAME environment variable.");
return new AzureOpenAIConfig(endpoint, deployName, azureOpenAIKey);
}
}
View on GitHub (pinned to 027ecf0a37)
Solutions
- Set AZURE_OPENAI_ENDPOINT to your resource endpoint (Azure Portal -> your Azure OpenAI resource -> Keys and Endpoint -> Endpoint), e.g. export AZURE_OPENAI_ENDPOINT=https://myresource.openai.azure.com.
- Also set AZURE_OPENAI_DEPLOY_NAME, which the helper validates immediately after this line.
- Copy all three values (key, endpoint, deployment) from the same Portal page to avoid partial config.
- Use the exact variable names the helper reads — no OPENAI_ENDPOINT or AZURE_OPENAI_RESOURCE variants.
Example fix
// before
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new Exception("Please set AZURE_OPENAI_ENDPOINT environment variable.");
// after
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set. Use the Endpoint value from your Azure OpenAI resource's 'Keys and Endpoint' page."); Defensive patterns
Strategy: validation
Validate before calling
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrWhiteSpace(endpoint) || !Uri.IsWellFormedUriString(endpoint, UriKind.Absolute))
{
throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT must be set to your resource endpoint, e.g. https://<resource>.openai.azure.com");
} Try / catch
try
{
var config = LLMConfiguration.GetAzureOpenAIGPT3_5_Turbo();
}
catch (Exception ex) when (ex.Message.Contains("AZURE_OPENAI_ENDPOINT"))
{
Console.Error.WriteLine($"Incomplete Azure OpenAI config: {ex.Message}");
} Prevention
- Set the endpoint at the same time as the key — both come from the same Portal page.
- Use the full https://<resource>.openai.azure.com URL; a bare resource name passes the null check but breaks later.
- Batch-validate all AZURE_OPENAI_* variables in one startup check.
When it happens
Trigger: A sample calling LLMConfiguration.GetAzureOpenAIGPT3_5_Turbo() where AZURE_OPENAI_API_KEY is set but AZURE_OPENAI_ENDPOINT is unset/empty. The deployment-name check (AZURE_OPENAI_DEPLOY_NAME) runs after and has not executed yet.
Common situations: Partial Azure configuration — developers copy the key but forget the endpoint from the same Azure Portal page; endpoint stored under a different name (OPENAI_ENDPOINT); CI secret list missing one of the three Azure variables.
Related errors
- Please set AZURE_OPENAI_API_KEY environment variable.
- Please set environment variable AZURE_OPENAI_API_KEY
- BING_API_KEY environment variable is not set
- Please set OPENAI_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/7aa52f7d8af864ea.
Report an issue: GitHub.