Repository navigation
Python: Prefer an injected Azure OpenAI deployment over environment model aliases - #9987
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits intoNov 3, 2026
Conversation
…ases An injected AsyncAzureOpenAI client was losing its configured deployment to AZURE_OPENAI_* model variables. Use an explicit model first, then that deployment, then the environment.
ZedingZhang (ZedingZhang)
temporarily deployed
to
github-app-auth
November 2, 2026 18:23 — with
GitHub Actions
Inactive
ZedingZhang (ZedingZhang)
requested review from
Darren Cohen (dargilco) and
sophia-ramsey
as code owners
November 2, 2026 18:23
ZedingZhang (ZedingZhang)
temporarily deployed
to
github-app-auth
November 2, 2026 18:24 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new inline SDK-client factory violates the required test-helper layout and must be moved to a callable factory fixture or an imported helper module.
1 open issue
What changed in this PR
Fixes #9949 by making the shared Python OpenAI settings resolver prefer an injected Azure client's deployment over ambient model variables.
Changes:
- Sets Azure model precedence to explicit
model, injected deployment, then environment aliases. - Adds regression tests across chat, chat-completions, and embedding clients.
- Documents the precedence while preserving plain OpenAI and no-client behavior.
| File | Description |
|---|---|
python/packages/openai/tests/openai/test_injected_client_model.py |
Tests injected-client precedence, explicit overrides, and environment fallback. |
python/packages/openai/README.md |
Explains injected deployment precedence and client ownership. |
python/packages/openai/AGENTS.md |
Documents request-model resolution order. |
python/packages/openai/agent_framework_openai/_shared.py |
Resolves injected Azure deployments before environment aliases. |
python/packages/openai/agent_framework_openai/_embedding_client.py |
Updates raw and layered embedding constructor docstrings. |
python/packages/openai/agent_framework_openai/_chat_completion_client.py |
Updates raw and layered chat-completion constructor docstrings. |
python/packages/openai/agent_framework_openai/_chat_client.py |
Updates raw and layered chat constructor docstrings. |
Review effort: Balanced
Parameterized reusable setup belongs in a callable factory fixture, not an inline test helper. Co-authored-by: ZedingZhang <me@zedingzhang.com>
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 3, 2026
ZedingZhang (ZedingZhang)
deleted the
fix/azure-openai-injected-deployment-9949
branch
November 3, 2026 18:19
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.

Motivation & Context
An injected
AsyncAzureOpenAIclient already has a deployment, but the shared OpenAI settings resolver readsAZURE_OPENAI_*model variables first. The wrapper then calls a different deployment than the SDK client the caller supplied. Chat, chat-completions, and embedding clients all go through this path.Description & Review Guide
load_openai_service_settings, resolve the Azure model as explicitmodel, then the injectedAsyncAzureOpenAIdeployment, then the environment aliases. Document that order and add regression tests for the three public clients.modelis omitted. An explicitmodelstill wins. A plainAsyncOpenAIclient still uses the OpenAI model variables. Creating a client without an injected client is unchanged.load_openai_service_settings. Hosts that previously let an ambient Azure model variable override an injected client's deployment will now follow the client.Related Issue
Fixes #9949. The issue has the
ready-for-implementationlabel; no competing open PR was found before submission.AI Assistance
AI assistance details: Cursor's coding agent assisted with the implementation, regression tests, docstring and README updates, and this PR description. I reviewed the change and accept responsibility for it.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.