Batches API
Create a batch from an uploaded input file, query its progress and cancel it. Creating a batch immediately returns a batch object in the
validatingstate; execution happens asynchronously in the background, and callers poll the batch details to track progress.For the batch object fields, batch statuses and result file format, see API Overview · Output Data Objects.
Permission scope
Batches are isolated strictly by API Key: only the API Key that created a batch can query or cancel it, and GET /v1/batches returns only the batches of the current API Key. Access from any other API Key returns 404 batch_not_found (including other API Keys under the same account or the same enterprise). See API Overview · Data Visibility.
Create a Batch
Endpoint
POST /v1/batchesRequest Headers
| Parameter | Type | Required | Description |
|---|---|---|---|
Authorization | string | Yes | Bearer <api-key> |
Content-Type | string | Yes | application/json |
Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
input_file_id | string | Yes | Identifier of an uploaded purpose=batch file |
endpoint | string | Yes | Batch endpoint; currently only /v1/chat/completions is supported |
completion_window | string | No | Completion window; only 24h is accepted (treated as 24h when omitted) |
metadata | object<string,string> | No | Custom key-value pairs: at most 16 keys, each key ≤64 characters, values must be strings ≤512 characters |
Synchronous validations performed when creating a batch (creation is rejected with the corresponding error if any of them fails):
- The file exists, belongs to the current API Key, and has
purpose=batch; - Every row is a valid JSON object containing
custom_id(non-empty, ≤256 characters, unique within the batch),method(empty orPOST),urlandbody; - All rows share the same
url, equal to theendpointused when creating the batch; - All rows have a
body.modelthat exists and is identical (a batch can only use one model); - Row-level
metadatasatisfies the same limits as themetadataof the batch creation request; - The current API Key is entitled to use the models in the file (otherwise
403 model_access_denied); - The current balance is sufficient to pay for this batch (otherwise
402 insufficient_quota); - The submission limits of the current API Key are not exceeded (otherwise
429 batch_limit_exceeded).
Request Example
curl --request POST \
--url 'https://neolink.com/api/v1/batches' \
--header 'Authorization: Bearer <api-key>' \
--header 'Content-Type: application/json' \
--data '{
"input_file_id": "file-51428aca4e0a47808012aaa03d1734ff",
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
"metadata": {
"job": "nightly"
}
}'Success Response
{
"id": "batch-63c583173a0a472bb8d3e48207041690",
"object": "batch",
"endpoint": "/v1/chat/completions",
"errors": null,
"input_file_id": "file-51428aca4e0a47808012aaa03d1734ff",
"completion_window": "24h",
"status": "validating",
"created_at": 1764031200,
"in_progress_at": null,
"expires_at": 1764117600,
"finalizing_at": null,
"completed_at": null,
"cancelling_at": null,
"cancelled_at": null,
"expired_at": null,
"failed_at": null,
"request_counts": { "total": 4, "completed": 0, "failed": 0 },
"metadata": { "job": "nightly" }
}The response may omit fields such as
output_file_id/error_file_idthat have not been produced yet.
Error Response
| HTTP | code | Description |
|---|---|---|
| 400 | invalid_request | The request body is not valid JSON |
| 400 | missing_input_file_id | input_file_id is missing |
| 400 | missing_endpoint | endpoint is missing |
| 400 | invalid_batch | File structure validation failed (multiple models, multiple endpoints, duplicate custom_id, invalid completion_window, metadata exceeding limits, etc.) |
| 403 | model_access_denied | No permission to access the models in the file |
| 403 | no_batch_channel | The current configuration does not support Batch |
| 403 | no_batch_group | Batch is not enabled for the current API Key |
| 402 | insufficient_quota | The balance is insufficient to pay for this batch |
| 404 | file_not_found | input_file_id does not exist or does not belong to the current API Key |
| 429 | batch_limit_exceeded | Batch submission limit exceeded |
| 503 | object_storage_unconfigured | The Batch service is temporarily unavailable |
| 503 | batch_create_budget_exceeded | Batch creation timed out; retry later or use a smaller file |
List Batches
Endpoint
GET /v1/batchesRequest Parameters
| Field | Type | Required | Description |
|---|---|---|---|
limit | int | No | Page size. Default 20, maximum 100 |
after | string | No | Cursor: the last_id returned by the previous page |
Request Example
curl --location 'https://neolink.com/api/v1/batches?limit=20' \
--header 'Authorization: Bearer <api-key>'Success Response
{
"object": "list",
"data": [
{
"id": "batch-63c583173a0a472bb8d3e48207041690",
"object": "batch",
"endpoint": "/v1/chat/completions",
"errors": null,
"input_file_id": "file-51428aca4e0a47808012aaa03d1734ff",
"completion_window": "24h",
"status": "in_progress",
"created_at": 1764031200,
"in_progress_at": 1764031215,
"expires_at": 1764117600,
"finalizing_at": null,
"completed_at": null,
"cancelling_at": null,
"cancelled_at": null,
"expired_at": null,
"failed_at": null,
"request_counts": { "total": 4, "completed": 2, "failed": 0 },
"metadata": {}
}
],
"has_more": false,
"first_id": "batch-63c583173a0a472bb8d3e48207041690",
"last_id": "batch-63c583173a0a472bb8d3e48207041690"
}Results are sorted by created_at in descending order; first_id / last_id are null for an empty list.
Error Response
| HTTP | code | Description |
|---|---|---|
| 400 | invalid_limit | limit is not a positive integer |
| 400 | invalid_after | The after cursor is invalid or points to a batch that does not exist |
Retrieve Batch Details
Endpoint
GET /v1/batches/{id}Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Batch identifier batch-... |
Request Example
curl --location 'https://neolink.com/api/v1/batches/batch-63c583173a0a472bb8d3e48207041690' \
--header 'Authorization: Bearer <api-key>'Success Response
Returns the batch object. For the fields, see API Overview · Batch Object. When polling, focus on:
status: whether the batch has reached a terminal state (completed/cancelled/expired/failed);request_counts: the number of requests that have succeeded/failed;output_file_id/error_file_id: once present, the results can be downloaded.
Error Response
| HTTP | code | Description |
|---|---|---|
| 404 | batch_not_found | The batch does not exist or does not belong to the current API Key |
Cancel a Batch
Endpoint
POST /v1/batches/{id}/cancelRequest Parameters
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Batch identifier batch-... |
Request Example
curl --request POST \
--url 'https://neolink.com/api/v1/batches/batch-84ed677b391849d48368c9b85788638c/cancel' \
--header 'Authorization: Bearer <api-key>'Success Response
Returns the batch object after cancellation.
| Current Status | Behavior |
|---|---|
validating / in_progress | Returns cancelling, and eventually becomes cancelled |
cancelling / cancelled | Idempotent; returns the current batch object |
After cancellation, no new requests are dispatched. Requests already executing are allowed to finish and are billed by actual usage; requests that were never executed incur no charge.
Error Response
| HTTP | code | Description |
|---|---|---|
| 400 | batch_not_cancellable | The batch has already finished or is generating results, so it cannot be cancelled |
| 404 | batch_not_found | The batch does not exist or does not belong to the current API Key |
