Python: Fix OpenAIEmbeddingClient to use AsyncOpenAI for /openai/v1 endpoints#5137
Open
chetantoshniwal wants to merge 4 commits intomicrosoft:mainfrom
Open
Python: Fix OpenAIEmbeddingClient to use AsyncOpenAI for /openai/v1 endpoints#5137chetantoshniwal wants to merge 4 commits intomicrosoft:mainfrom
chetantoshniwal wants to merge 4 commits intomicrosoft:mainfrom
Conversation
When base_url ends with /openai/v1/ and a credential is provided,
load_openai_service_settings was creating an AsyncAzureOpenAI client.
The Azure SDK rewrites deployment-based endpoints (including /embeddings)
by inserting /deployments/{model}/ into the URL, producing 404s on the
OpenAI-compatible /openai/v1 endpoint.
Use AsyncOpenAI instead of AsyncAzureOpenAI when the resolved base_url
targets /openai/v1, converting the Azure token provider to an async
api_key callable. The responses_mode path is unaffected because the
Responses API (/responses) is not in the SDK's rewrite list.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
chetantoshniwal
commented
Apr 7, 2026
Contributor
Author
chetantoshniwal
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 97% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by chetantoshniwal's agents
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Azure /openai/v1 compatibility for OpenAIEmbeddingClient by avoiding AsyncAzureOpenAI path rewriting that incorrectly inserts /deployments/{model}/... for OpenAI-compatible endpoints.
Changes:
- Route Azure
/openai/v1embedding requests throughAsyncOpenAI(instead ofAsyncAzureOpenAI) to preserve OpenAI-compatible request paths. - Add
_ensure_async_token_providerto normalize Azure token providers for use asAsyncOpenAIapi_keycallables. - Add unit tests covering
/openai/v1initialization (credential + API key) and ensuring standard Azure endpoints still useAsyncAzureOpenAI.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
python/packages/openai/agent_framework_openai/_shared.py |
Detects Azure /openai/v1 base URLs (non-Responses mode) and constructs an AsyncOpenAI client to avoid Azure SDK path rewriting; adds token-provider wrapper helper. |
python/packages/openai/tests/openai/test_openai_embedding_client_azure.py |
Adds unit tests verifying OpenAIEmbeddingClient selects AsyncOpenAI for /openai/v1 base URLs and keeps AsyncAzureOpenAI for standard Azure endpoints. |
python/packages/a2a/tests/test_a2a_agent.py |
Minor test formatting change (list literal formatting for .extend). |
…hanges - Revert unrelated formatting change in test_a2a_agent.py - Fix test_init_with_openai_v1_base_url_and_api_key_uses_openai_client to exercise the Azure settings path (via AZURE_OPENAI_BASE_URL env var) instead of the plain OpenAI path, covering the elif api_key branch - Add _ensure_async_token_provider unit tests for both sync and async token providers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…eddingClient` does not work with `/openai/v1` endpoint
chetantoshniwal
commented
Apr 7, 2026
Contributor
Author
chetantoshniwal
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 97% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by chetantoshniwal's agents
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.
Motivation and Context
When using the Azure
/openai/v1endpoint,OpenAIEmbeddingClientrouted requests throughAsyncAzureOpenAI, which rewrites request paths by inserting/deployments/{model}/. This produced 404 errors because the/openai/v1endpoint expects standard OpenAI-compatible paths.Fixes #5068
Description
The root cause is that
AsyncAzureOpenAImodifies request URLs (e.g.,/embeddings→/deployments/{model}/embeddings), which is incompatible with the/openai/v1API surface. The fix detects when the resolvedbase_urlends with/openai/v1(and the caller is not using the Responses API, whose/responsespath is not rewritten) and constructs anAsyncOpenAIclient instead, preserving request URLs as-is. A helper_ensure_async_token_providerwraps potentially synchronous Azure token providers into awaitables as required byAsyncOpenAI. Tests verify that both credential-based and API-key-based configurations correctly produce anAsyncOpenAIclient for/openai/v1URLs, while standard Azure endpoints continue usingAsyncAzureOpenAI.Contribution Checklist