Skip to main content
Glama
README.md
# `bifrost-fin-reconcile` — Deterministic Math-Verified Invoice, Receipt & Bank Statement OCR (CLI + Remote MCP)

[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)
[![Hosted Standby API & MCP](https://img.shields.io/badge/Hosted_Standby_API_%26_MCP-Apify_Store-00C853)](https://apify.com/bifrost-data/invoice-bank-statement-ocr-erp-reconciler)
[![MCP Protocol](https://img.shields.io/badge/MCP-Streamable_HTTP_2025--03--26-7C3AED)](https://apify.com/bifrost-data/invoice-bank-statement-ocr-erp-reconciler)

Open-source **Apache-2.0** financial document extraction, local CPU OCR, and **exact `Decimal` double-entry reconciliation** engine. Convert digital PDFs, AES-256 encrypted bank e-Statements, and tilted smartphone receipts into **mathematically audited** accounting entries and compliant EU/ERP e-Invoices:

- **QuickBooks Online CSV** (`4_column` & `3_column` bank feeds + bill imports)
- **Xero CSV** (`*ContactName,*InvoiceNumber,...` & bank statement imports)
- **Peppol BIS Billing 3.0** (`EN 16931 UBL 2.1 XML`, structurally validated via `lxml`)
- **EU Factur-X 1.07 / ZUGFeRD 2.3** (`EN 16931 CII XML`, structurally validated)
- **SAP Ariba / Coupa `cXML 1.2.061`** (`InvoiceDetailRequest`, compatible with [cXML 3-Way Match Bridge](https://apify.com/bifrost-data/cxml-ariba-coupa-procurement-bridge))

---

## Local CLI vs. Hosted Cloud Standby Webhook & MCP

| Capability | Open-Source Local CLI (`bifrost-fin-reconcile`) | [**Hosted Standby HTTP & Remote MCP (`ACT-028`)**](https://apify.com/bifrost-data/invoice-bank-statement-ocr-erp-reconciler) | Legacy Financial OCR SaaS (`Veryfi` / `Mindee`) |
| :--- | :--- | :--- | :--- |
| **Pricing** | **$0 Free Offline** (Apache-2.0) | **`$0.015/page` digital · `$0.030/page` OCR** (`$0/mo` minimum) | `$500/mo` (`Veryfi`) or `$53–$134/mo` minimums |
| **Batch Volume Cap** | **`<= 25` pages / invocation** | **Unlimited pages, `.zip` archives & S3 presigned URLs** | Tier-gated quotas |
| **Runtime Setup** | Local Python + Poppler/Tesseract | **Zero setup** — warm `512MB` container (`POST /reconcile` & `/mcp`) | Proprietary cloud SDK |
| **Duplicate & Invalid Files** | Skipped locally | **`$0.00` Zero-Charge Gate** + `RFC 9457` `copy_paste_patch` | Charged per upload |
| **Data Retention** | Local disk | **100% Zero-Retention** (`/tmp` overwritten & unlinked immediately) | Stored unless Enterprise tier |

---

## 1. Quickstart: Open-Source Local CLI (`<= 25` Pages Free)

Install directly from GitHub (no API keys or cloud accounts required for local digital PDFs):

```bash
# Core digital PDF + bank statement reconciler + 5 ERP/XML compilers
pip install "git+https://github.com/ballostark-wq/bifrost-fin-reconcile.git"

# Optional: include local ONNX + Tesseract OCR dependencies for camera receipts / scanned PDFs
pip install "bifrost-fin-reconcile[ocr] @ git+https://github.com/ballostark-wq/bifrost-fin-reconcile.git"
```

### Run Reconciler on Local Invoices, Receipts, or Encrypted Bank Statements

```bash
# Reconcile an invoice PDF and write QuickBooks CSV, Xero CSV, Peppol UBL 2.1 & Factur-X XML
bifrost-fin-reconcile ./sample_invoice.pdf \
  --formats json,quickbooks_csv,xero_csv,peppol_ubl_xml,facturx_cii_xml,ariba_cxml \
  --output-dir ./exports

# Unlock an AES-256 password-protected multi-page bank statement and verify every running balance row
bifrost-fin-reconcile ./mercury_statement.pdf \
  --password "YOUR_PDF_PASSWORD" \
  --type-hint bank_statement \
  --formats json,quickbooks_csv,xero_csv \
  --output-dir ./exports

# Run the deterministic 12-stage offline verification suite (0 external network calls)
bifrost-fin-reconcile --selftest
```

> **25-Page Local Funnel Cap**: Workloads exceeding `25` pages per CLI invocation return exit code `2` with an `RFC 9457` (`status: 402`, `OSS_CLI_25_PAGE_CAP_EXCEEDED`) pointer to the [Hosted Standby HTTP & MCP Server](https://apify.com/bifrost-data/invoice-bank-statement-ocr-erp-reconciler) for unlimited cloud batch & webhook automation.

---

## 2. Unlimited Cloud Webhooks: Synchronous Standby HTTP (`POST /reconcile`)

Skip Tesseract/Poppler Docker builds in production. Send S3/Drive/Dropbox presigned URLs, `.zip` archives, or raw `application/pdf` / `image/jpeg` bytes directly from **n8n**, **Make.com**, **Zapier**, or backend microservices:

```bash
curl -X POST "https://bifrost-data--invoice-bank-statement-ocr-erp-reconciler.apify.actor/reconcile" \
  -H "Authorization: Bearer $APIFY_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "documents": [
      {
        "fileUrl": "https://your-s3-bucket.s3.amazonaws.com/vendor-invoice.pdf",
        "documentTypeHint": "auto"
      }
    ],
    "exportFormats": ["json", "quickbooks_csv", "xero_csv", "peppol_ubl_xml", "facturx_cii_xml", "ariba_cxml"],
    "strictMathReconciliation": true,
    "dedupeBySha256": true
  }'
```

### One-Click Public Example Tasks on Apify Store
- [Invoice PDF & Receipt OCR to QuickBooks & Xero CSV](https://apify.com/bifrost-data/invoice-bank-statement-ocr-erp-reconciler/examples/invoice-pdf-and-receipt-ocr-to-quickbooks-xero)
- [Bank Statement PDF to Running-Balance Verified CSV](https://apify.com/bifrost-data/invoice-bank-statement-ocr-erp-reconciler/examples/bank-statement-pdf-to-balance-verified-csv)
- [PDF Invoice to Peppol UBL 2.1, Factur-X CII & SAP Ariba cXML](https://apify.com/bifrost-data/invoice-bank-statement-ocr-erp-reconciler/examples/pdf-invoice-to-peppol-ubl-and-facturx-xml)

---

## 3. Connect to Claude Desktop, Cursor, Windsurf & Copilot (`POST /mcp`)

Add the hosted Streamable HTTP MCP endpoint (`server.json` included in repo root):

```json
{
  "mcpServers": {
    "bifrost-fin-reconcile": {
      "type": "streamable-http",
      "url": "https://bifrost-data--invoice-bank-statement-ocr-erp-reconciler.apify.actor/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_APIFY_API_TOKEN"
      }
    }
  }
}
```

### Registered MCP Tools
1. **`reconcile_financial_documents`**: Hybrid vector/OCR extraction + exact `Decimal` math audit + simultaneous QuickBooks, Xero, Peppol UBL 2.1, Factur-X CII, and Ariba cXML compilation.
2. **`verify_bank_statement_running_balance`**: Multi-page chronological direction detection + row-by-row `prev_balance - debit + credit == printed_balance` verification (`$0.01` precision).

---

## 4. What `Zero-Hallucination Math Guard` Verifies

1. **Line-Item Arithmetic**: `round(quantity * unit_price, 2) == line_total` across every extracted line.
2. **Header Summation**: `sum(line_total) == subtotal` and `subtotal + tax_total + shipping_total - discount_total == grand_total`.
3. **SEPA EPC-QR Cross-Check**: Decodes European `BCD` payment QR codes and verifies QR `EUR` amount & beneficiary IBAN against OCR-extracted totals.
4. **Checksum Validation**: Validates EU VAT numbers, US EIN, Korean BRN (`10-digit` weighted mod-10), and international IBAN (`ISO 13616 MOD-97-10`).
5. **Continuous Bank Running Balances**: Audits both oldest-first and newest-first multi-page statements across page breaks, returning `VERIFIED_EXACT`, `ROUNDING_TOLERANCE_1C`, or `DISCREPANCY_FLAGGED` with pinpointed `discrepancy_rows[]`.

---

## Related Enterprise Finance & B2B Automation Engines

- [**cXML SAP Ariba & Coupa 3-Way Match Bridge (`$65/1k`)**](https://apify.com/bifrost-data/cxml-ariba-coupa-procurement-bridge) — Pair directly with `ariba_cxml` output for automated PO ↔ ASN ↔ Invoice 3-way reconciliation.
- [**SWIFT MT103 & Bank PDF Advice to ISO 20022 CBPR+ `pacs.008` Bridge (`$60/1k`)**](https://apify.com/bifrost-data/swift-mt103-cbpr-pacs008-wire-bridge) — Treasury wire advice PDF extraction & CBPR+ validation.
- [**7-ATS Enterprise Hiring Signals Scraper (`$1.00/1k`)**](https://apify.com/bifrost-data/greenhouse-lever-ashby-hiring-signals-scraper) — Unified Greenhouse, Lever, Ashby, SmartRecruiters, Workable, Recruitee & Rippling feed.
- [**n8n & Make.com Finance Automation Playbooks**](https://github.com/ballostark-wq/b2b-lead-automation-playbooks) — Ready-to-import workflow JSONs (`integrations/` folder also included in this repo).
- [**Bifrost K-Finance, US SEC XBRL & OFAC Sanctions MCP**](https://github.com/ballostark-wq/bifrost-kfinance-mcp) — Counterparty OFAC SDN & GLEIF LEI screening.

## License

Apache License 2.0 — see [`LICENSE`](./LICENSE).