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/cancelWhy 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
-
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/filesusingpurpose=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
urland the samemodel- both are auto-detected from the file and don't need to be repeated in the batch creation request. -
Create the batch with
POST /v1/batches, passing thefile_idfrom step 1. -
Check status with
GET /v1/batches/:batch_iduntilstatusiscompleted,failed,expired, orcancelled. -
Download results once
output_file_id(and/orerror_file_id) is set, usingGET /v1/files/:file_id/content. Each line in the output file echoes thecustom_idfrom the input so you can match responses back to requests. -
Cancel an in-flight batch anytime with
POST /v1/batches/:batch_id/cancel.
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/batches | Create batch |
| GET | /v1/batches | List batches |
| GET | /v1/batches/:batch_id | Retrieve batch |
| POST | /v1/batches/:batch_id/cancel | Cancel 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
| Constraint | Value |
|---|---|
| Input file format | JSONL, one request object per line |
| Max input file size | 200 MB |
endpoint | /v1/chat/completions or /v1/responses |
completion_window | 24h (only supported value) |
| Pricing | 50% of the standard token rate |
The batch object
| Field | Type | Description |
|---|---|---|
id | string | Unique batch identifier, prefixed with avn-batch_. |
object | string | Always batch. |
endpoint | string | /v1/chat/completions or /v1/responses. |
errors | object | null | Why 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_id | string | The uploaded input file's id. |
completion_window | string | Always 24h. |
status | string | One of validating, in_progress, finalizing, completed, failed, expired, cancelling, cancelled. |
output_file_id | string | null | Set once results are ready. |
error_file_id | string | null | Set when one or more lines failed. |
request_counts | object | { total, completed, failed }. |
metadata | object | null | Arbitrary string key/value pairs echoed back from creation. |
created_at | integer | Unix timestamp. |
in_progress_at | integer | null | Set when processing starts. |
finalizing_at | integer | null | Set while results are being assembled. |
completed_at | integer | null | Set when status becomes completed. |
failed_at | integer | null | Set when status becomes failed. |
expired_at | integer | null | Set when the batch expires before completing. |
cancelled_at | integer | null | Set when the batch is cancelled. |
expires_at | integer | null | When 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.
| Status | error.type | Meaning |
|---|---|---|
400 | validation_error | The create body failed schema validation (for example a missing input_file_id or an unsupported endpoint). |
400 | invalid_request_error | Unsupported model, an invalid input file, the file's endpoint or model doesn't match the request, or an unknown after cursor when listing. |
401 | authentication_error | Missing or invalid API key. |
402 | invalid_request_error | Create 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. |
403 | permission_denied_error | The account is suspended, or an Admin key was used. |
403 | invalid_request_error | The API key isn't scoped to a workspace (Batch API requires a workspace-scoped API key). |
404 | invalid_request_error | The batch or input file doesn't exist, or belongs to another workspace. |
500 | internal_server_error | Unexpected failure on our side. Try again later. |
502 | internal_server_error | The batch could not be submitted or read right now. Try again later. |