{"record":{"id":"21903dfdf15a6d51","repo":"microsoft/semantic-kernel","slug":"azure-openai-endpoint-is-not-set-21903d","errorCode":null,"errorMessage":"AZURE_OPENAI_ENDPOINT is not set.","messagePattern":"AZURE_OPENAI_ENDPOINT is not set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/AgentFrameworkMigration/AzureOpenAI/Step01_Basics/Program.cs","lineNumber":11,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\nusing Azure.AI.OpenAI;\nusing Azure.Identity;\nusing Microsoft.Agents.AI;\nusing Microsoft.SemanticKernel;\nusing Microsoft.SemanticKernel.Agents;\nusing Microsoft.SemanticKernel.Connectors.OpenAI;\nusing OpenAI.Chat;\n\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set.\");\nvar deploymentName = System.Environment.GetEnvironmentVariable(\"AZURE_OPENAI_DEPLOYMENT_NAME\") ?? \"gpt-4o\";\nvar userInput = \"Tell me a joke about a pirate.\";\n\nConsole.WriteLine($\"User Input: {userInput}\");\n\nawait SKAgent();\nawait SKAgent_As_AFAgentAsync();\nawait AFAgent();\n\nasync Task SKAgent()\n{\n    Console.WriteLine(\"\\n=== SK Agent ===\\n\");\n\n    var builder = Kernel.CreateBuilder().AddAzureOpenAIChatClient(deploymentName, endpoint, new AzureCliCredential());\n\n    var agent = new ChatCompletionAgent()\n    {\n        Kernel = builder.Build(),","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AzureOpenAI/Step01_Basics/Program.cs#L1-L29","documentation":"The Azure OpenAI Basics migration sample throws InvalidOperationException when AZURE_OPENAI_ENDPOINT is not set. This is the foundational sample comparing SK's ChatCompletionAgent with the Agent Framework's AIAgent for a simple pirate-joke prompt. The endpoint is used with AzureCliCredential to create an AzureOpenAIChatClient.","triggerScenarios":"Running AzureOpenAI/Step01_Basics without AZURE_OPENAI_ENDPOINT in the environment. The throw at line 11 fires before SKAgent(), SKAgent_As_AFAgentAsync(), or AFAgent() execute.","commonSituations":"First-time setup without reading the README's Environment Variables section; the endpoint was set for a Foundry sample (wrong variable name); az login session expired.","solutions":["Set AZURE_OPENAI_ENDPOINT to your Azure OpenAI resource URL (e.g. https://my-resource.cognitiveservices.azure.com/)","Optionally set AZURE_OPENAI_DEPLOYMENT_NAME (defaults to gpt-4o)","Run az login to ensure AzureCliCredential can acquire a token","Verify the deployment name matches an actual deployment in your Azure OpenAI resource"],"exampleFix":"// before\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set.\");\n\n// after\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\");\nif (string.IsNullOrWhiteSpace(endpoint))\n    throw new InvalidOperationException(\n        \"AZURE_OPENAI_ENDPOINT is not set. \" +\n        \"Set it: export AZURE_OPENAI_ENDPOINT='https://<resource>.cognitivesives.azure.com/'\");","handlingStrategy":"validation","validationCode":"var endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\");\nif (string.IsNullOrWhiteSpace(endpoint))\n{\n    Console.Error.WriteLine(\"AZURE_OPENAI_ENDPOINT is not set.\");\n    Console.Error.WriteLine(\"Example: https://<resource>.cognitiveservices.azure.com/\");\n    return;\n}","typeGuard":"static bool IsAzureOpenAIEndpointConfigured() =>\n    !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\"));","tryCatchPattern":"try\n{\n    var endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\")\n        ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set.\");\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AZURE_OPENAI_ENDPOINT\"))\n{\n    Console.Error.WriteLine(ex.Message);\n    return;\n}","preventionTips":["Set AZURE_OPENAI_ENDPOINT in a shared env-var script sourced before running any AzureOpenAI sample","Verify the endpoint URL matches an existing Azure OpenAI resource in your subscription","Run az login before executing samples that use AzureCliCredential","Add the variable to launchSettings.json for VS debugging"],"tags":["configuration","csharp","azure-openai","semantic-kernel","environment-variables","agent-framework-migration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}