Repository navigation
.Net: add Azure AI Foundry api-key header HttpClient sample (#10455) - #14609
Open
SparkyPunk (sparkysolutions10-pixel) wants to merge 2 commits into
Conversation
…#10455) Signed-off-by: sparkysolutions10-pixelmy <sparkysolutions10@gmail.com>
SparkyPunk (sparkysolutions10-pixel)
requested a review
from a team
as a code owner
October 16, 2026 07:40
SparkyPunk (sparkysolutions10-pixel)
temporarily deployed
to
github-app-auth
October 16, 2026 07:40 — with
GitHub Actions
Inactive
SparkyPunk (sparkysolutions10-pixel)
temporarily deployed
to
github-app-auth
October 16, 2026 07:40 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The sample omits the required inference API version, and its test does not exercise header injection.
2 open findings
What changed in this PR
Adds a .NET sample showing how to customize OpenAI connector authentication for Azure AI Foundry, addressing #10455 without changing core client abstractions.
Changes:
- Adds a handler that injects
api-keywhile preserving existing values. - Demonstrates registering the custom HTTP client with a kernel.
| File | Description |
|---|---|
| dotnet/samples/Concepts/ChatCompletion/Connectors_CustomHttpClient.cs | Adds the Foundry configuration sample, authentication handler, and kernel-construction assertion. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| var kernel = Kernel.CreateBuilder() | ||
| .AddOpenAIChatCompletion( | ||
| modelId: "Phi-3-small-8k-instruct", | ||
| endpoint: new Uri("https://my-resource.services.ai.azure.com/models"), |
| httpClient: httpClient) | ||
| .Build(); | ||
|
|
||
| Assert.NotNull(kernel); |
…icrosoft#10455) Addresses Copilot code-review feedback by appending api-version and adding in-memory unit tests. Signed-off-by: sparkysolutions10-pixelmy <sparkysolutions10@gmail.com>
SparkyPunk (sparkysolutions10-pixel)
temporarily deployed
to
github-app-auth
October 16, 2026 07:56 — with
GitHub Actions
Inactive
Author
|
Thank you for the constructive review Copilot! 🙌 Both recommended findings have been addressed in commit
Ready for maintainer review! 🚀 |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem & Solution Overview
Fixes #10455
Problem Description
When connecting to Azure AI Foundry model inference endpoints (e.g. Phi-3, Mistral, LLaMA on
https://<resource>.services.ai.azure.com/models) usingAddOpenAIChatCompletion, the underlying client defaults to sendingAuthorization: Bearer <key>, which results in401 Unauthorizedbecause Azure AI Foundry endpoints strictly require theapi-keyheader.As noted by maintainers in #10455, the underlying OpenAI SDK client is protocol-agnostic, and custom headers should be handled via a custom
HttpClient/DelegatingHandler. However, Semantic Kernel lacked a dedicated sample showing how developers can configure this seamless integration.Solution Summary
Added
UseCustomHttpClientWithApiKeyHeaderForAzureAIFoundryandAzureAIFoundryApiKeyHandlerindotnet/samples/Concepts/ChatCompletion/Connectors_CustomHttpClient.cs:AzureAIFoundryApiKeyHandlerinheriting fromDelegatingHandler.api-keyheader on outgoing requests to Azure AI Foundry deployments.Verification & Testing
Connectors_CustomHttpClientSigned-off-by)