/api/ocr-structured endpoint extracts invoice data into a structured JSON format compatible with MyBillBook. It includes automatic reconciliation to verify calculations and detect mismatches.
Endpoint
Request Body
Base64-encoded image data or data URLFormats:
- Bare base64:
iVBORw0KGgoAAAANS... - Data URL:
data:image/png;base64,iVBORw0KGgo...
MIME type of the image (e.g.,
image/png, image/jpeg, image/webp)Override the default model. Examples:
openai/gpt-4o, anthropic/claude-3.5-sonnetResponse Schema
The endpoint returns a structured invoice document with three main sections:Voucher Object
Invoice header information and totals
Items Array
Line items extracted from the invoice
Party Object
Customer/buyer information
Example Requests
Example Response
Success (200)
Error (400)
Reconciliation Logic
The endpoint automatically runs reconciliation usinglib/invoice.ts:
- Parse extracted JSON from model response
- Compute line item totals:
taxable = qty × price × (1 - discount%); tax = taxable × tax_rate; total = taxable + tax - Apply voucher discount before or after tax based on
invoice_discount_mode - Add charges with their GST
- Apply round-off adjustment
- Compare computed total with
total_invoice_amount - Set status:
"matched"if difference ≤ 0.05, else"unmatched"
Schema Constraints
The system prompt enforces these rules:- Numbers: Strings without commas (e.g.,
"1234.50") - Dates: dd-mm-yyyy format (converts from other formats)
- Unknown values: Empty string
"" - Tax-exclusive prices:
item.pricemust be pre-GST; model converts if needed - Discount combination: Multiple discounts combined multiplicatively
- Round-off: Typically ±1.00 unless explicitly printed
Limitations
- Image input only (no PDF support)
- Simpler schema than v4 (no header discounts, TCS, etc.)
- Less sophisticated reconciliation than v4
- Better suited for basic invoices
Migration to V4
For India GST invoices with complex scenarios, migrate to/api/ocr-structured-v4:
- PDF support with multi-page processing
- Header-level discounts (trade, special)
- TCS (Tax Collected at Source)
- HSN-wise tax tables
- Advanced reconciliation with multiple strategies
- Confidence scoring per field
Next Steps
V4 Schema
Upgrade to advanced India GST schema
Reconciliation Logic
Learn how calculation verification works
