{"record":{"id":"8c8b3d2aa14da707","repo":"microsoft/semantic-kernel","slug":"azure-openai-endpoint-is-not-set-8c8b3d","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/Step02_ToolCall/Program.cs","lineNumber":11,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\nusing System.ComponentModel;\nusing Azure.AI.OpenAI;\nusing Azure.Identity;\nusing Microsoft.Extensions.AI;\nusing Microsoft.SemanticKernel;\nusing Microsoft.SemanticKernel.Agents;\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 = \"What is the weather like in Amsterdam?\";\n\nConsole.WriteLine($\"User Input: {userInput}\");\n\n[KernelFunction]\n[Description(\"Get the weather for a given location.\")]\nstatic string GetWeather([Description(\"The location to get the weather for.\")] string location)\n    => $\"The weather in {location} is cloudy with a high of 15°C.\";\n\nawait SKAgent();\nawait SKAgent_As_AFAgentAsync();\nawait AFAgent();\n\nasync Task SKAgent()\n{\n    var builder = Kernel.CreateBuilder().AddAzureOpenAIChatClient(deploymentName, endpoint, new AzureCliCredential());\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AzureOpenAI/Step02_ToolCall/Program.cs#L1-L29","documentation":"The Azure OpenAI ToolCall migration sample throws InvalidOperationException when AZURE_OPENAI_ENDPOINT is missing. This sample demonstrates function calling with the GetWeather KernelFunction, comparing SK and AF approaches. The endpoint backs the AzureOpenAIChatClient that processes tool-call rounds.","triggerScenarios":"Running AzureOpenAI/Step02_ToolCall without AZURE_OPENAI_ENDPOINT. The throw at line 11 fires before the GetWeather function is defined or any agent is constructed.","commonSituations":"Setting only AZURE_OPENAI_DEPLOYMENT_NAME but forgetting the endpoint; using an API-key-based approach in another sample and assuming this one reads keys from settings; the deployed model does not support function calling.","solutions":["Set AZURE_OPENAI_ENDPOINT to your Azure OpenAI resource URL","Optionally set AZURE_OPENAI_DEPLOYMENT_NAME (defaults to gpt-4o)","Ensure az login is current for AzureCliCredential","Verify the deployed model supports function/tool calling"],"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{\n    Console.Write(\"Enter Azure OpenAI endpoint: \");\n    endpoint = Console.ReadLine() ?? \"\";\n}","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 tool-calling 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 deployed model supports function calling before running tool-call samples","Use a shared env-var setup script for all AzureOpenAI Step samples","Ensure az login is current for AzureCliCredential","Check that AZURE_OPENAI_DEPLOYMENT_NAME (if set) matches an actual deployment in the resource"],"tags":["configuration","csharp","azure-openai","semantic-kernel","environment-variables","tool-calling","agent-framework-migration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}