400 imagegen deployment must be provided through header: x-ms-oai-image-generati...
错误信息
API Error:400 imagegen deployment must be provided through header: x-ms-oai-image-generation-deployment
AI 解决方案
原文:API Error:400 imagegen deployment must be provided through header: x-ms-oai-image-generation-deployment
译文:API错误:400 imagegen部署必须通过请求头x-ms-oai-image-generation-deployment提供
🎯原因分析
该错误表明在进行图像生成相关的API调用时,未通过指定的请求头
x-ms-oai-image-generation-deployment 提供部署信息,导致请求无法正确处理。错误发生在API请求的头部验证阶段,系统检测到缺少必要的部署标识参数。💡解决方案
在发送API请求时,确保在HTTP请求头中添加
x-ms-oai-image-generation-deployment 字段,并配置正确的部署名称或ID。// 修复后的代码示例(以JavaScript为例)
const response = await fetch('https://api.example.com/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY',
'x-ms-oai-image-generation-deployment': 'your-deployment-name' // 添加部署信息
},
body: JSON.stringify({
prompt: 'a cute fox',
n: 1,
size: '1024x1024'
})
});