Azure OpenAI - `model` parameter in request body causes failures when deployment name differs from model name
维护者通常 1 天内回复
@fengjikui 已经在做这个了。
开始于 2026年6月24日。
评估
调研方向
从 openai/lib/azure.py 中的 AzureOpenAI._build_request 开始,检查 _deployments_endpoints 和 options.json_data 的处理方式。使用不同的 deployment 名称和 model 名称重现 images.generate 请求,然后验证 deployment 路由仍然有效,并且请求正文符合 Azure OpenAI REST API 的预期。
由索引模型根据 Issue 内容生成。
描述
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
When using AzureOpenAI client, the SDK sends the model parameter in the request body even though Azure OpenAI uses URL-based routing (/deployments/{deployment-id}/...). This causes failures when the deployment name doesn't match the model name exactly.
This is particularly problematic for gpt-image-1.5 because:
- Azure resource naming rules prohibit periods (dots) in deployment names
- The model name contains a dot:
gpt-image-1.5 - Therefore, deployment name can never match model name (e.g., must use
gpt-image-1-5)
The Azure backend validates the body's model field against actual model names, rejecting valid deployment names.
To Reproduce
Steps to Reproduce
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint="https://<resource>.openai.azure.com/",
api_key="<key>",
api_version="2024-10-21"
)
# Deployment name: "gpt-image-1-5" (dashes, due to Azure naming rules)
# Model name: "gpt-image-1.5" (dot)
response = client.images.generate(
model="gpt-image-1-5", # deployment name
prompt="A sunset over mountains",
size="1024x1024",
n=1
)
Expected Behavior
Request succeeds because URL routing correctly targets the deployment:
POST /openai/deployments/gpt-image-1-5/images/generations
Actual Behavior
Request fails with:
{
"error": {
"message": "Model not supported with Responses API. Supported models are: ['gpt-image-1', 'gpt-image-1-mini', 'gpt-image-1.5']",
"type": "invalid_request_error"
}
}
The Azure backend is validating "model": "gpt-image-1-5" in the request body against model names, not deployment names.
Root Cause
In openai/lib/azure.py, the _build_request method uses model from the body to construct the URL but doesn't remove it from the body:
def _build_request(self, options, *, retries_taken=0):
if options.url in _deployments_endpoints and is_mapping(options.json_data):
model = options.json_data.get("model")
if model is not None and "/deployments" not in str(self.base_url.path):
options.url = f"/deployments/{model}{options.url}"
# BUG: model is still in options.json_data
return super()._build_request(options, retries_taken=retries_taken)
The Azure OpenAI REST API spec does not include model in the request body for deployment-based endpoints - model selection is done entirely via the URL path.
Code snippets
OS
Linux (Ubuntu)
Python version
3.12
Library version
2.7.1 (also tested against latest)
- 主要语言
- Python
- 星标
- 31.8k
- 派生
- 8k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 137
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
openai/openai-python#4022 · 19 条评论 ·
维护者通常 1 天内回复
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providers可能已有人在做 @mohmedmm 于 12 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#4017 · 3 条评论 ·
维护者通常 1 天内回复
-
Querystring drops explicit empty-string scalar values可能已有人在做 @sylvesterkaczmarek 于 34 天前认领。 未关闭sdk-breaking-change v4
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#3837 ·
维护者通常 1 天内回复
-
Define + export `ServiceTiers` string literal可能已有人在做 @SparshGarg999 于 61 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#3556 · 3 条评论 ·
维护者通常 1 天内回复
-
Empty OPENAI_BASE_URL prevents fallback to default API endpoint可能已有人在做 @Sehastrajit-S 于 27 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#2927 · 6 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 72/100
-
[Bug]: Importing weave changes the process-wide locale可能已有人在做 @himanshu748 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
-
UX
难度 1/5 1 小时以内 新手友好度 72/100
mediajunkie/piper-morgan-product#2008 · 2 条评论 ·