{"record":{"id":"8763989e9bfaa390","repo":"microsoft/semantic-kernel","slug":"azure-openai-endpoint-is-not-set-876398","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/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs","lineNumber":14,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\nusing Azure.AI.OpenAI;\nusing Azure.Identity;\nusing Microsoft.Agents.AI;\nusing Microsoft.Extensions.AI;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.SemanticKernel.Agents.OpenAI;\nusing OpenAI.Responses;\n\n#pragma warning disable OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.\n#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.\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 SKAgentAsync();\nawait SKAgent_As_AFAgentAsync();\nawait AFAgentAsync();\n\nasync Task SKAgentAsync()\n{\n    Console.WriteLine(\"\\n=== SK Agent ===\\n\");\n\n    var serviceCollection = new ServiceCollection();\n    serviceCollection.AddTransient<Microsoft.SemanticKernel.Agents.Agent>((sp)\n        => new OpenAIResponseAgent(new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())\n        .GetResponsesClient(), deploymentName)\n        {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs#L1-L32","documentation":"The Azure OpenAI Responses DependencyInjection migration sample throws InvalidOperationException when AZURE_OPENAI_ENDPOINT is unset. This sample shows DI-based agent registration using the OpenAI Responses API on Azure OpenAI. The endpoint is needed at composition time to build the Responses API client that backs the registered AIAgent.","triggerScenarios":"Running AzureOpenAIResponses/Step04_DependencyInjection without AZURE_OPENAI_ENDPOINT. The throw at line 14 fires before any DI container or agent factory is invoked.","commonSituations":"DI samples read env vars directly, not IConfiguration or user secrets; the endpoint may be in a sibling project's launchSettings.json; running from CLI without the VS launch profile.","solutions":["Set AZURE_OPENAI_ENDPOINT to your Azure OpenAI resource URL","Optionally set AZURE_OPENAI_DEPLOYMENT_NAME (defaults to gpt-4o)","If using VS, add the variable to Properties/launchSettings.json","Ensure az login is current for AzureCliCredential"],"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. See README.md for configuration.\");","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. Required for Responses API DI samples.\");\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":["DI samples read env vars directly — add them to launchSettings.json for VS debugging","Validate env vars at the top of Program.cs before building the service container","Ensure the deployed model supports the Responses API","Run az login for AzureCliCredential"],"tags":["configuration","csharp","azure-openai","semantic-kernel","environment-variables","responses-api","dependency-injection","agent-framework-migration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}