Scan a receipt or invoice into a proposed voucher
Takes a receipt or invoice as RAW BYTES — a PDF, an image or plain text, uploaded under its own content type, not wrapped in JSON — extracts what the…
POST /v1/books/scan
| Address | https://api.hanzo.ai/v1/books/scan |
| Method | POST |
| Operation | post_books_scan |
| Auth | Authorization: Bearer $HANZO_API_KEY |
Takes a receipt or invoice as RAW BYTES — a PDF, an image or plain text, uploaded under its own content type, not wrapped in JSON — extracts what the document says, resolves the vendor's expense category, and answers a DRAFT carrying a balanced voucher proposed for it.
NOTHING IS POSTED. That split is the whole design: the model only ever produces a structured reading of the document, the voucher is assembled deterministically in Go from that reading, and the ledger is written only by the separate book call a human confirms. So a misread scan can propose a wrong draft; it cannot move money. Amounts are exact integer cents end to end — the extraction returns cents, never a decimal — so no rounding enters the ledger.
The draft's id is the FILE HASH, and that is what makes booking idempotent: re-scanning the same bytes addresses the same draft rather than queuing a second one. A row is written to the org's document inbox as a side effect, moving it from unsorted to draft. Scoped to the caller's own org from the validated principal and refused without one; sandbox=true targets the sandbox ledger, and filename is recorded for the inbox. An empty or oversized upload is a 400, and a deployment with no scanner model answers 501.
Request
1 field, body application/octet-stream.
| Field | In | Type | Required | Description |
|---|---|---|---|---|
(body) | body | string (binary) | yes |
Response
| Status | Body | Meaning |
|---|---|---|
2XX | ScanDraft | Success |
2XX body — 32 fields.
| Field | In | Type | Always | Description |
|---|---|---|---|---|
balanced | body | boolean | — | |
category | body | string | — | |
confidence | body | string | — | |
extracted | body | Extracted | — | |
extracted.category | body | string | — | Category is the expense bucket the SCANNER guessed, as a slug — a hint only. |
extracted.currency | body | string | — | Currency is the ISO code the document is denominated in. |
extracted.issuedAt | body | string | — | IssuedAt is the document's OWN date as YYYY-MM-DD — when the bill was issued, which is not when it was uploaded or when it will post. |
extracted.lineItems | body | LineItem[] | — | LineItems are the individual lines read off the document, where it had any. |
extracted.lineItems[].amountCents | body | integer | — | AmountCents is that line's amount in whole cents. |
extracted.lineItems[].description | body | string | — | Description is the line as it appears on the document. |
extracted.merchant | body | string | — | Merchant is the supplier as printed on the document. |
extracted.note | body | string | — | Note is anything else worth carrying from the document that has no field of its own. |
extracted.taxCents | body | integer | — | TaxCents is how much of that total is tax, in cents. |
extracted.totalCents | body | integer | — | TotalCents is the document total in whole cents, tax INCLUDED. |
questions | body | Question[] | — | |
questions[].account | body | string | — | Account is the chart number the questioned entry posted to, where one applies. |
questions[].amount | body | string | — | Amount is the figure that makes the question concrete, already FORMATTED for display with its currency symbol — a string, not cents, and not for arithmetic. |
questions[].id | body | string | — | ID is the source transaction the question is about, so answering it leads straight back to the entry that raised it. |
questions[].kind | body | string | — | Kind is what looked wrong: outlier (a charge far above the usual), reversal (a posting undone), roundoff (a balancing plug big enough to be worth explaining),… |
questions[].postedAt | body | string | — | PostedAt anchors the question in time — when the entry it concerns posted. |
questions[].text | body | string | — | Text is the question itself, written for a founder to answer directly. |
scanId | body | string | — | |
vendor | body | string | — | |
voucher | body | Voucher | — | |
voucher.description | body | string | — | Description is the human line for the event, e.g. |
voucher.legs | body | Leg[] | — | Legs are the sides of the posting. |
voucher.legs[].account | body | string | — | Account is the chart-of-accounts number this side posts to, e.g. |
voucher.legs[].credit | body | integer | — | Credit is the leg's credit in exact cents. |
voucher.legs[].debit | body | integer | — | Debit is the leg's debit in exact cents. |
voucher.postingAt | body | string | — | PostingAt is the RFC3339 instant the event posts at — the time every statement window filters on. |
voucher.sourceId | body | string | — | SourceID is the source event's own id within that namespace. |
voucher.sourceKind | body | string | — | SourceKind is the idempotency namespace naming what booked this, e.g. |
Failure carries the platform error shape — see Errors.
Examples
hanzo books scan createimport { Configuration, BooksApi } from 'hanzoai';
const api = new BooksApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postBooksScan();from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import BooksApi
client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = BooksApi(client).post_books_scan()cfg := cloud.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := cloud.NewAPIClient(cfg)
resp, _, err := client.BooksAPI.PostBooksScan(context.Background()).Execute()
if err != nil {
return err
}use hanzo_cloud::apis::{configuration::Configuration, books_api};
let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();
let result = books_api::post_books_scan(&cfg, Default::default()).await?;import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.BooksApi;
ApiClient client = new ApiClient();
client.setRequestInterceptor(b -> b.header("Authorization", "Bearer " + System.getenv("HANZO_API_KEY")));
var result = new BooksApi(client).postBooksScan();curl -X POST https://api.hanzo.ai/v1/books/scan \
-H "Authorization: Bearer $HANZO_API_KEY"The door reaches books through the books tool, which names its 24 operations with its own verbs — this one among them, under a name only the door declares. describe explains any of them:
curl -X POST https://api.hanzo.ai/v1/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "describe",
"arguments": {
"op": "list_book_accounts"
}
}
}'How is this guide?