{"record":{"id":"7aa52f7d8af864ea","repo":"microsoft/autogen","slug":"please-set-azure-openai-endpoint-environment-varia","errorCode":null,"errorMessage":"Please set AZURE_OPENAI_ENDPOINT environment variable.","messagePattern":"Please set AZURE_OPENAI_ENDPOINT environment variable\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"dotnet/samples/AgentChat/AutoGen.Basic.Sample/LLMConfiguration.cs","lineNumber":22,"sourceCode":"using OpenAI;\nusing OpenAI.Chat;\n\nnamespace AutoGen.Basic.Sample;\n\ninternal static class LLMConfiguration\n{\n    public static ChatClient GetOpenAIGPT4o_mini()\n    {\n        var openAIKey = Environment.GetEnvironmentVariable(\"OPENAI_API_KEY\") ?? throw new Exception(\"Please set OPENAI_API_KEY environment variable.\");\n        var modelId = \"gpt-4o-mini\";\n\n        return new OpenAIClient(openAIKey).GetChatClient(modelId);\n    }\n\n    public static AzureOpenAIConfig GetAzureOpenAIGPT3_5_Turbo(string? deployName = null)\n    {\n        var azureOpenAIKey = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_API_KEY\") ?? throw new Exception(\"Please set AZURE_OPENAI_API_KEY environment variable.\");\n        var endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new Exception(\"Please set AZURE_OPENAI_ENDPOINT environment variable.\");\n        deployName = deployName ?? Environment.GetEnvironmentVariable(\"AZURE_OPENAI_DEPLOY_NAME\") ?? throw new Exception(\"Please set AZURE_OPENAI_DEPLOY_NAME environment variable.\");\n        return new AzureOpenAIConfig(endpoint, deployName, azureOpenAIKey);\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":27,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/samples/AgentChat/AutoGen.Basic.Sample/LLMConfiguration.cs#L4-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new Exception(\"Please set AZURE_OPENAI_ENDPOINT environment variable.\");\n\n// after\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\")\n    ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set. Use the Endpoint value from your Azure OpenAI resource's 'Keys and Endpoint' page.\");","handlingStrategy":"validation","validationCode":"var endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\");\nif (string.IsNullOrWhiteSpace(endpoint) || !Uri.IsWellFormedUriString(endpoint, UriKind.Absolute))\n{\n    throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT must be set to your resource endpoint, e.g. https://<resource>.openai.azure.com\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var config = LLMConfiguration.GetAzureOpenAIGPT3_5_Turbo();\n}\ncatch (Exception ex) when (ex.Message.Contains(\"AZURE_OPENAI_ENDPOINT\"))\n{\n    Console.Error.WriteLine($\"Incomplete Azure OpenAI config: {ex.Message}\");\n}","preventionTips":["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."],"tags":["configuration","environment-variables","azure","azure-openai","dotnet","autogen"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}