Python: [Bug]: AZURE_OPENAI_API_VERSION is ignored by the OpenAI clients on the Azure route
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Description
OpenAIChatCompletionClient, OpenAIChatClient and OpenAIEmbeddingClient ignore AZURE_OPENAI_API_VERSION, whether it is set in the environment or in a .env file, and always send their built-in default api-version to Azure. Passing api_version= explicitly works.
The constructors document the opposite. For example, OpenAIChatCompletionClient says: "When not provided explicitly, the constructor reads AZURE_OPENAI_API_VERSION and then uses the Chat Completions default." OpenAIChatClient and OpenAIEmbeddingClient say the same, and the package README lists the variable as the Azure OpenAI API version.
Cause: load_openai_service_settings in agent_framework_openai/_shared.py passes the default into load_settings:
azure_settings = load_settings(
AzureOpenAISettings,
env_prefix="AZURE_OPENAI_",
...
api_version=api_version or default_azure_api_version,
...
)
load_settings gives explicit keyword values priority over .env files and environment variables. Since api_version or default_azure_api_version is never None, the environment value can never win. This looks like a regression from #4925; before it, only the explicit api_version was passed and the default was applied afterwards.
The existing tests miss this because the Azure test fixture sets AZURE_OPENAI_API_VERSION to 2024-12-01-preview, which is also the Chat Completions default.
Expected: an explicit api_version wins, then AZURE_OPENAI_API_VERSION (environment or .env), then the client's default.
Code Sample
import os
for name in ("OPENAI_API_KEY", "AZURE_OPENAI_BASE_URL"):
os.environ.pop(name, None) # make sure the clients take the Azure route
os.environ.update({
"AZURE_OPENAI_ENDPOINT": "https://my-resource.openai.azure.com",
"AZURE_OPENAI_API_KEY": "test-key",
"AZURE_OPENAI_MODEL": "my-deployment",
"AZURE_OPENAI_API_VERSION": "2025-04-01-preview",
})
from agent_framework.openai import OpenAIChatClient, OpenAIChatCompletionClient, OpenAIEmbeddingClient
for client_type in (OpenAIChatCompletionClient, OpenAIChatClient, OpenAIEmbeddingClient):
client = client_type()
print(f"{client_type.__name__:<27} api_version={client.api_version}")
Output on main:
OpenAIChatCompletionClient api_version=2024-12-01-preview
OpenAIChatClient api_version=preview
OpenAIEmbeddingClient api_version=2024-10-21
Every client should report 2025-04-01-preview. The same default also goes out as the api-version query parameter on the request, and setting the variable in a .env file passed via env_file_path behaves the same way.
Error Messages / Stack Traces
None. Requests silently use the default version.
Package Versions
agent-framework-openai: 1.15.0, agent-framework-core: 1.20.0 (source checkout of main at b9d24c8fb)
Python Version
Python 3.13
Additional Context
- Reproduced on Windows and Linux.
- One question for the fix:
OpenAIChatClient(Responses) defaults topreviewon the/openai/v1/path. Once the variable is read again, a dated value set for Chat Completions would also be used by the Responses client. That matches its docstring and the behavior before #4925, but if the Responses client shouldn't pick up the shared variable, its docstring would need to change instead. - Fix: pass only the explicit
api_versiontoload_settings, and apply the client default afterwards when nothing set a version. I'll open a PR with that and regression tests.
- Ngôn ngữ chính
- Python
- Star
- 14.3k
- Fork
- 2.5k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 383
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/agent-framework
-
Python: [Bug]: native Windows --files paths skip changed-package tasksCó thể đã có người làm @leilei3167 đã nhận 1 ngày trước. Đang mởneeds-maintainer-triage python triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/agent-framework#9742 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
.NET triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
microsoft/agent-framework#9704 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Python: FileSessionStore.set fails on Windows for long session IDs because its temp file name is 38 characters longer than the snapshotCó thể đã có người làm @Sonica-B đã nhận 2 ngày trước. Đang mởpython ready-for-implementation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/agent-framework#9682 · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Python: foundry-hosting drops request `metadata` from the stored response — `_create_response_event_stream` never passes `request` to `ResponseEventStream`Có thể đã có người làm @its-amann đã nhận 2 ngày trước. Đang mởpython triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/agent-framework#9529 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
.NET: Proposal: add an llms.txtĐang mở.NET python triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
microsoft/agent-framework#9092 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/agent-framework
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
glossyio/traffic-monitor#264 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add self-hostĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Atarity/deploy-your-own-saas#102 ·
-
[Bug]: RDFlex silently drops the covariate adjustment when the outcome or treatment column is integer-typedCó thể đã có người làm @vrjdev đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DoubleML/doubleml-for-py#424 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agentic-dmx docs enhancement
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
521xueweihan/HelloGitHub#4150 ·