OpenAI
创建图像编辑
在 CometAPI 中使用 POST /v1/images/edits 通过 multipart 上传、mask、GPT 图像模型和编码图像输出控制来编辑图像。
POST
/
v1
/
images
/
edits
curl https://api.cometapi.com/v1/images/edits \
-H "Authorization: Bearer $COMETAPI_KEY" \
-F image=@cat.jpg \
-F prompt="Add a small red bow tie on the cat" \
-F model=gpt-image-2 \
-F quality=low{
"created": 1781075000,
"background": "opaque",
"output_format": "png",
"quality": "low",
"size": "1024x1024",
"usage": {
"input_tokens": 784,
"input_tokens_details": {
"image_tokens": 768,
"text_tokens": 16
},
"output_tokens": 196,
"output_tokens_details": {
"image_tokens": 196,
"text_tokens": 0
},
"total_tokens": 980
},
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}使用此路由可在 CometAPI 上通过 OpenAI 兼容的 multipart 上传来编辑现有图像。
在以下情况使用此路由
- 你已经有一张源图像,并希望基于 prompt 进行编辑
- 你可能需要使用 mask 来进行定向修改
- 你可以处理 multipart 文件上传,而不是纯 JSON 请求
安全的首次请求
- 从一个 PNG 或 JPG 文件开始
- 在基础编辑流程跑通之前先跳过 mask
- 在此路由上发起 GPT 图像编辑请求时,使用
model: "gpt-image-2" - 使用一条简短指令,只要求一个可见变化
- 从
data[0].b64_json读取编辑后的结果 - 当你需要 JPEG 负载时,设置
output_format: "jpeg" - 预期会比普通图像生成有更长的延迟
模型行为
- 此路由上的 GPT 图像编辑模型会返回内联的 base64 图像数据
output_format控制b64_json中编码图像的类型response_format仅在模型支持 URL 输出时才有意义qwen-image-edit在同一个 CometAPI 路由后遵循提供商特定的编辑行为
请求体
multipart/form-data
响应
200 - application/json
Edited image result.
最后修改于 2026年6月23日
⌘I
curl https://api.cometapi.com/v1/images/edits \
-H "Authorization: Bearer $COMETAPI_KEY" \
-F image=@cat.jpg \
-F prompt="Add a small red bow tie on the cat" \
-F model=gpt-image-2 \
-F quality=low{
"created": 1781075000,
"background": "opaque",
"output_format": "png",
"quality": "low",
"size": "1024x1024",
"usage": {
"input_tokens": 784,
"input_tokens_details": {
"image_tokens": 768,
"text_tokens": 16
},
"output_tokens": 196,
"output_tokens_details": {
"image_tokens": 196,
"text_tokens": 0
},
"total_tokens": 980
},
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}