# GPT Image 2 API 由 OpenAI 提供支持的 GPT Image 2 模型完整 API 参考。 ## 模型变体 此 API 支持四个模型变体: | 模型 | ID | 说明 | |-------|-----|-------------| | **GPT Image 2** | `gpt-image-2` | 文生图 | | **GPT Image 2 Edit** | `gpt-image-2-edit` | 图片编辑与多图合成 | | **GPT Image 2 Client** | `gpt-image-2-client` | 预览版文生图,核心能力与 GPT Image 2 相同 | | **GPT Image 2 Edit Client** | `gpt-image-2-edit-client` | 预览版图片编辑与多图合成,核心能力与 GPT Image 2 Edit 相同 | ## 快速对比 | 功能 | GPT Image 2 | GPT Image 2 Edit | GPT Image 2 Client | GPT Image 2 Edit Client | |---------|-------------|------------------|--------------------|-------------------------| | 输入 | 文本提示词 | 图片 + 文本提示词 | 文本提示词 | 图片 + 文本提示词 | | 分辨率选项 | `1k`, `2k`, `4k` | `1k`, `2k`, `4k` | `1k`, `2k`, `4k` | `1k`, `2k`, `4k` | | 质量选项 | `low`, `medium`, `high` | `low`, `medium`, `high` | `low`, `medium`, `high` | `low`, `medium`, `high` | | 宽高比 | 10 种 | 10 种 | 10 种 | 10 种 | | 图片输入 | 否 | 是(1-16 张) | 否 | 是(1-16 张) | | 多图支持 | 否 | 是 | 否 | 是 | ### 支持的宽高比 `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 ``` ### 请求参数 #### 必填 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `model_name` | string | 必须为 `"gpt-image-2"` | | `prompt` | string | 图像生成提示词 | | `width` | number | 宽度比例值,例如 `16:9` 中传 `16` | | `height` | number | 高度比例值,例如 `16:9` 中传 `9` | | `resolution` | string | 输出分辨率:`"1k"`、`"2k"` 或 `"4k"` | | `quality` | string | 输出质量:`"low"`、`"medium"` 或 `"high"` | **注意:** width:height 必须是以下比例之一:`16:9`、`9:16`、`1:1`、`3:2`、`2:3`、`3:4`、`4:3`、`5:4`、`4:5`、`21:9` ### 请求示例 ```javascript 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; // Poll for results 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 ``` ### 请求参数 #### 必填 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `model_name` | string | 必须为 `"gpt-image-2-edit"` | | `prompt` | string | 需要执行的编辑描述 | | `image_url_list` | string[] | 输入图片 URL 数组(1-16 张) | #### 选填 | 参数 | 类型 | 默认值 | 说明 | |-----------|------|---------|-------------| | `width` | number | - | 宽度比例值,例如 `16:9` 中传 `16` | | `height` | number | - | 高度比例值,例如 `16:9` 中传 `9` | | `resolution` | string | `"1k"` | 输出分辨率:`"1k"`、`"2k"` 或 `"4k"` | | `quality` | string | `"medium"` | 输出质量:`"low"`、`"medium"` 或 `"high"` | **注意:** 当提供 `width` 和 `height` 时,其比例必须是以下之一:`16:9`、`9:16`、`1:1`、`3:2`、`2:3`、`3:4`、`4:3`、`5:4`、`4:5`、`21:9` ### 单图编辑示例 ```javascript { 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' } ``` ### 多图合成示例 ```javascript { 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`。这是预览体验版,稳定性可能较低。 ### 请求示例 ```javascript 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`。这是预览体验版,稳定性可能较低。 ### 请求示例 ```javascript 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`: ```json { "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}` 查看任务状态: ```json { "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 秒,具体取决于分辨率、质量、提示词复杂度,以及编辑请求中的图片数量。 ## 最佳实践 1. **明确描述构图**:GPT Image 2 在提示词中清楚描述主体、构图、光线和风格时效果最佳。 2. **根据流程选择质量**:迭代阶段使用 `low` 或 `medium`,高质量成品使用 `high`。 3. **按目标场景设置比例**:在生成前就根据社媒、横幅、商品页或编辑排版场景确定宽高比。 4. **编辑时使用清晰源图**:清晰、光线良好的输入有助于人物一致性和局部编辑质量。 5. **多图请求只保留强参考**:对于编辑模型,只提供真正关键的参考图,避免视觉指引冲突。