microsoft / microsoft/semantic-kernel

.Net: Bug: .NET api-key header not sent - OpenAIChatCompletion not working with Azure AI Foundry deployments

Open
#10,455 10 comments 1 reaction 1 assignee View on GitHub

@dmytrostruk is already working on this.

Since Feb 10, 2025.

.NET bug
Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
14h 13m
Merged PRs (30d)
18

Description

Describe the bug
api-key header is not being sent when using the AddOpenAIChatCompletion Kernel extensions. Instead an Authorization: Bearer * header is being sent which does not work with Azure AI Foundry deployments - they require an api-key header.

To Reproduce
Steps to reproduce the behavior:

  1. Register an OpenAI chat client:
            services.AddOpenAIChatCompletion(
                modelId: modelId,
                serviceId: modelId,
                openAIClient: new OpenAIClient(
                    credential: new ApiKeyCredential(
                        apiKey
                    ),
                    options: new OpenAIClientOptions
                    {
                        Endpoint = new Uri(endpoint)
                    }
                )
            );
  1. Obtain it and send a request:
        var chatModel = _semanticKernel.GetRequiredService<IChatCompletionService>(chatModelInfo.ModelId);
        var response = await chatModel.GetChatMessageContentAsync(
                    chatHistory: _chatHistory,
                    kernel: _Kernel);

  1. The request will fail with a 401 Unauthorized

Expected behavior
api-key header should be sent

Platform

  • Language: C#
  • Source: v. 1.3.6
  • AI model: Phi-3-small-8k-instruct

Additional context
Obviously it can be worked around with a custom HTTP client that's sending the correct header, but this being a Microsoft-supported package it should integrate with Microsoft products seamlessly.

The URL https://.services.ai.azure.com/models is passed to the endpoint parameter.
From the official docs it would seem that this is supported out-of-the-box, but it's not. https://learn.microsoft.com/bg-bg/azure/ai-foundry/model-inference/concepts/endpoints?tabs=csharp#routing

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.