异步图片批量生成
EasyRouter 支持基于 Vertex AI BatchPredictionJob 的异步图片批量生成,适合大规模图片生成场景。与同步 /v1/images/generations 相比,异步批量生成具有更低的价格(默认 batch 5 折)和更高的吞吐量。
计费说明
- 计费方式:按成功生成的图片数量结算
- 基础价格:与同步调用一致
- Batch 折扣:默认 5 折(可由管理员配置
batchRatio) - 预扣费:提交时按
请求数 × 同步单价 × batchRatio预扣 - 结算:完成后按成功比例结算,多退少补
- 日志:提交时写一条预扣费日志;完成后仅在费用有差额时补充差额日志
完整工作流程
- 接受隐私政策:调用
/api/image-batch-privacy接受隐私政策(每个用户仅需一次) - [可选] 上传参考图片:如果需要图生图,调用
/v1/image-files(purpose=vision) 获取file_id - 准备 JSONL 输入文件:每行一个 JSON 对象(如果使用参考图,在 JSONL 中通过
image_file_id引用) - 上传并自动创建:调用
/v1/image-files(purpose=image_batch) 上传 JSONL,将自动创建 Batch 任务并预扣费 - 轮询状态:调用
/v1/image-batches/{batch_id}查询进度 - 下载结果:完成后调用
/v1/files/{file_id}/content下载输出文件
Authorization
BearerAuth
使用 Bearer Token 进行身份验证。
格式:Authorization: Bearer sk-xxxxxx
In: header
Request Body
application/json
是否接受隐私政策,必须为 true。
trueResponse Body
application/json
curl -X PUT "https://easyrouter.io/api/image-batch-privacy" \ -H "Content-Type: application/json" \ -d '{}'{
"success": true
}Authorization
BearerAuth
使用 Bearer Token 进行身份验证。
格式:Authorization: Bearer sk-xxxxxx
In: header
Request Body
multipart/form-data
上传文件的用途。image_batch 表示上传 JSONL 批量任务文件,vision 表示上传参考图片。
"image_batch" | "vision"要上传的文件。批量任务时为 JSONL 文件,上传参考图时为图片文件。
binaryResponse Body
application/json
curl -X POST "https://easyrouter.io/v1/image-files" \ -F purpose="image_batch" \ -F file="string"{
"id": "batch_OQiw8N2XoEraPjOjuWYu7CWT",
"object": "batch",
"status": "validating"
}Authorization
BearerAuth
使用 Bearer Token 进行身份验证。
格式:Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
要查询的 Batch 任务 ID。
Response Body
application/json
curl -X GET "https://easyrouter.io/v1/image-batches/string"{
"id": "string",
"object": "string",
"status": "completed",
"output_file_id": "file_HhV64GDHhj3cqBFhDmX1KpZz"
}Authorization
BearerAuth
使用 Bearer Token 进行身份验证。
格式:Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
要下载的输出文件 ID。
Response Body
text/plain
curl -X GET "https://easyrouter.io/v1/files/string/content""{\"id\":\"batch_req_0\",\"custom_id\":\"req-1\",\"response\":{\"status_code\":200,\"request_id\":\"vertex_batch_req_0\",\"body\":{\"data\":[{\"b64_json\":\"...base64 image data...\"}]}},\"error\":null}"Authorization
BearerAuth
使用 Bearer Token 进行身份验证。
格式:Authorization: Bearer sk-xxxxxx
In: header
Query Parameters
每页返回的任务数量,默认为 20。
20分页游标,传入上一页响应中的最后一条记录 ID,用于获取下一页数据。
按任务状态筛选,例如 completed。
Response Body
application/json
curl -X GET "https://easyrouter.io/v1/image-batches"{
"object": "list",
"data": [
{}
],
"first_id": "string",
"last_id": "string",
"has_more": true
}Authorization
BearerAuth
使用 Bearer Token 进行身份验证。
格式:Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
要取消的 Batch 任务 ID。
Response Body
application/json
curl -X POST "https://easyrouter.io/v1/image-batches/string/cancel"{
"id": "string",
"status": "cancelling"
}Authorization
BearerAuth
使用 Bearer Token 进行身份验证。
格式:Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
要删除的 Batch 任务 ID。
Response Body
application/json
curl -X DELETE "https://easyrouter.io/v1/image-batches/string"{
"id": "batch_OQiw8N2XoEraPjOjuWYu7CWT",
"object": "batch.deleted",
"deleted": true
}