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
- Accept Privacy Policy: Call
/api/image-batch-privacy(only once per user). - [Optional] Upload Reference Image: If image-to-image is needed, call
/v1/image-files(purpose=vision) to get afile_id. - Prepare JSONL Input File: One JSON object per line (reference the image via
image_file_idif using one). - Upload and Create: Call
/v1/image-files(purpose=image_batch) to upload JSONL, auto-create the Batch task, and pre-deduct quota. - Poll Status: Call
/v1/image-batches/{batch_id}to check progress. - Download Results: Call
/v1/files/{file_id}/contentto download the output file once completed.
Authorization
BearerAuth
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
In: header
Request Body
application/json
Whether to accept the privacy policy. Must be 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
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
In: header
Request Body
multipart/form-data
The intended purpose of the uploaded file. Use image_batch for JSONL batch tasks, or vision for uploading reference images.
"image_batch" | "vision"The file to upload. Can be a JSONL file for batch processing or an image file for vision reference.
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
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
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"
}Authorization
BearerAuth
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
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}"Authorization
BearerAuth
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
In: header
Query Parameters
Maximum number of tasks to return per page. Default is 20.
20Pagination cursor. Pass the last record ID from the previous response to get the next page.
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
}Authorization
BearerAuth
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
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"
}Authorization
BearerAuth
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
In: header
Path Parameters
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
}