# AI OCR Solution for Invoices, Receipts & Contracts — API Store Hub

> VI: Trích xuất tự động mã số thuế, dòng hàng, thuế suất VAT, số tiền và chữ ký từ ảnh chụp hóa đơn/chứng từ Việt Nam sang JSON kế toán với độ chính xác cao.
> EN: Extract tax IDs, line items, VAT rates, totals, and signatures from invoices, bills of lading, and contracts into validated accounting JSON.

- Industry: Accounting, Finance & Logistics Document AI
- Canonical VI: https://apistorehub.com/vi/giai-phap/ocr-hoa-don-chung-tu-viet-nam
- Canonical EN: https://apistorehub.com/en/giai-phap/ocr-hoa-don-chung-tu-viet-nam

## Reference Architecture
Pre-process scans (auto-orient, resize to 1800px JPEG), extract structured fields with Vision + JSON Schema, and run deterministic math checksums (subtotal + VAT == total) to flag exceptions automatically.

## Recommended Model Stack (Live ST Pricing)
| Role | Model | Live ST Rate | Why |
|---|---|---|---|
| High-Volume Standard Invoice OCR | `gemini-3.8-flash` | 5,200 ST / 1M tokens | Fast, low-cost extraction on structured invoices and thermal receipts. |
| Complex Scans & Handwritten Documents | `claude-sonnet-5-5` | 7,700 ST / 1M tokens | Superior reasoning on multi-column tables and degraded scans. |
| Long Contract & Clause Verification | `gemini-4-neon` | 20,400 ST / 1M tokens | Up to 1M context for cross-checking full contract bundles. |

## Deployment Steps
1. Compress document images to 1600–2000px JPEG (q=82) to prevent 413 errors and speed up inference.
2. Extract fields against a strict accounting JSON Schema with line items and tax totals.
3. Run deterministic arithmetic validation (`sum(items) + vat == grand_total`) in backend code.
4. Automatically escalate failed checksums to `claude-sonnet-5-5` before human review.

## Quickstart cURL
```bash
curl https://apistorehub.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ash-your_key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-3.8-flash","response_format":{"type":"json_object"},"messages":[{"role":"user","content":"Trích xuất JSON gồm mst, ngay_hd, tong_tien từ nội dung hóa đơn đính kèm."}]}'
```

## FAQ
- **Why pair Vision LLMs with deterministic arithmetic checks?**: Checksum validation catches rare digit misreads on blurry scans and automatically triggers a stronger second-pass model.
- **Do Vision models handle skewed phone photos?**: Yes. Modern multimodal models handle perspective distortion and uneven lighting far better than legacy OCR.
- **How should I process 20-page PDFs?**: Render pages to 1600px JPEG images and process them concurrently in small batches.
