# Batch status and callbacks
Source: https://docs.file.ai/ingest/batch-status

> Follow a batch of uploads with one status call, or get one callback when the whole batch settles.

fileScout

# Batch status and callbacks

Copy pageCopy page

Follow a batch of uploads with one status call, or get one callback when the whole batch settles.

Copy pageCopy page

After you register files with `POST /v1/files/upload/batch` or `POST /v1/files/upload/multipart/batch`, you can follow the whole batch by its `batchId` instead of polling every `uploadId`. The batch status call returns a state for each file and one set of counts for the batch. Set `batchCallbackURL` and fileAI also sends one `POST` when the batch settles, listing the files that failed.

## [](#when-to-use-it)When to use it

*   You send many files at once and want to know when **all** of them are done, not each one.
*   You need the list of files that failed or were never uploaded, so you can resend just those.
*   You already use a per-file `callbackURL` and want one summary at the end as well.

To follow a single file, use `GET /v1/uploads/{uploadId}` or a [processing callback](/deliver/callbacks).

## [](#how-it-works)How it works

Every file you register in a batch moves through its own states. The batch stays `in_progress` until every registered file is settled, which means it has reached `succeeded`, `failed` or `expired`. Once every file is settled, the batch settles to one of three states:

Batch `state`

When

`completed`

Every file succeeded.

`failed`

No file succeeded.

`partially_failed`

Some succeeded and some did not.

*   **Files rejected at registration count as failures.** A batch with one rejected file can’t reach `completed`. They appear in `counts.rejected` but never in `files[]`.
*   **A batch where every file was rejected** settles at once as `failed`, with an empty `files[]`. Its status and callback still work.
*   **A file you never upload expires.** A registered file that is not uploaded is `expired` 30 minutes after its upload URL expired, so it never holds up the batch. On `/files/upload/batch` the URL lasts 300 seconds, so this is about 35 minutes after registration.
*   **Batches settle without you polling.** A background job also checks unsettled batches, so the callback is sent even if you never call the status endpoint.

## [](#get-the-batchid)Get the batchId

The `batchId` comes back in the response when you register the batch. Save it with your record of the batch: there is no endpoint that lists batches.

You registered with

Where the `batchId` is

`POST /v1/files/upload/batch`

`batchId` at the top of the `201` or `207` response

`POST /v1/files/upload/multipart/batch`

`batchId` at the top of the `201` response. It is also accepted, optionally, by `POST /v1/files/upload/multipart/complete/batch` and echoed back.

Response (207) from POST /v1/files/upload/batch

```
{
  "batchId": "k3x9q2m7v1c8z4n6b0w5t",
  "apiRequestId": "k3x9q2m7v1c8z4n6b0w5t",
  "accepted": 2,
  "rejected": 1,
  "results": [ … ]
}
```

*   Treat `batchId` as an opaque string. Its format depends on the route: `/files/upload/batch` returns a 21-character lowercase id such as `k3x9q2m7v1c8z4n6b0w5t`, and `/files/upload/multipart/batch` returns `batch_` and 26 characters, such as `batch_01JA1ZC7S9V0F4C6H2M8QK3R7T`.
*   Use `batchId`, not `apiRequestId`. They match unless you set your own `apiRequestId` in `defaults`, and only `batchId` works on the status route.
*   A `batchId` is returned even when every file is rejected, and its status and callback still work.
*   Lost the `batchId` from `POST /v1/files/upload/batch`? Repeat the request with the same `Idempotency-Key` within 24 hours, and the replay returns the same `batchId`. See [Idempotency](/api/idempotency). `POST /v1/files/upload/multipart/batch` ignores `Idempotency-Key`, so a retry there creates a new batch.

## [](#example)Example

Register a batch with a `batchCallbackURL` in `defaults`, upload each file to its presigned URL as in [Upload files](/ingest/uploads#batch-registration), then check the batch:

```
curl -X POST "$FILEAI_BASE_URL/files/upload/batch" \
  -H "x-api-key: $FILEAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "defaults": {
      "callbackURL": "https://example.com/fileai/callback",
      "batchCallbackURL": "https://example.com/fileai/batch-callback?token=8f3c..."
    },
    "files": [
      { "fileName": "inv-001.pdf", "fileType": "application/pdf" },
      { "fileName": "inv-002.pdf", "fileType": "application/pdf" },
      { "fileName": "scan.png", "fileType": "image/png", "ocrModel": "Not_A_Model" }
    ]
  }'
```

Take `batchId` from the response (`k3x9q2m7v1c8z4n6b0w5t` here). Then read the batch status, following `nextCursor` until `hasMore` is `false`:

cURL

Python

Node.js

```
curl "$FILEAI_BASE_URL/files/upload/batch/k3x9q2m7v1c8z4n6b0w5t?limit=100" \
  -H "x-api-key: $FILEAI_API_KEY"

# Next page: pass pagination.nextCursor from the previous response
curl "$FILEAI_BASE_URL/files/upload/batch/k3x9q2m7v1c8z4n6b0w5t?limit=100&cursor=<nextCursor>" \
  -H "x-api-key: $FILEAI_API_KEY"
```

```
import os, requests

BASE = "https://api.orion.file.ai/prod/v1"
HEADERS = {"x-api-key": os.environ["FILEAI_API_KEY"]}
batch_id = "k3x9q2m7v1c8z4n6b0w5t"

files, cursor = [], None
while True:
    params = {"limit": 100}
    if cursor:
        params["cursor"] = cursor
    page = requests.get(
        f"{BASE}/files/upload/batch/{batch_id}", headers=HEADERS, params=params
    )
    page.raise_for_status()
    body = page.json()
    files.extend(body["files"])
    if not body["pagination"]["hasMore"]:
        break
    cursor = body["pagination"]["nextCursor"]

print(body["state"], body["counts"])
```

```
const BASE = "https://api.orion.file.ai/prod/v1";
const headers = { "x-api-key": process.env.FILEAI_API_KEY };
const batchId = "k3x9q2m7v1c8z4n6b0w5t";

const files = [];
let cursor;
let body;
do {
  const params = new URLSearchParams({ limit: "100" });
  if (cursor) params.set("cursor", cursor);
  const res = await fetch(`${BASE}/files/upload/batch/${batchId}?${params}`, { headers });
  if (!res.ok) throw new Error(`Batch status failed: ${res.status}`);
  body = await res.json();
  files.push(...body.files);
  cursor = body.pagination.nextCursor;
} while (body.pagination.hasMore);

console.log(body.state, body.counts);
```

While one file is still processing:

Response (200)

```
{
  "batchId": "k3x9q2m7v1c8z4n6b0w5t",
  "createdAt": "2026-12-02T10:00:00.000Z",
  "state": "in_progress",
  "counts": {
    "total": 3,
    "registered": 2,
    "uploaded": 2,
    "processing": 1,
    "succeeded": 1,
    "failed": 0,
    "expired": 0,
    "rejected": 1
  },
  "settlement": null,
  "callback": {
    "status": "waiting",
    "attempts": 0,
    "lastAttemptAt": null,
    "lastResponseStatus": null,
    "lastError": null,
    "nextAttemptAt": null,
    "deliveredAt": null
  },
  "files": [
    {
      "index": 0,
      "uploadId": "f2538513-f0b9-4aa8-9c57-bc0a85c77de6",
      "fileName": "inv-001.pdf",
      "state": "succeeded",
      "documentId": "53d6a0b1-2c4e-4f7a-9b1d-8e6f0a2c3d4e",
      "documentIds": ["53d6a0b1-2c4e-4f7a-9b1d-8e6f0a2c3d4e"]
    },
    {
      "index": 1,
      "uploadId": "a91c7e20-4b3d-4e1f-8c6a-2d5b9f0e7a13",
      "fileName": "inv-002.pdf",
      "state": "processing"
    }
  ],
  "pagination": { "limit": 100, "nextCursor": null, "hasMore": false }
}
```

`scan.png` was rejected at registration (index 2), so it is counted in `counts.rejected` and is not in `files[]`. When `inv-002.pdf` settles, `state` becomes `partially_failed` because of the rejected file, even if `inv-002.pdf` succeeds. `settlement` is filled in and `callback.status` moves to `pending` and then `delivered`.

## [](#batch-callback)Batch callback

Set `batchCallbackURL` in `defaults` on `POST /v1/files/upload/batch` or `POST /v1/files/upload/multipart/batch`. It applies to the whole batch, so you can’t set it per file.

### [](#when-it-is-sent)When it is sent

fileAI sends **one** `POST` after the batch settles as `completed`, `partially_failed` or `failed`. A batch that is still `in_progress` sends nothing, and a batch without `batchCallbackURL` never sends one.

### [](#how-it-relates-to-callbackurl)How it relates to `callbackURL`

The two are independent, and you can set either or both:

`callbackURL`

`batchCallbackURL`

Scope

One upload

The whole batch

Sent

Once per processing step of each file

Once, when the batch settles

Payload

Step event ([Processing callbacks](/deliver/callbacks))

Batch roll-up and failed files (below)

Retries

None

Up to 5 retries

Falls back to the API key’s default

On `/files/upload/batch` only, not on multipart routes

Never

Setting `batchCallbackURL` does not change or replace the per-file callbacks.

### [](#payload)Payload

```
{
  "event": "upload.batch.settled",
  "batchId": "k3x9q2m7v1c8z4n6b0w5t",
  "uploadType": "simple",
  "state": "partially_failed",
  "counts": {
    "total": 3,
    "registered": 2,
    "uploaded": 2,
    "processing": 0,
    "succeeded": 1,
    "failed": 1,
    "expired": 0,
    "rejected": 1
  },
  "settledAt": "2026-12-02T10:04:12.000Z",
  "failures": [
    {
      "index": 1,
      "uploadId": "a91c7e20-4b3d-4e1f-8c6a-2d5b9f0e7a13",
      "fileName": "inv-002.pdf",
      "state": "failed"
    }
  ]
}
```

Field

Type

Description

`event`

string

Always `upload.batch.settled`.

`batchId`

string

The batch. Use it to drop duplicate deliveries.

`uploadType`

string

`simple` for `/files/upload/batch`, `multipart` for `/files/upload/multipart/batch`.

`state`

string

`completed`, `partially_failed` or `failed`.

`counts`

object

The [counts](#counts) when the batch settled.

`settledAt`

string

ISO 8601 time the batch settled.

`failures`

array

Every registered file that `failed` or `expired`, each with `index`, `uploadId`, `fileName` and `state`. Empty when none did. Files rejected at registration are not listed here; they are counted in `counts.rejected`, and you already have their errors from the registration response.

The payload holds the same values as `settlement` on the status response, and it does not change after the batch settles.

### [](#delivery)Delivery

*   **Request:** `POST` with `Content-Type: application/json` and no other custom headers. The batch callback is not signed.
*   **Success:** any `2xx` response. Redirects are not followed.
*   **Timeout:** 10 seconds per attempt, including reading your response.
*   **Retries:** a non-`2xx` response, timeout or network error is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours. That makes six attempts over about 15 hours. After the last one, delivery is `failed`.
*   **No retry:** a URL that is not `https`, includes a username or password, or resolves to a private, loopback or other non-public address fails at once with `URL_NOT_ALLOWED`.
*   **At least once:** the same callback can arrive more than once. Treat `batchId` as the idempotency key.

`batchCallbackURL` is checked when you register the batch: it must be an `https` URL without a username or password, and not `localhost` or a private address. Otherwise the whole request is rejected with `422` `VALIDATION_FAILED` and nothing is registered. Check delivery at any time in `callback` on the [status response](#callback).

### [](#handle-it-safely)Handle it safely

Because the batch callback is not signed, treat it as a signal to check, not as proof:

1

Put a token in the URL

Add an unguessable query parameter to `batchCallbackURL`, for example `?token=8f3c...`, and reject requests without it. fileAI drops only a `#fragment`.

2

Confirm with the API

Before acting, call `GET /v1/files/upload/batch/{batchId}` (or the multipart route) with your API key, and read `settlement` and `files[]`.

3

Skip repeats

Record each `batchId` you have handled and ignore later deliveries for it.

## [](#multipart-batches)Multipart batches

Batches from `POST /v1/files/upload/multipart/batch` have their own status route, `GET /v1/files/upload/multipart/batch/{batchId}`, with the same query parameters and response. The two routes don’t mix: a multipart `batchId` on the simple route, or a simple `batchId` on the multipart route, returns `404`.

*   `files[].uploadId` is the `results[].fileId` from the multipart initiate response, and is the id `GET /v1/uploads/{uploadId}` takes. In that initiate response, `uploadId` is the storage multipart id. See [Many large files](/ingest/uploads#many-large-files).
*   A file is `expired` 30 minutes after its last part URL expired. Refreshing part URLs with `POST /v1/files/upload/multipart/urls/refresh` moves that deadline.
*   An expired file can still be refreshed and completed. It then leaves `expired`, and the live `state` and `counts` are worked out again. `settlement` and the callback already sent keep the values from when the batch first settled.

## [](#reference)Reference

### [](#endpoints)Endpoints

Batch registered with

Status route

`POST /v1/files/upload/batch`

[`GET /v1/files/upload/batch/{batchId}`](/api-reference/uploads/get-the-status-of-a-file-batch)

`POST /v1/files/upload/multipart/batch`

[`GET /v1/files/upload/multipart/batch/{batchId}`](/api-reference/uploads/get-the-status-of-a-multipart-file-batch)

Authenticate with your API key in the `x-api-key` header, as in [Authentication](/authentication).

### [](#parameters)Parameters

Parameter

In

Description

`batchId`

path

The `batchId` from the registration response. See [Get the batchId](#get-the-batchid). Required.

`limit`

query

`files[]` entries per page, 1 to 100. Default 100. Anything else is a `400`.

`cursor`

query

`pagination.nextCursor` from the previous page. Leave it out for the first page. A malformed cursor, or one from another batch, is a `400`.

`files[]` is paged in the order the files appeared in the request. `counts` always cover the whole batch, on every page. See [Pagination](/api/pagination).

### [](#response)Response

Field

Type

Description

`batchId`

string

The batch.

`createdAt`

string

ISO 8601 time the batch was registered.

`state`

string

`in_progress`, `completed`, `partially_failed` or `failed`. Live: see [How it works](#how-it-works).

`counts`

object

Live [counts](#counts) for the whole batch.

`settlement`

object | null

`null` until the batch first settles. Then `state`, `counts` and `settledAt` as they were at that moment. It never changes after it is saved.

`callback`

object | null

Delivery of the [batch callback](#callback). `null` when the batch has no `batchCallbackURL`.

`files`

array

One page of [registered files](#files).

`pagination`

object

`limit`, `nextCursor` (`null` on the last page) and `hasMore`.

### [](#counts)Counts

Field

Description

`total`

Files in the batch request, including files rejected at registration.

`registered`

Files accepted and registered.

`uploaded`

Registered files whose bytes arrived. Always `processing` + `succeeded` + `failed`.

`processing`

Uploaded files still processing.

`succeeded`

Files fully processed.

`failed`

Uploaded files whose processing failed.

`expired`

Registered files not uploaded within 30 minutes after their last upload URL expired.

`rejected`

Files rejected at registration (`total` − `registered`). They never appear in `files[]`.

### [](#files)Files

Field

Type

Description

`index`

number

Zero-based position in the `files` array of the registration request.

`uploadId`

string

The id `GET /v1/uploads/{uploadId}` takes.

`fileName`

string

The file name you registered.

`state`

string

See below.

`documentId`

string

The first document produced from the file, once there is one.

`documentIds`

array

Every document produced from the file. More than one when the file was split.

File `state`

Meaning

`registered`

Waiting for the upload.

`processing`

Bytes received; processing.

`succeeded`

Processed into at least one document. Settled.

`failed`

Processing failed or produced no document, for example a corrupt file. Settled.

`expired`

Not uploaded 30 minutes after its last upload URL expired. Settled.

### [](#callback)Callback

Field

Type

Description

`status`

string

`waiting`: the batch has not settled. `pending`: a delivery is due or will be retried. `delivered`: your URL answered `2xx`. `failed`: every attempt failed, or the URL was refused.

`attempts`

number

Attempts made so far.

`lastAttemptAt`

string | null

When the last attempt was made.

`lastResponseStatus`

number | null

HTTP status of the last attempt, when your URL answered.

`lastError`

string | null

Why the last attempt did not deliver: `HTTP_STATUS`, `TIMEOUT`, `NETWORK_ERROR` or `URL_NOT_ALLOWED`. `null` after a delivery.

`nextAttemptAt`

string | null

When the next attempt is due, while `pending`.

`deliveredAt`

string | null

When your URL acknowledged the callback.

### [](#errors)Errors

Status

`code`

When

`400`

`BAD_REQUEST`

`limit` is outside 1 to 100, or `cursor` is malformed or from another batch.

`401`

`UNAUTHENTICATED`

The `x-api-key` header is missing or the key is invalid.

`403`

`FORBIDDEN`

The key is inactive.

`404`

`NOT_FOUND`

No batch with this `batchId` in the API key’s project. The response is the same when the batch doesn’t exist, belongs to another project, or was registered on the other route, so it never reveals whether a batch exists.

`429`

`RATE_LIMITED`

See [Rate limits](/api/rate-limits).

Errors use the shape described in [Errors](/api/errors).

## [](#related)Related

## Upload files

Register a batch and upload each file.

## Processing callbacks

The per-file callback for each processing step.

## Async jobs

Choose between polling and callbacks.

## Pagination

How cursors work across the API.

[Previous](/ingest/uploads)[

File types

Every file format fileAI accepts for upload, the size limits, and how to prepare files for the best results.

Next

](/ingest/supported-files)

⌘I

## On this page

Back to top

*   [When to use it](#when-to-use-it)
*   [How it works](#how-it-works)
*   [Get the batchId](#get-the-batchid)
*   [Example](#example)
*   [Batch callback](#batch-callback)
    *   [When it is sent](#when-it-is-sent)
    *   [How it relates to callbackURL](#how-it-relates-to-callbackurl)
    *   [Payload](#payload)
    *   [Delivery](#delivery)
    *   [Handle it safely](#handle-it-safely)
*   [Multipart batches](#multipart-batches)
*   [Reference](#reference)
    *   [Endpoints](#endpoints)
    *   [Parameters](#parameters)
    *   [Response](#response)
    *   [Counts](#counts)
    *   [Files](#files)
    *   [Callback](#callback)
    *   [Errors](#errors)
*   [Related](#related)
