{"record":{"id":"349f1f901a447149","repo":"microsoft/semantic-kernel","slug":"azure-openai-endpoint-is-not-set-349f1f","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/Step04_ToolCall_WithOpenAPI/Program.cs","lineNumber":14,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\n// This sample demonstrates how to use an Agent with function tools provided via an OpenAPI spec with both Semantic Kernel and Agent Framework.\n\nusing Azure.AI.OpenAI;\nusing Azure.Identity;\nusing Microsoft.Agents.AI;\nusing Microsoft.Extensions.AI;\nusing Microsoft.SemanticKernel;\nusing Microsoft.SemanticKernel.Agents;\nusing Microsoft.SemanticKernel.Plugins.OpenApi;\nusing OpenAI.Chat;\n\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set.\");\nvar deploymentName = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_DEPLOYMENT_NAME\") ?? \"gpt-4o-mini\";\n\nawait SKAgent();\nawait AFAgent();\n\nasync Task SKAgent()\n{\n    Console.WriteLine(\"\\n=== SK Agent ===\\n\");\n\n    // Create a kernel with an Azure OpenAI chat client.\n    var kernel = Kernel.CreateBuilder().AddAzureOpenAIChatClient(deploymentName, endpoint, new AzureCliCredential()).Build();\n\n    // Load the OpenAPI Spec from a file.\n    var plugin = await kernel.ImportPluginFromOpenApiAsync(\"github\", \"OpenAPISpec.json\");\n\n    // Create the agent, and provide the kernel with the OpenAPI function tools to the agent.\n    var agent = new ChatCompletionAgent()\n    {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AzureOpenAI/Step04_ToolCall_WithOpenAPI/Program.cs#L1-L32","documentation":"The Azure OpenAI ToolCall_WithOpenAPI migration sample throws InvalidOperationException when AZURE_OPENAI_ENDPOINT is null. This sample shows agents using tools provided via an OpenAPI specification, comparing SK's plugin system (importing OpenAPI documents into the Kernel) with AF's direct tool registration. The endpoint backs the AzureOpenAIChatClient for both paths.","triggerScenarios":"Running AzureOpenAI/Step04_ToolCall_WithOpenAPI without AZURE_OPENAI_ENDPOINT. The throw at line 14 fires before the OpenAPI document is loaded or any agent invokes a tool.","commonSituations":"The OpenAPI URL in the sample is unreachable (separate network issue masked by the env-var error that fires first); forgetting this sample uses Azure OpenAI rather than plain OpenAI (the OpenAI/ samples use OPENAI_API_KEY instead); az login expired.","solutions":["Set AZURE_OPENAI_ENDPOINT to your Azure OpenAI resource URL","Optionally set AZURE_OPENAI_DEPLOYMENT_NAME (defaults to gpt-4o-mini)","Ensure az login is current for AzureCliCredential","Verify the model deployment supports function calling for OpenAPI-based tools"],"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. Required for Azure OpenAI samples.\");","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 OpenAPI tool 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":["Verify the OpenAPI spec URL is reachable in addition to setting the endpoint","Ensure the deployed model supports function calling for OpenAPI-based tools","Note this sample defaults to gpt-4o-mini, not gpt-4o like other AzureOpenAI samples","Run az login before executing"],"tags":["configuration","csharp","azure-openai","semantic-kernel","environment-variables","tool-calling","openapi","agent-framework-migration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}