microsoft/semantic-kernel · error · ArgumentException

A2AClient:ApiKey must be provided

Error message

A2AClient:ApiKey must be provided

What it means

Error "A2AClient:ApiKey must be provided" thrown in microsoft/semantic-kernel.

Source

Thrown at dotnet/samples/Demos/A2AClientServer/A2AClient/Program.cs:46

    }

    #region private
    private static async System.Threading.Tasks.Task RunCliAsync()
    {
        // Set up the logging
        using var loggerFactory = LoggerFactory.Create(builder =>
        {
            builder.AddConsole();
            builder.SetMinimumLevel(LogLevel.Information);
        });
        var logger = loggerFactory.CreateLogger("A2AClient");

        // Retrieve configuration settings
        IConfigurationRoot configRoot = new ConfigurationBuilder()
            .AddEnvironmentVariables()
            .AddUserSecrets(Assembly.GetExecutingAssembly())
            .Build();
        var apiKey = configRoot["A2AClient:ApiKey"] ?? throw new ArgumentException("A2AClient:ApiKey must be provided");
        var modelId = configRoot["A2AClient:ModelId"] ?? "gpt-4.1";
        var agentUrls = configRoot["A2AClient:AgentUrls"] ?? "http://localhost:5000/;http://localhost:5001/;http://localhost:5002/";

        // Create the Host agent
        var hostAgent = new HostClientAgent(logger);
        await hostAgent.InitializeAgentAsync(modelId, apiKey, agentUrls!.Split(";"));
        AgentThread thread = new ChatHistoryAgentThread();
        try
        {
            while (true)
            {
                // Get user message
                Console.Write("\nUser (:q or quit to exit): ");
                string? message = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(message))
                {
                    Console.WriteLine("Request cannot be empty.");
                    continue;

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set the A2AClient:ApiKey value in appsettings.json or user secrets before running the client.
  2. Verify the configuration section name is exactly 'A2AClient' and the key is 'ApiKey'.

When it happens

Trigger: Thrown at dotnet/samples/Demos/A2AClientServer/A2AClient/Program.cs:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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