Skip to content

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 validating state; 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 ​

http
POST /v1/batches

Request Headers ​

ParameterTypeRequiredDescription
AuthorizationstringYesBearer <api-key>
Content-TypestringYesapplication/json

Request Parameters ​

FieldTypeRequiredDescription
input_file_idstringYesIdentifier of an uploaded purpose=batch file
endpointstringYesBatch endpoint; currently only /v1/chat/completions is supported
completion_windowstringNoCompletion window; only 24h is accepted (treated as 24h when omitted)
metadataobject<string,string>NoCustom 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 or POST), url and body;
  • All rows share the same url, equal to the endpoint used when creating the batch;
  • All rows have a body.model that exists and is identical (a batch can only use one model);
  • Row-level metadata satisfies the same limits as the metadata of 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 ​

bash
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 ​

json
{
  "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_id that have not been produced yet.

Error Response ​

HTTPcodeDescription
400invalid_requestThe request body is not valid JSON
400missing_input_file_idinput_file_id is missing
400missing_endpointendpoint is missing
400invalid_batchFile structure validation failed (multiple models, multiple endpoints, duplicate custom_id, invalid completion_window, metadata exceeding limits, etc.)
403model_access_deniedNo permission to access the models in the file
403no_batch_channelThe current configuration does not support Batch
403no_batch_groupBatch is not enabled for the current API Key
402insufficient_quotaThe balance is insufficient to pay for this batch
404file_not_foundinput_file_id does not exist or does not belong to the current API Key
429batch_limit_exceededBatch submission limit exceeded
503object_storage_unconfiguredThe Batch service is temporarily unavailable
503batch_create_budget_exceededBatch creation timed out; retry later or use a smaller file

List Batches ​

Endpoint ​

http
GET /v1/batches

Request Parameters ​

FieldTypeRequiredDescription
limitintNoPage size. Default 20, maximum 100
afterstringNoCursor: the last_id returned by the previous page

Request Example ​

bash
curl --location 'https://neolink.com/api/v1/batches?limit=20' \
  --header 'Authorization: Bearer <api-key>'

Success Response ​

json
{
  "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 ​

HTTPcodeDescription
400invalid_limitlimit is not a positive integer
400invalid_afterThe after cursor is invalid or points to a batch that does not exist

Retrieve Batch Details ​

Endpoint ​

http
GET /v1/batches/{id}

Request Parameters ​

FieldTypeRequiredDescription
idstringYesBatch identifier batch-...

Request Example ​

bash
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 ​

HTTPcodeDescription
404batch_not_foundThe batch does not exist or does not belong to the current API Key

Cancel a Batch ​

Endpoint ​

http
POST /v1/batches/{id}/cancel

Request Parameters ​

FieldTypeRequiredDescription
idstringYesBatch identifier batch-...

Request Example ​

bash
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 StatusBehavior
validating / in_progressReturns cancelling, and eventually becomes cancelled
cancelling / cancelledIdempotent; 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 ​

HTTPcodeDescription
400batch_not_cancellableThe batch has already finished or is generating results, so it cannot be cancelled
404batch_not_foundThe batch does not exist or does not belong to the current API Key