Skip to content

fix(chat): call Azure OpenAI v1 API with the OpenAI SDK, drop Azure.AI.OpenAI - #1566

Merged
BenjaminMichaelis merged 4 commits into
mainfrom
chore/openai-v1-migration
Oct 26, 2026
Merged

BenjaminMichaelis merged 4 commits into
mainfrom
chore/openai-v1-migration

Conversation

@BenjaminMichaelis

Copy link
Copy Markdown
Member

Why

Chat on dev fails ("Unable to connect to the chat service"). The server logs show ClientResultException: HTTP 404 (Resource not found) from ResponsesClient.CreateResponseAsync.

#1282 replaced AzureOpenAIClient.GetResponsesClient() (binary-incompatible after the OpenAI 2.12 bump) with a hand-built ResponsesClient whose base is {endpoint}/openai/deployments/{name}. Responses has no deployment-scoped route: that path returns 404 for every deployment (gpt-5 included). The SDK's own client called {endpoint}/openai/responses?api-version=2025-04-01-preview (I read the Azure.AI.OpenAI 2.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.OpenAI has had no release since 2026-03-13, and its changelog/migration guide recommend using the OpenAI SDK directly against the v1 routes. (Azure.AI.Extensions.OpenAI targets Foundry agents, not this use.)

What changed

  • New AzureOpenAIV1Clients: Responses and embedding clients at {endpoint}/openai/v1, no api-version, deployment name as model, Entra bearer auth. Token scope is unchanged (cognitiveservices.azure.com) so only one variable changes.
  • AIChatService and the embedding generator use it. Removed the hand-built deployment URL, the api-version policy, the AzureOpenAIClient registration and two unused Semantic Kernel chat registrations (AddAzureOpenAIChatClient/AddAzureOpenAIChatCompletion; nothing resolves them).
  • Microsoft.SemanticKernel -> Microsoft.SemanticKernel.Core (Kernel and TextChunker still come from it). The metapackage was the only thing pulling in Azure.AI.OpenAI, which is gone from the dependency graph. Removed its version entry.
  • AzureOpenAIV1ClientsTests: pin method, URL, query, auth header and model for 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:

  • the v1 route on ecs-cog-prod.cognitiveservices.azure.com with grok-4-1-fast-non-reasoning (Microsoft documents Grok via the Foundry project route .../api/projects/<project>/openai/v1; the project essentialcsharp exists but is not in Terraform);
  • the token scope on the v1 route (a 401 would point at https://ai.azure.com/.default);
  • embeddings now use /openai/v1/embeddings instead of the classic deployment route.

If the account host does not work, the next step is a Terraform change (the endpoint comes from AIOptions--Endpoint Key Vault secrets, source of truth is EssentialCSharp.AzureResourceManagement), dev first, since prod still runs the old code.

Hold the pending Production approval until chat works on dev.

Test plan

  • dotnet test EssentialCSharp.Chat.Tests (35 passed, incl. 4 new)
  • dotnet test EssentialCSharp.Web.Tests (190 passed)
  • dotnet nuget why Azure.AI.OpenAI reports no dependency in the Web and Chat projects
  • Chat message works on dev

…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.
@BenjaminMichaelis
BenjaminMichaelis merged commit 366e0c6 into main Oct 26, 2026
13 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the chore/openai-v1-migration branch October 26, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant