Skip to content

OpenAI 编辑图片

/v1/images/edits 是 OpenAI Images API 兼容的同步图片编辑接口。普通 API Key 走同步图片网关;任务 API Key 使用任务 API 的模型和价格配置,并同步等待编辑结果。

接口说明

项目
MethodPOST
Path/v1/images/edits,也支持 /images/edits
Content-Typemultipart/form-dataapplication/json
认证Authorization: Bearer YOUR_API_KEY
普通 API Key需要 OpenAI 平台分组,且分组启用生图能力
任务 API Key使用任务 API 的模型和计费配置

使用任务 API Key 时,本接口最多同步等待 120 秒。如果等待超时且响应包含 task_id,请使用任务 API 查询最终状态。

Multipart 参数

参数类型必填说明
modelstring图片模型,默认 gpt-image-2。普通 API Key 需使用 OpenAI Images 兼容模型;任务 API Key 可使用任务 API 模型列表中的图片模型。
promptstring编辑指令。
imagefile输入图片。多个图片可使用多个 image 字段或 image[]
maskfile蒙版图片。
sizestring输出尺寸。
ninteger生成图片数量。
response_formatstring响应格式。
input_fidelitystringOpenAI Images API 编辑参数,是否生效取决于所选模型。

JSON 参数

参数类型必填说明
modelstring图片模型,默认 gpt-image-2。普通 API Key 需使用 OpenAI Images 兼容模型;任务 API Key 可使用任务 API 模型列表中的图片模型。
promptstring编辑指令。
imagesarray每项支持 { "image_url": "https://..." }file_id 当前不支持。
mask.image_urlstring蒙版图片 URL。mask.file_id 当前不支持。
sizestring输出尺寸。
ninteger生成图片数量。

使用 JSON 请求时,图片 URL 需要能被服务端访问;如果图片只在客户端本地,请使用 multipart 上传。

Multipart 示例

bash
curl https://api.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://api.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"
  }'

响应 — 200 OK

json
{
  "created": 1779912000,
  "data": [
    {
      "b64_json": "..."
    }
  ]
}
字段说明
created响应创建时间,Unix 时间戳。
data[].b64_jsonresponse_formatb64_json 时返回的编辑后图片 Base64。
data[].url当 URL 响应可用时返回的编辑后图片地址。

错误码

状态码原因
400请求体无效、缺少图片文件或 images[].image_url,或使用了 file_id 等不支持字段。
401API Key 缺失或无效。
403余额、额度或分组权限校验失败。
404当前 API Key 分组不能调用 OpenAI Images API。
429达到频率限制或并发限制。
504任务 API Key 同步等待超时;如果后续可查询最终状态,响应会包含 task_id
500 / 502 / 503网关或上游服务商失败。