Skip to main content

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.
Batches are designed for throughput, not for latency. A batch item starts within a few seconds of submission, but total wall-clock time is bounded by the slowest generation in the batch and by the concurrency throttle.

Supported endpoints

A batch item may only target the asynchronous generation endpoints below. Any other url is rejected with unsupported_url.

Endpoints

All endpoints require Authorization: Bearer <SIRAY_API_TOKEN>.

Create a batch

  • POST https://api.siray.ai/v1/batches
The create endpoint accepts three input shapes; pick whichever fits your client.

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

Set Content-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

Send multipart/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 with status 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}
Returns the same batch object shown above with refreshed 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}
Pages are ordered newest-first.

Cancel a batch

  • POST https://api.siray.ai/v1/batches/{batch_id}/cancel
Behaviour:
  • Queued requests are marked cancelled immediately 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 cancelling and becomes cancelled once no request can change state anymore.
  • The call is idempotent: cancelling a completed, failed, expired or cancelled batch simply returns its current object.

Download results

Two JSONL streams are available. Both are scoped to the batch and require the same API key.
Each line is one result:

Result line fields

Notes on the error stream:
  • A generation that failed upstream still has a response.body (the task status payload containing fail_code / fail_reason); error.message mirrors that failure reason.
  • A request that failed before reaching a provider has response: null and the reason in error.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) with status_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_id values of the form batch-<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.

Errors