GPT Image 2 API
由 OpenAI 提供支持的 GPT Image 2 模型完整 API 参考。
模型变体
此 API 支持四个模型变体:
快速对比
支持的宽高比
16:9, 9:16, 1:1, 3:2, 2:3, 3:4, 4:3, 5:4, 4:5, 21:9
GPT Image 2(文生图)
接口地址
POST /api/v1/image/task
鉴权
Authorization: Bearer YOUR_API_KEY
请求参数
必填
注意: width:height 必须是以下比例之一:16:9、9:16、1:1、3:2、2:3、3:4、4:3、5:4、4:5、21:9
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'gpt-image-2',
prompt: 'A minimalist product shot of a ceramic mug on marble, soft studio light',
width: 1,
height: 1,
resolution: '1k',
quality: 'medium'
})
});
const { data } = await response.json();
const taskId = data.task_id;
const pollResponse = await fetch(
`https://api.flaq.ai/api/v1/image/${taskId}`,
{
headers: { Authorization: 'Bearer YOUR_API_KEY' }
}
);
const result = await pollResponse.json();
console.log(result.data.task_result.images[0].url);
GPT Image 2 Edit(图片编辑)
接口地址
POST /api/v1/image/task
请求参数
必填
选填
注意: 当提供 width 和 height 时,其比例必须是以下之一:16:9、9:16、1:1、3:2、2:3、3:4、4:3、5:4、4:5、21:9
单图编辑示例
{
model_name: 'gpt-image-2-edit',
prompt: 'Replace the background with a clean studio scene and brighten the product lighting',
image_url_list: ['https://example.com/product-photo.jpg'],
width: 16,
height: 9,
resolution: '1k',
quality: 'medium'
}
多图合成示例
{
model_name: 'gpt-image-2-edit',
prompt: 'Blend these reference images into a polished campaign composition while keeping the main subject identity consistent',
image_url_list: [
'https://example.com/image1.jpg',
'https://example.com/image2.jpg',
'https://example.com/image3.jpg'
],
width: 16,
height: 9,
resolution: '2k',
quality: 'high'
}
GPT Image 2 Client
与 GPT Image 2 使用相同参数和能力,只需将 model_name 设置为 gpt-image-2-client。这是预览体验版,稳定性可能较低。
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'gpt-image-2-client',
prompt: 'A luxury skincare still life with soft reflections and elegant typography',
width: 4,
height: 5,
resolution: '1k',
quality: 'medium'
})
});
const { data } = await response.json();
const taskId = data.task_id;
GPT Image 2 Edit Client
与 GPT Image 2 Edit 使用相同参数和能力,只需将 model_name 设置为 gpt-image-2-edit-client。这是预览体验版,稳定性可能较低。
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'gpt-image-2-edit-client',
prompt: 'Turn this portrait into a clean editorial poster while preserving the face and pose',
image_url_list: ['https://example.com/portrait.jpg'],
width: 4,
height: 5,
resolution: '1k',
quality: 'medium'
})
});
const { data } = await response.json();
const taskId = data.task_id;
响应格式
初始响应
所有 GPT Image 2 变体都会返回一个用于轮询的 task_id:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
轮询响应
轮询 GET /api/v1/image/{task_id} 查看任务状态:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "succeed",
"task_status_msg": null,
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}",
"task_result": {
"credit": 0.0997,
"images": [
{
"url": "https://example.com/generated-image.jpeg"
}
]
}
},
"message": "success"
}
状态值
submitted: 任务已接收
processing: 图像生成或编辑中
succeed: 任务成功完成
failed: 任务失败
处理时间
典型处理时间为 15-60 秒,具体取决于分辨率、质量、提示词复杂度,以及编辑请求中的图片数量。
最佳实践
- 明确描述构图:GPT Image 2 在提示词中清楚描述主体、构图、光线和风格时效果最佳。
- 根据流程选择质量:迭代阶段使用
low 或 medium,高质量成品使用 high。
- 按目标场景设置比例:在生成前就根据社媒、横幅、商品页或编辑排版场景确定宽高比。
- 编辑时使用清晰源图:清晰、光线良好的输入有助于人物一致性和局部编辑质量。
- 多图请求只保留强参考:对于编辑模型,只提供真正关键的参考图,避免视觉指引冲突。