Skip to content
OpenRelay is in early access, and the /v1 API is stable. New capabilities ship in the changelog.
Inference APIBatch API

Batches

Create, get, list, and cancel batches. The batch object, inline vs file input, the status lifecycle, and pagination.

A batch runs a set of inference requests asynchronously against one endpoint. You create it from an uploaded file or from inline requests, poll it to a terminal status, then download its result files.

The batch object

FieldTypeDescription
idstringThe batch id (batch_…).
objectstringAlways "batch".
endpointstringThe endpoint the requests target, e.g. /v1/chat/completions.
input_file_idstringThe input file the batch runs. For inline requests, an input file the gateway synthesized from them.
completion_windowstringAlways "24h".
statusstringThe lifecycle status. See Status lifecycle.
modelstringThe model id, once known.
output_file_idstringPresent when there are successful results (the file of response lines).
error_file_idstringPresent when there are failed results (the file of error lines).
created_atintegerUnix seconds when the batch was submitted.
expires_atintegerUnix seconds when the 24-hour window ends.
completed_at / failed_at / expired_at / cancelled_atintegerUnix seconds the batch reached that terminal status (whichever applies).
request_countsobject{ total, completed, failed }, updated as work progresses.
usageobjectRolled-up { input_tokens, output_tokens, cost_nano_usd }. Present once non-zero. cost_nano_usd is the customer price in nanodollars (1e-9 USD), with the batch discount already applied.
metadataobjectThe string-to-string map you attached at creation.

Create a batch

POST https://inference.openrelay.inc/v1/batches
FieldTypeDescription
input_file_idstringThe id of an uploaded purpose: "batch" file. Provide either this or requests, not both.
requestsarrayInline request objects (the same shape as input file lines). The gateway stores them as a synthesized input file. Provide either this or input_file_id.
endpointstring (required)One of /v1/chat/completions or /v1/completions.
completion_windowstring (required)Must be "24h".
modelstringOptional hint so the batch shows a model id immediately. The authoritative value is read from the input file when the batch validates.
metadataobjectOptional string-to-string map, echoed back on the batch.

Creating a batch returns it at status validating with zeroed request_counts; the real counts settle once the input file is validated.

curl https://inference.openrelay.inc/v1/batches \
  -H "Authorization: Bearer $OPENRELAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input_file_id": "file-a1b2c3d4e5f6a7b8c9d0e1f2",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h",
    "metadata": { "job": "nightly-summaries" }
  }'
{
  "id": "batch_9f8e7d6c5b4a",
  "object": "batch",
  "endpoint": "/v1/chat/completions",
  "input_file_id": "file-a1b2c3d4e5f6a7b8c9d0e1f2",
  "completion_window": "24h",
  "status": "validating",
  "created_at": 1752460801,
  "expires_at": 1752547201,
  "request_counts": { "total": 0, "completed": 0, "failed": 0 },
  "metadata": { "job": "nightly-summaries" }
}

CLI: orl batches create --input-file-id file-a1b2c3d4e5f6a7b8c9d0e1f2 --endpoint /v1/chat/completions (or --input-file requests.jsonl to upload and create in one command; completion-window defaults to 24h).

Inline requests

For small jobs, skip the upload and pass requests inline. Each element is one request object, the same shape as an input file line:

curl https://inference.openrelay.inc/v1/batches \
  -H "Authorization: Bearer $OPENRELAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h",
    "requests": [
      {"custom_id": "req-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "openrelay/gpt-oss-120b", "messages": [{"role": "user", "content": "Name three primary colors."}]}}
    ]
  }'

Provide exactly one of input_file_id or requests: sending both, or neither, returns 400. Inline requests are capped at 50,000 records like an uploaded file.

Get a batch

GET https://inference.openrelay.inc/v1/batches/{id}
curl https://inference.openrelay.inc/v1/batches/batch_9f8e7d6c5b4a \
  -H "Authorization: Bearer $OPENRELAY_API_KEY"

Returns the batch object, or 404 if the id is unknown to your organization. Poll this until status is terminal. CLI: orl batches get batch_9f8e7d6c5b4a.

List batches

GET https://inference.openrelay.inc/v1/batches?limit=20&after=batch_9f8e7d6c5b4a

Returns your batches newest first.

QueryDescription
limitPage size, 1 to 100. Defaults to 20.
afterA batch id to page after (the last_id of the previous page).
{
  "object": "list",
  "data": [ { "id": "batch_9f8e7d6c5b4a", "object": "batch", "status": "completed", "…": "…" } ],
  "first_id": "batch_9f8e7d6c5b4a",
  "last_id": "batch_9f8e7d6c5b4a",
  "has_more": false
}

To page, pass the previous response's last_id as after; stop when has_more is false. CLI: orl batches list --limit 20 --after batch_9f8e7d6c5b4a.

Cancel a batch

POST https://inference.openrelay.inc/v1/batches/{id}/cancel

Cancels a batch that is still running. In-flight requests finish, unstarted requests are not started, partial results are written, and the batch settles to cancelled within a few minutes. The response echoes the batch with status cancelling.

curl https://inference.openrelay.inc/v1/batches/batch_9f8e7d6c5b4a/cancel \
  -H "Authorization: Bearer $OPENRELAY_API_KEY" \
  -X POST

Cancelling a batch that has already reached a terminal status returns 409. CLI: orl batches cancel batch_9f8e7d6c5b4a.

Status lifecycle

A batch moves through these statuses, matching the OpenAI Batch API exactly:

StatusMeaning
validatingThe input file is being checked before the run starts.
in_progressRequests are being run.
finalizingThe run finished; the result files are being assembled.
completedDone. output_file_id (and error_file_id, if any) are ready.
failedThe batch could not run, for example an unreadable or over-limit input file.
expiredThe 24-hour window elapsed before the batch finished. Completed work is kept and billed; unfinished requests are written to the error file with code: "batch_expired".
cancellingA cancel was requested; the batch is winding down.
cancelledThe batch was cancelled.

completed, failed, expired, and cancelled are terminal.

On this page