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

  1. Set AZURE_FOUNDRY_PROJECT_ENDPOINT to your Azure AI Foundry project URL
  2. Optionally set AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME (defaults to gpt-4o)
  3. Ensure the Foundry project has code interpreter enabled and a compatible model deployed
  4. 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

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


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/9b99eeb8c798f6bd. Report an issue: GitHub.