Repository navigation
Python: Read AZURE_OPENAI_API_VERSION before applying the Azure client default - #9098
Conversation
load_openai_service_settings passed api_version or the client default to load_settings. Explicit values there always beat .env files and environment variables, so AZURE_OPENAI_API_VERSION was never read and every Azure request used the hard-coded default. Pass only the explicit value, and apply the default after loading when nothing set a version.
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 3d13171b52ac
Model: gpt-5.6-sol
Overview
The change restores the documented Azure API-version precedence by allowing explicit .env and process-environment values to resolve before applying each client's default. The shared loader preserves routing behavior, explicit overrides, and client-specific defaults, while tests cover the resolved settings and outgoing request query for all precedence layers. No publishable Critical, High, or Medium defect was established.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Motivation & Context
On the Azure route,
OpenAIChatCompletionClient,OpenAIChatClientandOpenAIEmbeddingClientignoreAZURE_OPENAI_API_VERSIONfrom the environment or a.envfile and always send their built-in defaultapi-version, although their docstrings and the package README say the variable is read.load_openai_service_settingspassedapi_version or default_azure_api_versiontoload_settings, and an explicit value there always beats.envfiles and environment variables.Description & Review Guide
What are the major changes?
load_openai_service_settingspasses only the explicitapi_versiontoload_settings, then applies the client default when neither the argument, the.envfile nor the environment set a version:New tests in
test_openai_shared.py:test_azure_api_version_precedencechecks default, environment over default, and explicit over environment, both in the loaded settings and in theapi-versionquery parameter of a built request.test_azure_api_version_from_env_filecovers the.envpath.test_azure_clients_read_api_version_from_environmentruns the three public clients with the variable set to a value that differs from every default.The environment and
.envcases fail without the change (5 of the 7 new cases) and pass with it.What is the impact of these changes?
The documented precedence is restored: explicit
api_version, thenAZURE_OPENAI_API_VERSION, then the client default. For the repro in the linked issue:An explicit
api_versionand the defaults are unchanged, and nothing changes when the variable is unset.What do you want reviewers to focus on?
OpenAIChatClient(Responses) uses the/openai/v1/path with the defaultpreview. With this change, a datedAZURE_OPENAI_API_VERSIONset for Chat Completions is also used by the Responses client, which matches its docstring and the behavior before [BREAKING] Python: fix OpenAI Azure routing and provider samples #4925. If the Responses client shouldn't read the shared variable, I can keep it on its default and update its docstring instead.Related Issue
Fixes #9097
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.