Batches

Run chat completions or responses in bulk against a JSONL input file, at half the standard token price.

The Batch API runs a large set of chat completions or responses asynchronously, at half the price of the equivalent synchronous calls. It is wire-compatible with OpenAI's Batch API - point any OpenAI SDK's baseURL at https://api.aivene.com/v1 and it works out of the box.

POST /v1/batches
GET  /v1/batches
GET  /v1/batches/:batch_id
POST /v1/batches/:batch_id/cancel

Why use it

  • 50% discount - every request inside a batch is billed at half the standard token rate for that model.
  • No rate limit pressure - batches run in a separate queue, so they don't consume your regular requests-per-minute budget.
  • Built for bulk - classification, evaluation, backfills, and offline scoring jobs that don't need a response in real time.

Lifecycle

  1. Upload the input file. A batch is driven by a JSONL file where each line is one request:

    { "custom_id": "req-1", "method": "POST", "url": "/v1/chat/completions", "body": { "model": "gpt-4.1", "messages": [{ "role": "user", "content": "Hello" }] } }

    Upload it with POST /v1/files using purpose=batch:

    curl https://api.aivene.com/v1/files \
      -H "Authorization: Bearer $AIVENE_API_KEY" \
      -F "purpose=batch" \
      -F "[email protected]"

    Every line must target the same url and the same model - both are auto-detected from the file and don't need to be repeated in the batch creation request.

  2. Create the batch with POST /v1/batches, passing the file_id from step 1.

  3. Check status with GET /v1/batches/:batch_id until status is completed, failed, expired, or cancelled.

  4. Download results once output_file_id (and/or error_file_id) is set, using GET /v1/files/:file_id/content. Each line in the output file echoes the custom_id from the input so you can match responses back to requests.

  5. Cancel an in-flight batch anytime with POST /v1/batches/:batch_id/cancel.

Endpoints

MethodEndpointDescription
POST/v1/batchesCreate batch
GET/v1/batchesList batches
GET/v1/batches/:batch_idRetrieve batch
POST/v1/batches/:batch_id/cancelCancel batch

Every endpoint expects a bearer token in the Authorization header. Create keys at Manage API Keys.

Supported models

The Batch API supports these models: gpt-5.4, gpt-5.4-mini, gpt-5.1, gpt-5, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, gpt-4o, gpt-4o-mini. Any other model returns 400.

The model isn't part of the batch creation request - it's read from body.model on the first line of the input file, so every line must target the same model.

Limits

ConstraintValue
Input file formatJSONL, one request object per line
Max input file size200 MB
endpoint/v1/chat/completions or /v1/responses
completion_window24h (only supported value)
Pricing50% of the standard token rate

The batch object

FieldTypeDescription
idstringUnique batch identifier, prefixed with avn-batch_.
objectstringAlways batch.
endpointstring/v1/chat/completions or /v1/responses.
errorsobject | nullWhy the batch failed, when it did: { object: 'list', data: [{ code, message, param, line }] }. Only message is filled in; code, param, and line are null. null when there is no batch-level error.
input_file_idstringThe uploaded input file's id.
completion_windowstringAlways 24h.
statusstringOne of validating, in_progress, finalizing, completed, failed, expired, cancelling, cancelled.
output_file_idstring | nullSet once results are ready.
error_file_idstring | nullSet when one or more lines failed.
request_countsobject{ total, completed, failed }.
metadataobject | nullArbitrary string key/value pairs echoed back from creation.
created_atintegerUnix timestamp.
in_progress_atinteger | nullSet when processing starts.
finalizing_atinteger | nullSet while results are being assembled.
completed_atinteger | nullSet when status becomes completed.
failed_atinteger | nullSet when status becomes failed.
expired_atinteger | nullSet when the batch expires before completing.
cancelled_atinteger | nullSet when the batch is cancelled.
expires_atinteger | nullWhen the batch will expire if not completed.

Errors

All errors share one shape:

{ "error": { "message": "...", "type": "invalid_request_error" } }

Errors raised by the Batch API itself use type invalid_request_error for every 4xx, so branch on the HTTP status code. Only authentication and access checks that run before the request reaches the Batch API use their own types.

Statuserror.typeMeaning
400validation_errorThe create body failed schema validation (for example a missing input_file_id or an unsupported endpoint).
400invalid_request_errorUnsupported model, an invalid input file, the file's endpoint or model doesn't match the request, or an unknown after cursor when listing.
401authentication_errorMissing or invalid API key.
402invalid_request_errorCreate only: not enough credit, an unpaid balance, a spend limit was reached, or the batch's estimated cost is more than your balance plus the perks that cover the model.
403permission_denied_errorThe account is suspended, or an Admin key was used.
403invalid_request_errorThe API key isn't scoped to a workspace (Batch API requires a workspace-scoped API key).
404invalid_request_errorThe batch or input file doesn't exist, or belongs to another workspace.
500internal_server_errorUnexpected failure on our side. Try again later.
502internal_server_errorThe batch could not be submitted or read right now. Try again later.