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 Basics migration sample throws InvalidOperationException when AZURE_FOUNDRY_PROJECT_ENDPOINT is null. This endpoint is distinct from a plain AZURE_OPENAI_ENDPOINT — it targets an Azure AI Foundry project, used to create cloud-hosted persistent agents via PersistentAgentsClient and AzureAIAgent. The sample compares SK's AzureAIAgent against the Agent Framework equivalent.

Source

Thrown at dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step01_Basics/Program.cs:12

// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.Agents.Persistent;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.SemanticKernel;
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 = "Tell me a joke about a pirate.";

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,
        name: "GenerateStory",

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set AZURE_FOUNDRY_PROJECT_ENDPOINT to your Foundry project URL (format: https://<project>-resource.services.ai.azure.com/api/projects/<project>)
  2. Optionally set AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME (defaults to gpt-4o)
  3. Provision an Azure AI Foundry project and deploy a model in the Azure portal first
  4. Ensure az login is current 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")
    ?? throw new InvalidOperationException(
        "AZURE_FOUNDRY_PROJECT_ENDPOINT is not set. " +
        "Format: https://<project>-resource.services.ai.azure.com/api/projects/<project>");
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 not set.");
    Console.Error.WriteLine("Format: https://<project>-resource.services.ai.azure.com/api/projects/<project>");
    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);
    Console.Error.WriteLine("Provision an Azure AI Foundry project first.");
    return;
}

Prevention

When it happens

Trigger: Running AzureAIFoundry/Step01_Basics without AZURE_FOUNDRY_PROJECT_ENDPOINT. The throw at line 12 fires before SKAgentAsync, SKAgent_As_AFAgentAsync, and AFAgentAsync execute.

Common situations: Confusing AZURE_FOUNDRY_PROJECT_ENDPOINT with AZURE_OPENAI_ENDPOINT (different URL formats and resources); not having an Azure AI Foundry project provisioned; setting the OpenAI endpoint variable instead of the Foundry project endpoint.

Related errors


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