Repository navigation
fix(chat): call Azure OpenAI v1 API with the OpenAI SDK, drop Azure.AI.OpenAI - #1566
Merged
Merged
Conversation
…I.OpenAI
Chat on dev fails with HTTP 404 because AIChatService builds the Responses
client by hand at {endpoint}/openai/deployments/{name}, a route the service
does not have for Responses. Prod still runs the older SDK-built client
(/openai/responses) and works, so the next prod deploy would break chat.
Use the plain OpenAI SDK against the documented v1 route instead, as
Microsoft's migration guidance recommends (Azure.AI.OpenAI has had no
release since 2026-03-13):
- Add AzureOpenAIV1Clients: Responses and embedding clients at
{endpoint}/openai/v1, no api-version, deployment name as the model,
Entra bearer auth (scope unchanged).
- AIChatService and the embedding generator use it; remove the hand-built
deployment URL, api-version policy and AzureOpenAIClient registration,
plus two unused Semantic Kernel chat registrations.
- Replace Microsoft.SemanticKernel with Microsoft.SemanticKernel.Core (the
metapackage was the only source of Azure.AI.OpenAI) and drop the
Azure.AI.OpenAI version.
- Add tests pinning the request method, URL, auth header and model.
…forgiving operators
…n v1 client tests
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.
Why
Chat on dev fails ("Unable to connect to the chat service"). The server logs show
ClientResultException: HTTP 404 (Resource not found)fromResponsesClient.CreateResponseAsync.#1282 replaced
AzureOpenAIClient.GetResponsesClient()(binary-incompatible after the OpenAI 2.12 bump) with a hand-builtResponsesClientwhose base is{endpoint}/openai/deployments/{name}. Responses has no deployment-scoped route: that path returns 404 for every deployment (gpt-5included). The SDK's own client called{endpoint}/openai/responses?api-version=2025-04-01-preview(I read theAzure.AI.OpenAI2.9.0-beta.1 source). Prod still runs the August code (77c809fb) with the SDK client and works, so the next prod deploy would break prod chat.Azure.AI.OpenAIhas had no release since 2026-03-13, and its changelog/migration guide recommend using theOpenAISDK directly against the v1 routes. (Azure.AI.Extensions.OpenAItargets Foundry agents, not this use.)What changed
AzureOpenAIV1Clients: Responses and embedding clients at{endpoint}/openai/v1, noapi-version, deployment name asmodel, Entra bearer auth. Token scope is unchanged (cognitiveservices.azure.com) so only one variable changes.AIChatServiceand the embedding generator use it. Removed the hand-built deployment URL, theapi-versionpolicy, theAzureOpenAIClientregistration and two unused Semantic Kernel chat registrations (AddAzureOpenAIChatClient/AddAzureOpenAIChatCompletion; nothing resolves them).Microsoft.SemanticKernel->Microsoft.SemanticKernel.Core(KernelandTextChunkerstill come from it). The metapackage was the only thing pulling inAzure.AI.OpenAI, which is gone from the dependency graph. Removed its version entry.AzureOpenAIV1ClientsTests: pin method, URL, query, auth header andmodelfor both clients through a stub transport.Not verified (needs dev)
The resource is private, so I could not call it from CI or my machine. Please send one chat message on dev after deploy; contextual search is on by default, so it exercises both chat and embeddings. Things that could still fail:
ecs-cog-prod.cognitiveservices.azure.comwithgrok-4-1-fast-non-reasoning(Microsoft documents Grok via the Foundry project route.../api/projects/<project>/openai/v1; the projectessentialcsharpexists but is not in Terraform);https://ai.azure.com/.default);/openai/v1/embeddingsinstead of the classic deployment route.If the account host does not work, the next step is a Terraform change (the endpoint comes from
AIOptions--EndpointKey Vault secrets, source of truth isEssentialCSharp.AzureResourceManagement), dev first, since prod still runs the old code.Hold the pending Production approval until chat works on dev.
Test plan
dotnet testEssentialCSharp.Chat.Tests (35 passed, incl. 4 new)dotnet testEssentialCSharp.Web.Tests (190 passed)dotnet nuget why Azure.AI.OpenAIreports no dependency in the Web and Chat projects