AI Documents
Send a purchase document (PDF or image) to the same AI pipeline the app uses for bills. It classifies the document, extracts it, resolves the vendor and line coding, and creates a bill in REVIEW for the accountant to finish in the app (or for you to approve with POST /bills/{bill_id}/approve).
There are no AIBooks.ai.* scopes. These routes reuse the bills scopes: AIBooks.bills.CREATE to submit and AIBooks.bills.READ to read. The organization must have AI enabled, or submitting returns 403.
Response shape
These three routes do not use the standard envelope. They return success: true and camelCase fields at the top level (a list comes back under items):
{
"success": true,
"jobId": "job_…",
"status": "review", // processing | review | parked | posted | failed
"docFamily": "ap",
"docType": "…",
"classifierConfidence": 0.97,
"reviewReason": null,
"error": null,
"billId": "bill_…", // the draft or posted bill, once one exists
"extraction": { // null until extraction has run
"invoiceNumber": "INV-8812",
"invoiceDate": "2026-05-10",
"vendorName": "Acme Supplies",
"vendorGstin": "27AABCC1234D1Z5",
"totalAmount": 11800.0,
"currency": "INR",
"lineCount": 3
},
"createdAt": "2026-05-12T08:30:00"
}parked means the document was recognised as something other than a purchase bill (a bank statement, a credit or debit note, a receipt routed elsewhere) and is waiting for a person in the app. Errors on these routes are raised as plain text, so the code is the generic one for the HTTP status.
/ai/documentsSubmit a documentAIBooks.bills.CREATEIdempotency-Key is required (400 idempotency.key_required without it). Send multipart/form-data with one file field.
curl -X POST "$BASE/ai/documents" \
-H "Authorization: Bearer $PAT" \
-H "Idempotency-Key: $(uuidgen)" \
-F "file=@vendor-invoice.pdf"
201 Created
{ "success": true, "jobId": "job_…", "status": "review", "billId": "bill_…", "extraction": { … }, … }The call runs the pipeline before it answers, which takes a few seconds (the code comment says about 6 to 15), so set a client timeout of at least 30 seconds. If it has not finished, you get the job back in processing and can poll GET /ai/documents/{job_id}.
Notable errors
403 auth.insufficient_scope— AI is not enabled for this organization (the message reads “AI document pipeline is not enabled for this organisation.”). The code is the generic 403 fallback, so read the message.404 not_found.resource— organization not found.
/ai/documents/{job_id}Get a document jobAIBooks.bills.READReturns the shape above for one job. Unknown id: 404 not_found.resource.
/ai/documentsList recent document jobsAIBooks.bills.READlimit: 1 – 100, default 25. Newest first. Not cursor-paginated: you only get the latest limit jobs.
200 OK
{ "success": true, "items": [ { "jobId": "job_…", "status": "review", … } ] }