请求参数
Authorizationstring必填Bearer sk-zerofa-xxxContent-Typestring必填application/jsonmodelstring必填your-image-model-idpromptstring必填一只戴宇航头盔的柴犬,扁平插画imagestring | string[]可选https://.../reference.pngimagesstring[] | object[]可选["https://.../a.png","https://.../b.png"]ninteger可选1sizestring可选1024x1024qualitystring可选highresponse_formatstring可选urloutput_formatstring可选webpbackgroundstring可选transparentstreamboolean可选truepartial_imagesinteger可选2宽高必须为 16 的倍数,长边不超过 3840,长短边比不超过 3:1,总像素为 655,360–8,294,400。竖版可交换宽高。
| 比例 | 1K | 2K | 4K |
|---|---|---|---|
| 1:1 | 1024x1024 | 2048x2048 | 2880x2880 |
| 4:3 | 1360x1024 | 2048x1536 | 3312x2480 |
| 3:2 | 1536x1024 | 2048x1360 | 3504x2336 |
| 16:9 | 1824x1024 | 2048x1152 | 3840x2160 |
| 21:9 | 2384x1024 | 2048x880 | 3840x1648 |
图生图与多参考图(本站 / new-api 通用)
在 /v1/images/generations 的文生图请求上增加 image 或 images 即可切换到参考生图。多图统一推荐使用 images;该 JSON 结构可直接调用本站,也可经 OpenAI 兼容的 new-api 渠道转发。
curl https://zerofa.ai/v1/images/generations \
-H "Authorization: Bearer sk-zerofa-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "your-image-model-id",
"prompt": "融合人物、服装和场景参考,生成一张电影海报",
"images": [
"https://example.com/person.png",
"https://example.com/outfit.png",
"data:image/png;base64,..."
],
"size": "2048x2048",
"response_format": "url"
}'响应
data 数组中的每项代表一张图片,包含 url 或 b64_json,取决于 response_format。url 为临时链接,需要长期保存时请及时下载。
图像编辑(图生图)
/v1/images/edits通过 multipart/form-data 上传参考图并提供 prompt。除 OpenAI 标准 mask 外,还支持 bbox_list=[[[x1,y1,x2,y2]], ...] 矩形区域扩展:每个外层元素对应一张输入图,坐标为原图绝对像素,每张图最多两个框,mask 与 bbox_list 不能同时使用。OpenAI 路由会将首图坐标转换为 Mask,Wan 2.7 原生使用 bbox_list;不支持区域编辑的模型会明确报错。输出尺寸由上游决定,可能与请求 size 不完全一致。
curl https://zerofa.ai/v1/images/edits \
-H "Authorization: Bearer sk-zerofa-xxx" \
-F "model=your-image-model-id" \
-F "prompt=把背景换成夜晚的星空" \
-F "size=1024x1024" \
-F "image=@source.png;type=image/png"
# 精确矩形区域编辑:bbox_list 按 image/image[] 的顺序对齐
curl https://zerofa.ai/v1/images/edits \
-H "Authorization: Bearer sk-zerofa-xxx" \
-F "model=wan2.7-image-pro" \
-F "prompt=替换框选区域内的物体" \
-F "image=@source.png;type=image/png" \
-F 'bbox_list=[[[120,80,640,720]]]'curl https://zerofa.ai/v1/images/edits \
-H "Authorization: Bearer sk-zerofa-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "your-image-model-id",
"prompt": "融合两张参考图的构图和材质",
"images": [
{"image_url": "https://example.com/reference-1.png"},
{"image_url": "data:image/png;base64,..."}
],
"input_fidelity": "high",
"output_format": "webp",
"response_format": "url"
}'流式图片响应
stream=true 返回 OpenAI Images 标准 SSE 事件。统一路由会始终返回 image_generation.completed 或 image_edit.completed;partial_image 事件取决于供给链路能力,不保证出现。
curl -N https://zerofa.ai/v1/images/generations \
-H "Authorization: Bearer sk-zerofa-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "your-image-model-id",
"prompt": "一只戴宇航头盔的柴犬,扁平插画",
"stream": true,
"partial_images": 2
}'
# 终态事件:event: image_generation.completed
# data: {"type":"image_generation.completed","b64_json":"..."}OpenAI 编辑接口工具模型
同一个 POST /v1/images/edits 也可调用抠图和图片超分。使用 background-removal-1 输出透明 PNG;使用 image-upscale、image-upscale-2x 或 image-upscale-4x 执行超分。
# Background removal
curl https://zerofa.ai/v1/images/edits \
-H "Authorization: Bearer sk-zerofa-xxx" \
-F "model=background-removal-1" \
-F "prompt=Remove the background and preserve the subject" \
-F "image=@source.png;type=image/png"
# Image upscale: size > long_side/short_side > scale > default 2x
curl https://zerofa.ai/v1/images/edits \
-H "Authorization: Bearer sk-zerofa-xxx" \
-F "model=image-upscale" \
-F "prompt=Upscale while preserving all details" \
-F "image=@source.png;type=image/png" \
-F "size=2048x1536" \
-F "response_format=url"异步生成
除同步生成外,也可以提交异步图片任务并轮询结果。
/v1/images/generations/tasks提交任务时不扣费。Body 与 /v1/images/generations 一致,并立即返回 id 和 submitted 状态。
curl https://zerofa.ai/v1/images/generations/tasks \
-H "Authorization: Bearer sk-zerofa-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "your-image-model-id",
"prompt": "一只戴宇航头盔的柴犬,扁平插画",
"size": "3840x2160"
}'
# → {"id":"<task-id>","model":"your-image-model-id","status":"submitted"}/v1/images/generations/tasks/{id}每隔几秒轮询任务,直到 succeeded 或 failed。成功时返回 OpenAI 风格 data;首次成功结果按实际张数扣费,重复轮询不会重复扣款。失败或超时不扣费,临时图片 URL 请及时下载。
curl https://zerofa.ai/v1/images/generations/tasks/<task-id> \
-H "Authorization: Bearer sk-zerofa-xxx"
# running → {"id":"...","status":"running"}
# succeeded → {"id":"...","status":"succeeded",
# "data":[{"url":"https://.../4k.png"}]}可用模型
文生图模型见 模型广场 并筛选图像类型。价格根据 model、size 和计费方式变化。
请求与响应体
用下面的示例确认请求格式与返回结构。需要在线发起请求时,点击页面顶部“调试”拉起在线运行面板。
curl https://zerofa.ai/v1/images/generations \
-H "Authorization: Bearer sk-zerofa-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "your-image-model-id",
"prompt": "一只戴宇航头盔的柴犬,扁平插画",
"n": 1,
"size": "1024x1024",
"response_format": "url"
}'{
"created": 1715961234,
"data": [
{ "url": "https://.../generated.png" }
]
}