EasyRouterEasyRouter
User GuideAPI DocsConnect Agent Tools
AI Model APIImagesNative OpenAI Format

Async Image Batch Generation

EasyRouter supports asynchronous image batch generation based on Vertex AI BatchPredictionJob. Compared to synchronous /v1/images/generations, asynchronous batch generation has lower prices (default 50% discount) and higher throughput.

Billing Details

  • Billing Model: Settled based on the number of successfully generated images.
  • Base Price: Same as synchronous calls.
  • Batch Discount: Default 50% off (configurable via batchRatio).
  • Pre-deduction: Pre-deducted upon submission based on requests × sync price × batchRatio.
  • Settlement: Settled upon completion based on the success ratio, with refunds for failures.
  • Logs: A pre-deduction log is written upon submission; a difference log is added only if there is a price difference upon completion.

Complete Workflow

  1. Accept Privacy Policy: Call /api/image-batch-privacy (only once per user).
  2. [Optional] Upload Reference Image: If image-to-image is needed, call /v1/image-files (purpose=vision) to get a file_id.
  3. Prepare JSONL Input File: One JSON object per line (reference the image via image_file_id if using one).
  4. Upload and Create: Call /v1/image-files (purpose=image_batch) to upload JSONL, auto-create the Batch task, and pre-deduct quota.
  5. Poll Status: Call /v1/image-batches/{batch_id} to check progress.
  6. Download Results: Call /v1/files/{file_id}/content to download the output file once completed.
PUT
/api/image-batch-privacy

Authorization

BearerAuth

AuthorizationBearer <token>

Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

In: header

Request Body

application/json

accepted?boolean

Whether to accept the privacy policy. Must be 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>

Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

In: header

Request Body

multipart/form-data

purpose*string

The intended purpose of the uploaded file. Use image_batch for JSONL batch tasks, or vision for uploading reference images.

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

The file to upload. Can be a JSONL file for batch processing or an image file for vision reference.

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>

Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

batch_id*string

The ID of the batch task to retrieve.

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>

Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

file_id*string

The ID of the output file to download.

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>

Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

In: header

Query Parameters

limit?integer

Maximum number of tasks to return per page. Default is 20.

Default20
after?string

Pagination cursor. Pass the last record ID from the previous response to get the next page.

status?string

Filter tasks by status, e.g. 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>

Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

batch_id*string

The ID of the batch task to cancel.

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>

Authenticate using a Bearer Token. Format: Authorization: Bearer sk-xxxxxx

In: header

Path Parameters

batch_id*string

The ID of the batch task to delete.

Response Body

application/json

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