图生图

上传原图,按提示词编辑、改色或调整风格。

MethodPOST
Endpoint/v1/images/edits
Content-Typemultipart/form-data

Base URL:https://zsmfai.top · 鉴权:Authorization: Bearer sk-你的Key

接口说明

图生图 / 图片编辑接口,支持上传原图和可选蒙版。推荐使用 multipart/form-data;也支持 JSON 中传 Base64 Data URL 或 HTTPS 图片 URL。

请求方式image 字段适用场景
multipart/form-data文件上传本地图片、大图,推荐
application/jsonData URL / HTTPS URL服务端已有图片地址或 Base64

请求参数

参数类型默认值 / 可选值说明
image必填file / stringPNG / JPEG / WebP原图。multipart 传文件;JSON 传 Data URL 或可访问 HTTPS URL。多图时可重复传 image,最多 5 张。
maskfile / string可选蒙版:透明区域可编辑,不透明区域保留原图;必须同时提供原图。
model必填string例如 gpt-image-2.6编辑模型 ID,见模型列表。
prompt必填string—编辑要求,例如“把杯子改成蓝色,其他保持不变”。
ninteger默认 1;常用 1–4生成数量。
sizestring1024x1024
1536x1024
1024x1536
3840x2160 · 4K
2160x3840 · 4K
输出尺寸;实际像素以响应为准。
response_formatstringb64_json / url
默认 b64_json
推荐 b64_json。
output_formatstringpng / jpeg / webp输出格式,取决于上游。
qualitystringauto / low / medium / high质量档位。
userstring可选调用方用户标识。

响应字段

与文生图相同,返回 created 和 data 数组;每项包含 b64_json 或 url。

字段类型说明
createdintegerUnix 时间戳。
dataarray编辑结果数组。
data[].b64_jsonstringBase64 图片。
data[].urlstring图片 URL(可能有时效)。

请求示例

快速调用

curl · 快速调用
curl https://zsmfai.top/v1/images/edits \
  -H "Authorization: Bearer sk-你的Key" \
  -F "model=gpt-image-2.6" \
  -F "prompt=把杯子改成蓝色,保持白色背景" \
  -F "image=@input.png"

蒙版编辑

透明区域表示可编辑范围,不透明区域保留原图:

curl · mask
curl https://zsmfai.top/v1/images/edits \
  -H "Authorization: Bearer sk-你的Key" \
  -F "model=gpt-image-2.6" \
  -F "prompt=只把蝙蝠改成红色,其他内容保持不变" \
  -F "size=1024x1024" \
  -F "image=@source.png" \
  -F "mask=@mask.png" \
  -F "response_format=b64_json"

多图参考

需要参考多张图片时重复传 image 字段:

curl · 多图
curl https://zsmfai.top/v1/images/edits \
  -H "Authorization: Bearer sk-你的Key" \
  -F "model=gpt-image-2.6" \
  -F "prompt=保持主体不变,融合第二张图的配色和风格" \
  -F "image=@subject.png" \
  -F "image=@style.png" \
  -F "size=1024x1024" \
  -F "response_format=b64_json"

4K 编辑

curl · 3840x2160
curl https://zsmfai.top/v1/images/edits \
  -H "Authorization: Bearer sk-你的Key" \
  -F "model=gpt-image-2.6" \
  -F "prompt=保持主体不变,把背景改成雪山" \
  -F "image=@source.png" \
  -F "size=3840x2160" \
  -F "response_format=b64_json"

JSON 与 Python

JSON · Base64
curl https://zsmfai.top/v1/images/edits \
  -H "Authorization: Bearer sk-你的Key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.6",
    "prompt": "把杯子改成蓝色,保持白色背景和其他物体不变",
    "image": "data:image/png;base64,",
    "mask": "data:image/png;base64,",
    "size": "1024x1024",
    "response_format": "b64_json"
  }'
Python
import base64, requests

url = "https://zsmfai.top/v1/images/edits"
headers = {"Authorization": "Bearer sk-你的Key"}
data = {
    "model": "gpt-image-2.6",
    "prompt": "把杯子改成蓝色,保持白色背景和其他物体不变",
    "size": "1024x1024",
    "response_format": "b64_json",
}
with open("input.png", "rb") as f:
    r = requests.post(url, headers=headers, data=data,
                      files={"image": ("input.png", f, "image/png")}, timeout=180)
r.raise_for_status()
open("output.png", "wb").write(base64.b64decode(r.json()["data"][0]["b64_json"]))

限制与注意事项

常见错误

状态码常见原因处理方式
400缺少 image、文件格式不支持、参数冲突检查图片字段、格式和必填参数
401/403Key 无效、分组无权限确认 Key 和 gpt-image 分组
413上传文件过大压缩图片或降低分辨率后重试
500/502上游编辑失败或超时换模型或稍后重试
Esc