Overview
The Batch API groups many asynchronous generation requests into a single batch. You submit the batch once, the service queues every request, dispatches them through the same relay path a direct call would use, tracks the resulting tasks, and lets you download one aggregated result file.Supported endpoints
A batch item may only target the asynchronous generation endpoints below. Any otherurl is rejected with unsupported_url.
Endpoints
All endpoints require
Authorization: Bearer <SIRAY_API_TOKEN>.
Create a batch
POST https://api.siray.ai/v1/batches
Option 1 — inline JSON
body is the exact JSON object you would have posted to that endpoint — including image inputs, data: URLs, durations, aspect ratios, and so on.
You may also post a bare array of request items (no wrapper object); it is treated as {"requests": [...]}.
Option 2 — raw JSONL
SetContent-Type: application/jsonl (or application/x-ndjson, or text/plain) and send one request item per line. Blank lines and trailing \r are ignored.
Option 3 — multipart file upload
Sendmultipart/form-data with a file part containing JSONL, plus an optional completion_window form field.
Request item fields
Top-level fields
Validation rules
Every request is validated before anything is persisted, so a single malformed item rejects the whole batch instead of producing a half-valid one.
Errors are returned in the standard shape:
Response
A successful create returns the batch object withstatus already set to in_progress:
Batch object
Batch status
Item status
queued → submitting → submitted → completed / failed. A request that is stopped before it is ever dispatched ends as cancelled.
Retrieve a batch
GET https://api.siray.ai/v1/batches/{batch_id}
status and request_counts. Polling every 3–5 seconds is a good default; a batch with long video generations will spend most of its life in in_progress.
List batches
GET https://api.siray.ai/v1/batches?limit=20&after={batch_id}
Cancel a batch
POST https://api.siray.ai/v1/batches/{batch_id}/cancel
- Queued requests are marked
cancelledimmediately and are never sent upstream. - Requests already accepted by an upstream provider cannot be recalled — the provider offers no cancel operation. Their results are still collected and returned, so you do not silently lose the quota you already paid for.
- The batch moves to
cancellingand becomescancelledonce no request can change state anymore. - The call is idempotent: cancelling a
completed,failed,expiredorcancelledbatch simply returns its current object.
Download results
Two JSONL streams are available. Both are scoped to the batch and require the same API key.Result line fields
Notes on the error stream:
- A generation that failed upstream still has a
response.body(the task status payload containingfail_code/fail_reason);error.messagemirrors that failure reason. - A request that failed before reaching a provider has
response: nulland the reason inerror.message. - If the task is finished but reading its result is rejected (any non-2xx, for example the API key was revoked or its IP allowlist changed while the batch was running), the error document is never stored as the result: the line falls back to a minimal body built from the stored task (
outputs/fail_reason) withstatus_code: 200, and the item settles on the task’s real terminal status.
Pagination
Both streams are paginated:
The response header
X-Batch-Has-More: true indicates another page exists. The Content-Disposition header suggests a filename such as batch_xxx_output.jsonl. Streaming is incremental — you can read partial results while the batch is still running.
End-to-end example
Billing
- Every batch request is a normal asynchronous generation and is charged per item at the model’s price. The batch itself is free.
- The key used for a replay is the key that gets charged. A batch replays with the key that created it; if that key is deleted, disabled, exhausted or expired, replay falls back to the oldest enabled key of the same user and key identity — so a rotated key keeps the batch collectable. Quota, group, model limits and usage-log attribution follow the fallback key; the batch itself stays owned by its creator. Tasks created by any key of the same identity count as the batch’s own result; another identity’s task is never adopted.
- Usage log entries carry
request_idvalues of the formbatch-<batch_id>-<item_id>, so a batch can be reconciled line by line. - A failing item never affects its siblings: insufficient balance, moderation rejection or an unsupported model only fails that one request.
