EasyRouterEasyRouter
使用指南API 文档接入 Agent 工具
AI 模型接口图像(Images)OpenAI 格式

异步图片批量生成

EasyRouter 支持基于 Vertex AI BatchPredictionJob 的异步图片批量生成,适合大规模图片生成场景。与同步 /v1/images/generations 相比,异步批量生成具有更低的价格(默认 batch 5 折)和更高的吞吐量

计费说明

  • 计费方式:按成功生成的图片数量结算
  • 基础价格:与同步调用一致
  • Batch 折扣默认 5 折(可由管理员配置 batchRatio
  • 预扣费:提交时按 请求数 × 同步单价 × batchRatio 预扣
  • 结算:完成后按成功比例结算,多退少补
  • 日志:提交时写一条预扣费日志;完成后仅在费用有差额时补充差额日志

完整工作流程

  1. 接受隐私政策:调用 /api/image-batch-privacy 接受隐私政策(每个用户仅需一次)
  2. [可选] 上传参考图片:如果需要图生图,调用 /v1/image-files (purpose=vision) 获取 file_id
  3. 准备 JSONL 输入文件:每行一个 JSON 对象(如果使用参考图,在 JSONL 中通过 image_file_id 引用)
  4. 上传并自动创建:调用 /v1/image-files (purpose=image_batch) 上传 JSONL,将自动创建 Batch 任务并预扣费
  5. 轮询状态:调用 /v1/image-batches/{batch_id} 查询进度
  6. 下载结果:完成后调用 /v1/files/{file_id}/content 下载输出文件
PUT
/api/image-batch-privacy

Authorization

BearerAuth

AuthorizationBearer <token>

使用 Bearer Token 进行身份验证。 格式:Authorization: Bearer sk-xxxxxx

In: header

Request Body

application/json

accepted?boolean

是否接受隐私政策,必须为 true。

Defaulttrue

Response Body

application/json

curl -X PUT "https://easyrouter.io/api/image-batch-privacy" \  -H "Content-Type: application/json" \  -d '{}'
{
  "success": true
}
POST
/v1/image-files

Authorization

BearerAuth

AuthorizationBearer <token>

使用 Bearer Token 进行身份验证。 格式:Authorization: Bearer sk-xxxxxx

In: header

Request Body

multipart/form-data

purpose*string

上传文件的用途。image_batch 表示上传 JSONL 批量任务文件,vision 表示上传参考图片。

Value in"image_batch" | "vision"
file*file

要上传的文件。批量任务时为 JSONL 文件,上传参考图时为图片文件。

Formatbinary

Response 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"
}
GET
/v1/image-batches/{batch_id}

Authorization

BearerAuth

AuthorizationBearer <token>

使用 Bearer Token 进行身份验证。 格式:Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

batch_id*string

要查询的 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"
}
GET
/v1/files/{file_id}/content

Authorization

BearerAuth

AuthorizationBearer <token>

使用 Bearer Token 进行身份验证。 格式:Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

file_id*string

要下载的输出文件 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}"
GET
/v1/image-batches

Authorization

BearerAuth

AuthorizationBearer <token>

使用 Bearer Token 进行身份验证。 格式:Authorization: Bearer sk-xxxxxx

In: header

Query Parameters

limit?integer

每页返回的任务数量,默认为 20。

Default20
after?string

分页游标,传入上一页响应中的最后一条记录 ID,用于获取下一页数据。

status?string

按任务状态筛选,例如 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
}
POST
/v1/image-batches/{batch_id}/cancel

Authorization

BearerAuth

AuthorizationBearer <token>

使用 Bearer Token 进行身份验证。 格式:Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

batch_id*string

要取消的 Batch 任务 ID。

Response Body

application/json

curl -X POST "https://easyrouter.io/v1/image-batches/string/cancel"
{
  "id": "string",
  "status": "cancelling"
}
DELETE
/v1/image-batches/{batch_id}

Authorization

BearerAuth

AuthorizationBearer <token>

使用 Bearer Token 进行身份验证。 格式:Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

batch_id*string

要删除的 Batch 任务 ID。

Response Body

application/json

curl -X DELETE "https://easyrouter.io/v1/image-batches/string"
{
  "id": "batch_OQiw8N2XoEraPjOjuWYu7CWT",
  "object": "batch.deleted",
  "deleted": true
}