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

  • 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.

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:
  • 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

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.
Response (207) from POST /v1/files/upload/batch
  • 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. POST /v1/files/upload/multipart/batch ignores Idempotency-Key, so a retry there creates a new batch.

Example

Register a batch with a batchCallbackURL in defaults, upload each file to its presigned URL as in Upload files, then check the batch:
Take batchId from the response (k3x9q2m7v1c8z4n6b0w5t here). Then read the batch status, following nextCursor until hasMore is false:
While one file is still processing:
Response (200)
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

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

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

The two are independent, and you can set either or both: Setting batchCallbackURL does not change or replace the per-file callbacks.

Payload

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

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.

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

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.
  • 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

Endpoints

Authenticate with your API key in the x-api-key header, as in Authentication.

Parameters

files[] is paged in the order the files appeared in the request. counts always cover the whole batch, on every page. See Pagination.

Response

Counts

Files

Callback

Errors

Errors use the shape described in Errors.

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.