microsoft/semantic-kernel · error · InvalidOperationException
AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
Error message
AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
What it means
The Azure AI Foundry CodeInterpreter migration sample throws InvalidOperationException when AZURE_FOUNDRY_PROJECT_ENDPOINT is null. This sample demonstrates the code interpreter tool with persistent agents for generating and running Python code. The Foundry project endpoint is required to provision the agent with code interpreter capabilities.
Source
Thrown at dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step04_CodeInterpreter/Program.cs:15
// Copyright (c) Microsoft. All rights reserved.
using System.Text;
using Azure.AI.Agents.Persistent;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
#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.
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
var deploymentName = System.Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME") ?? "gpt-4o";
var userInput = "Create a python code file using the code interpreter tool with a code ready to determine the values in the Fibonacci sequence that are less then the value of 101";
Console.WriteLine($"User Input: {userInput}");
await SKAgentAsync();
await SKAgent_As_AFAgentAsync();
await AFAgentAsync();
async Task SKAgentAsync()
{
Console.WriteLine("\n=== SK Agent ===\n");
var azureAgentClient = AzureAIAgent.CreateAgentsClient(azureEndpoint, new AzureCliCredential());
PersistentAgent definition = await azureAgentClient.Administration.CreateAgentAsync(deploymentName, tools: [new CodeInterpreterToolDefinition()]);
AzureAIAgent agent = new(definition, azureAgentClient);View on GitHub (pinned to c028a0c7dc)
Solutions
- Set AZURE_FOUNDRY_PROJECT_ENDPOINT to your Azure AI Foundry project URL
- Optionally set AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME (defaults to gpt-4o)
- Ensure the Foundry project has code interpreter enabled and a compatible model deployed
- Run az login for AzureCliCredential
Example fix
// before
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
// after
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT");
if (string.IsNullOrWhiteSpace(azureEndpoint))
throw new InvalidOperationException(
"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set. Provision a Foundry project first."); Defensive patterns
Strategy: validation
Validate before calling
var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT");
if (string.IsNullOrWhiteSpace(endpoint))
{
Console.Error.WriteLine("AZURE_FOUNDRY_PROJECT_ENDPOINT is required for code interpreter samples.");
return;
} Type guard
static bool IsFoundryEndpointConfigured() =>
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT")); Try / catch
try
{
var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT")
?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
}
catch (InvalidOperationException ex) when (ex.Message.Contains("AZURE_FOUNDRY_PROJECT_ENDPOINT"))
{
Console.Error.WriteLine(ex.Message);
return;
} Prevention
- Ensure the Foundry project has code interpreter enabled before running this sample
- Confirm the deployed model supports code interpreter capabilities
- Run az login before executing
- Distinguish Foundry project endpoint from Azure OpenAI resource endpoint
When it happens
Trigger: Running AzureAIFoundry/Step04_CodeInterpreter without AZURE_FOUNDRY_PROJECT_ENDPOINT. The throw at line 15 fires before the code interpreter tool is attached or the Fibonacci prompt is sent.
Common situations: The Foundry project does not have code interpreter enabled; confusing the standard Azure OpenAI endpoint with the Foundry project endpoint; the model deployed in the project does not support code interpreter.
Related errors
- AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
- AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
- AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/9b99eeb8c798f6bd.
Report an issue: GitHub.