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
callbackURLand want one summary at the end as well.
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 staysin_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 incounts.rejectedbut never infiles[]. - A batch where every file was rejected settles at once as
failed, with an emptyfiles[]. Its status and callback still work. - A file you never upload expires. A registered file that is not uploaded is
expired30 minutes after its upload URL expired, so it never holds up the batch. On/files/upload/batchthe 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
ThebatchId 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
batchIdas an opaque string. Its format depends on the route:/files/upload/batchreturns a 21-character lowercase id such ask3x9q2m7v1c8z4n6b0w5t, and/files/upload/multipart/batchreturnsbatch_and 26 characters, such asbatch_01JA1ZC7S9V0F4C6H2M8QK3R7T. - Use
batchId, notapiRequestId. They match unless you set your ownapiRequestIdindefaults, and onlybatchIdworks on the status route. - A
batchIdis returned even when every file is rejected, and its status and callback still work. - Lost the
batchIdfromPOST /v1/files/upload/batch? Repeat the request with the sameIdempotency-Keywithin 24 hours, and the replay returns the samebatchId. See Idempotency.POST /v1/files/upload/multipart/batchignoresIdempotency-Key, so a retry there creates a new batch.
Example
Register a batch with abatchCallbackURL in defaults, upload each file to its presigned URL as in Upload files, then check the batch:
batchId from the response (k3x9q2m7v1c8z4n6b0w5t here). Then read the batch status, following nextCursor until hasMore is false:
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
SetbatchCallbackURL 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 onePOST 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:
POSTwithContent-Type: application/jsonand no other custom headers. The batch callback is not signed. - Success: any
2xxresponse. Redirects are not followed. - Timeout: 10 seconds per attempt, including reading your response.
- Retries: a non-
2xxresponse, 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 isfailed. - 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 withURL_NOT_ALLOWED. - At least once: the same callback can arrive more than once. Treat
batchIdas 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 fromPOST /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[].uploadIdis theresults[].fileIdfrom the multipart initiate response, and is the idGET /v1/uploads/{uploadId}takes. In that initiate response,uploadIdis the storage multipart id. See Many large files.- A file is
expired30 minutes after its last part URL expired. Refreshing part URLs withPOST /v1/files/upload/multipart/urls/refreshmoves that deadline. - An expired file can still be refreshed and completed. It then leaves
expired, and the livestateandcountsare worked out again.settlementand 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.
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.