Files
Upload documents once, reuse them across analyses, and download their PDF previews.
Upload each document once with POST /v1/files. You can then use its ID in as many analyses as you
need. Uploading is free and does not start an analysis. AirCredit stores the original bytes and
starts preparing the file for analysis right away.
A file cannot change after upload. To correct a document, upload the new version as a new file, as Analyses describes.
Upload a file
Send the file as multipart form data, with a new Idempotency-Key. The SDKs do both in one call,
createFile in TypeScript and create_file in Python and Rust. It takes the file name and content
type from the path and sends a new key with every upload. The quickstart and the
examples below upload this way.
The multipart body has one file part and an optional retention_days part
(Shorter retention). The API rejects a duplicate or unknown part.
The API answers 201 with the file's id, mode, size in bytes and expiry time in expires_at,
plus a Location header. Store the ID. The API has no endpoint that returns a file's status or its
original bytes. A test key keeps only the file's metadata (Test mode).
A live upload counts the document's pages before it answers, because analyses are priced by them (Billing). A Word file is converted to PDF for this, which can take a few seconds. AirCredit refuses a document it can never analyze:
- more than 500 pages:
422 document_too_large. For a text file that is about 1.5 million characters; - a document it cannot open, such as a damaged PDF:
422 unreadable_document.
If counting is briefly unavailable, the upload returns 429 rate_limited. Wait Retry-After
seconds, then retry with the same Idempotency-Key.
Retries
Every upload needs an Idempotency-Key header. Use a new key for each new file. A key applies
within its integration and mode.
- The same key with the same upload returns the original file, again with
201. - The same key with a different upload returns
409 idempotency_conflict. - A retry while the first upload is still in progress can return
409 upload_in_progress.
Limits
| Limit | Value | When exceeded |
|---|---|---|
| Files per integration and mode | 256 | 409 file_limit_reached |
| Size of one file | 100 MiB | 413 payload_too_large |
| Pages of one document | 500 | 422 document_too_large |
A file counts toward the file limit until it is deleted or expires. The detail of the 409 error
names the limit. Delete files you no longer need, or wait for them to expire, then retry. Test files
expire 24 hours after upload. Limits lists every current limit.
Supported formats
| Format | Content type |
|---|---|
application/pdf | |
| JPEG | image/jpeg |
| PNG | image/png |
| Word DOC | application/msword |
| Word DOCX | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| Text | text/plain |
| Markdown | text/markdown |
| CSV | text/csv |
| HTML | text/html |
| JSON | application/json |
Text files must be UTF-8. Keep the exact original bytes of every text file, because text citations point to byte positions in them.
Shorter retention
Files are kept for the integration's retention period, 30 days by default. To delete a file sooner,
send retention_days with the upload. This example keeps the file for seven days, and an analysis
of it too:
// Keeps a file and its analysis for seven days instead of the integration's 30.
import { Client } from "@aircredit/sdk/partner/v1";
const client = Client.fromEnv();
// Keep the upload for seven days.
const file = await client.createFile("payslip.pdf", { retentionDays: 7 });
console.log(`the file expires at ${file.expires_at}`);
// Keep the analysis for seven days too.
const analysis = await client.createAnalysis({
files: [file.id],
retention_days: 7,
spec: { fields: { net_income: { builtin: "net_salary" } } },
});
console.log(`analysis ${analysis.id} is ${analysis.status}`);Retention and deletion explains what happens when a file expires.
Preview
Every file with pages has a preview: a PDF of the pages AirCredit read. Page citations point to pages of this PDF, so draw highlights on the preview, whatever the original format.
| Original | Preview |
|---|---|
| The same pages as the original | |
| JPEG, PNG | One page, turned upright according to the EXIF orientation |
| DOC, DOCX | The PDF AirCredit converted the document to |
Text files have no pages and no preview. Their citations are byte ranges in the original file. For billing and the page limit, a text file counts one page per 3,000 characters.
Download the preview with GET /v1/files/{id}/preview. This example uploads a payslip and saves its
preview, waiting up to a minute while AirCredit prepares the file:
// Downloads the preview PDF that page citations are drawn on.
import { writeFile } from "node:fs/promises";
import { Client } from "@aircredit/sdk/partner/v1";
const client = Client.fromEnv();
// Upload the payslip. PDFs, images and Word documents all preview as a PDF.
const file = await client.createFile("payslip.pdf");
// The preview is ready once AirCredit has prepared the file, so wait up to a minute for it.
const preview = await client.waitForFilePreview(file.id, { timeout: 60 });
await writeFile("payslip.preview.pdf", preview);The response is the PDF, with the content type application/pdf.
409 preview_not_readymeans AirCredit is still preparing the file. Retry after the number of seconds inRetry-After. The SDKs' preview helper in the example does this for you.404 preview_unavailablemeans the file has no preview. This applies to text files, files that could not be processed, and files whose preview could not be made. Retrying does not help.
The pages of a preview never change, but a later download can return a different PDF with the same pages. Do not convert a Word file yourself, because your conversion can lay out the pages differently.
Delete a file
DELETE /v1/files/{id} returns an empty 204. The file is unavailable immediately. So is every
analysis that uses it, finished or not. AirCredit cancels work still running on those analyses and
removes the stored data later. Other files and your usage records are kept.
Retention and deletion has the details.