Document, invoice, and contract classification API
Sort uploaded PDFs, OCR text, and scanned attachments into invoices, tax forms, contracts, and purchase orders—while flagging redlines or missing signatures for legal review in one fast pass.
MASTER SERVICES AGREEMENT — Section 9.2 (Amended): Vendor agrees to unlimited consequential damages and 90-day net payment terms. Signature block: [BLANK].
curl --fail-with-body https://clef-flash.com/api/v1/decisions \
-H "authorization: Bearer $CLEF_API_KEY" \
-H "content-type: application/json" \
--data-binary @- <<'CLEF_DECISION'
{
"model": "cloudflare/clef-flash",
"threshold": 0.86,
"state": "MASTER SERVICES AGREEMENT — Section 9.2 (Amended): Vendor agrees to unlimited consequential damages and 90-day net payment terms. Signature block: [BLANK].",
"questions": {
"doc_type": {
"type": "choice",
"instructions": "Classify this uploaded business document into its exact archive type.",
"criteria": {
"invoice_receipt": "commercial invoice, itemized bill, payment receipt or credit memo",
"tax_form": "W-9, W-8BEN, VAT certificate or tax residency declaration",
"legal_contract": "MSA, NDA, DPA, SOW or enterprise order form",
"purchase_order": "buyer-issued PO authorizing spend with PO number and line items"
}
},
"needs_legal_review": {
"type": "noul",
"instructions": "Does this document contain non-standard liability, redlines or missing signatures requiring human review?",
"criteria": {
"true": "redlined indemnity clauses, uncapped liability or unsigned execution block",
"false": "standard fully executed form, routine invoice or standard tax certificate"
}
}
}
}
CLEF_DECISION
Ship this in production with a $19 Pro key
2,000 decisions/day, 8 concurrent requests in flight, text + JSON + image states, and an API key emailed in about a minute.
Fast, deterministic document intake for finance and legal ops
Vendor onboarding portals and accounts-payable inboxes receive an unpredictable mix of W-9s, VAT certificates, MSAs, redlined NDAs, purchase orders, and receipts. Filename heuristics fail constantly, and pushing every multi-page PDF through an expensive frontier LLM just to route it to the right folder wastes budget.
Clef-Flash reads up to 24,576 tokens (100,000 characters) of extracted document text—or up to 4 scanned page images on paid keys—and returns calibrated probabilities for exact document type plus a needs_legal_review gate in one pass.
- Classifies invoices, W-9/W-8BEN tax forms, POs, and legal contracts into closed archive keys.
- Flags redlined liability clauses, non-standard net terms, or blank signature blocks automatically.
- Accepts both OCR text and direct page images via Clef-Flash native vision encoder.
Document intake taxonomy and compliance gates
Pair high-confidence auto-filing for routine tax and PO documents with strict human review on contracts.
| Document Type | Typical Downstream System | Legal Review Gate |
|---|---|---|
| invoice_receipt | AP ledger / ERP ingestion | Auto-file when P >= 0.86 and standard terms |
| tax_form | Vendor compliance vault (W-9 / VAT) | Flag if unsigned or mismatched entity |
| legal_contract | CLM / Legal counsel queue | Trigger needs_legal_review on any redline |
| purchase_order | RevOps / order activation | Auto-match PO number against quote |
Never silently truncate the signature block on the last page
One classic failure mode in document AI is silent context truncation that cuts off the execution block or amended appendix at the end of a contract. Clef-Flash enforces an explicit 24,576-token (100,000-character) ceiling on /api/v1/decisions and returns HTTP 413 with exact byte counts if a document exceeds it—so you can split cleanly instead of missing a signature.
Inspect the three realistic document samples above, tune your compliance threshold, and copy a ready-to-run curl or TypeScript call.
Precision vs. speed: choose 9B Clef-Flash or 27B Clef per workflow
Use Clef-Flash (9B, ~39 ms median, $0.019/1M input) for high-volume invoice and receipt routing, or switch the model field to cloudflare/clef (27B precision model) on the exact same endpoint when screening subtle legal clauses where maximum accuracy outweighs latency.
Frequently asked questions
Can Clef-Flash classify scanned document images without a separate OCR step?
Yes. Paid API keys on /api/v1/decisions accept up to 4 images per request (up to 4 MiB each) using Clef-Flash and Clef native vision encoders.
What happens if an uploaded contract exceeds the 100,000-character limit?
The API refuses it explicitly with HTTP 413 payload_too_large and reports your exact character count versus the served limit—never silently dropping the end of the contract.
Should I use Clef-Flash (9B) or Clef (27B) for contract redline screening?
Clef-Flash handles high-volume intake routing at ~39 ms; for nuanced legal clause screening, pin model: "cloudflare/clef" (27B) on the exact same /api/v1/decisions endpoint.
Are uploaded documents stored in your database?
No. Decision payloads are processed statelessly and not saved in our application database. Check our privacy page for full retention details.
Keep reading
- Multimodal image decision API
- Email routing classification API
- Clef vs Clef-Flash (27B vs 9B)
- Structured output API
- Pricing & API keys
Model notes
One short email when a new decision model lands or a benchmark changes. No spam, unsubscribe in one click.