Skip to content
reaatechREAATECH

Files · Anthropic Document Pipeline for Sage Intacct SMB Invoice Processing

76 (1 binary, 557.8 kB total)attempt 1

README.md·3067 B·markdown
markdown
# Anthropic Document Pipeline for Sage Intacct SMB Invoice Processing
 
> Automatically parse PDF invoices, extract line-item data, and push it directly into Sage Intacct with confidence checks.
 
## Problem
 
SMBs using Sage Intacct manually enter invoice data from PDFs — a slow, error-prone process. This pipeline automates the full flow: upload a PDF, extract text, parse line items with Claude, repair the structured output, run confidence checks, and push to Sage Intacct.
 
## Architecture
 
```mermaid
flowchart LR
  A[PDF Upload] --> B[pdfjs-dist Text Extraction]
  B --> C[Claude Anthropic SDK Extraction]
  C --> D[@reaatech/structured-repair-core Repair]
  D --> E[@reaatech/confidence-router Decision]
  E --> F[Sage Intacct REST API Push]
  E --> G[@reaatech/agent-budget-engine Log]
  G --> H[@reaatech/llm-cost-telemetry]
```
 
## Environment Variables
 
| Variable | Description | Source |
|---|---|---|
| `ANTHROPIC_API_KEY` | Anthropic API key for Claude | [console.anthropic.com](https://console.anthropic.com/settings/keys) |
| `SAGE_INTACCT_COMPANY_ID` | Sage Intacct company ID | Sage Intacct Developer Portal |
| `SAGE_INTACCT_SENDER_ID` | Sage Intacct sender ID | Sage Intacct Developer Portal |
| `SAGE_INTACCT_SENDER_PASSWORD` | Sage Intacct sender password | Sage Intacct Developer Portal |
| `SAGE_INTACCT_USER_ID` | Sage Intacct user ID | Sage Intacct Web App |
| `SAGE_INTACCT_USER_PASSWORD` | Sage Intacct user password | Sage Intacct Web App |
| `SAGE_INTACCT_BASE_URL` | Sage Intacct API base URL | Sage Intacct Developer Portal |
| `LANGFUSE_PUBLIC_KEY` | Langfuse public key | [langfuse.com](https://langfuse.com) |
| `LANGFUSE_SECRET_KEY` | Langfuse secret key | [langfuse.com](https://langfuse.com) |
| `LANGFUSE_HOST` | Langfuse host URL | [langfuse.com](https://langfuse.com) |
| `UNSTRUCTURED_API_KEY` | Unstructured API key | [unstructured.io](https://unstructured.io/developers) |
 
## Setup
 
```bash
pnpm install
cp .env.example .env
# Fill in your keys
pnpm dev
```
 
## API
 
### `POST /api/invoice/process`
 
Upload a PDF invoice for processing.
 
```bash
curl -X POST http://localhost:3000/api/invoice/process \
  -F "file=@invoice.pdf"
```
 
Accepts `multipart/form-data` with a `file` field containing the PDF.
 
## Tests
 
```bash
pnpm test
```
 
## Related Packages
 
- [@reaatech/agent-budget-engine](https://www.npmjs.com/package/@reaatech/agent-budget-engine) — Tracks agent execution costs and budgets
- [@reaatech/confidence-router](https://www.npmjs.com/package/@reaatech/confidence-router) — Routes documents based on extraction confidence
- [@reaatech/llm-cost-telemetry](https://www.npmjs.com/package/@reaatech/llm-cost-telemetry) — LLM cost tracking and telemetry
- [@reaatech/media-pipeline-mcp-doc-extraction](https://www.npmjs.com/package/@reaatech/media-pipeline-mcp-doc-extraction) — Document extraction MCP pipeline
- [@reaatech/structured-repair-core](https://www.npmjs.com/package/@reaatech/structured-repair-core) — Repairs and validates structured data
 
## License
 
MIT — see [LICENSE](./LICENSE).