OpenAI 编辑图片
/v1/images/edits 是 OpenAI Images API 兼容的同步图片编辑接口。它和图片生成接口使用相同的平台限制、分组权限、内容风控、并发与余额校验。
接口说明
| 项目 | 值 |
|---|---|
| Method | POST |
| Path | /v1/images/edits |
| Content-Type | multipart/form-data 或 application/json |
| 认证 | Authorization: Bearer YOUR_API_KEY |
| 平台要求 | OpenAI 平台分组,且分组启用生图能力 |
Multipart 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 否 | 图片模型,默认 gpt-image-2。 |
prompt | string | 是 | 编辑指令。 |
image | file | 是 | 输入图片。多个图片可使用多个 image 字段或 image[]。 |
mask | file | 否 | 蒙版图片。 |
size | string | 否 | 输出尺寸。 |
n | integer | 否 | 生成图片数量。 |
response_format | string | 否 | 响应格式。 |
input_fidelity | string | 否 | OpenAI 原生编辑参数,按上游能力透传。 |
JSON 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 否 | 图片模型,默认 gpt-image-2。 |
prompt | string | 是 | 编辑指令。 |
images | array | 是 | 每项支持 { "image_url": "https://..." }。file_id 当前不支持。 |
mask.image_url | string | 否 | 蒙版图片 URL。mask.file_id 当前不支持。 |
size | string | 否 | 输出尺寸。 |
n | integer | 否 | 生成图片数量。 |
Multipart 示例
bash
curl https://llmapi.site/v1/images/edits \
-H 'Authorization: Bearer YOUR_API_KEY' \
-F 'model=gpt-image-2' \
-F 'image=@input.png' \
-F 'prompt=change the background to a clean studio setting' \
-F 'size=1024x1024'JSON 示例
bash
curl https://llmapi.site/v1/images/edits \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-image-2",
"prompt": "replace the background with a bright studio",
"images": [
{ "image_url": "https://example.com/input.png" }
],
"size": "1024x1024"
}'常见错误
| 错误 | 说明 |
|---|---|
Images API is not supported for this platform | 当前 Key 分组不是 OpenAI 平台。 |
images[].image_url is required | JSON 编辑请求缺少输入图片 URL。 |
images[].file_id is not supported | 当前 JSON 编辑请求不支持 file_id。 |
image file is required | Multipart 编辑请求缺少图片文件。 |