API Quickstart & Reference
One multipart endpoint. Proven JSON back.
Send a PDF, photo, or multi-page TIFF along with an ExtractionSchema JSON payload. Every response is re-audited by an independent verifier before it reaches your client.
POST/v1/extractmultipart/form-data
Test live in Playgroundimport json
import httpx
schema = json.load(open("w2_schema.json"))
with open("w2-official.pdf", "rb") as f:
resp = httpx.post(
"https://doc2x.ai/api/extract",
files={"document": ("w2-official.pdf", f, "application/pdf")},
data={"schema": json.dumps(schema)},
timeout=60.0,
)
result = resp.raise_for_status().json()
assert result["status"] == "OPTIMAL"
assert result["constraints"]["all_hard_satisfied"] is True
print("Wages (Box 1):", result["data"]["wages"])
print("Provenance:", result["provenance"]["/wages"])Request Parameters (multipart/form-data)
| Field | Required | Description |
|---|---|---|
| document | Yes | PDF, PNG, JPEG, WebP, BMP, or multi-page TIFF (max 20 MiB). |
| schema | Yes | JSON string defining fields, nested arrays, checksums, and hard/soft constraints. Browse ready-to-use templates in the Schema Library. |
| include_greedy | Optional (false) | When true, also returns greedy_data (unconstrained per-field argmax) for auditing how CP-SAT corrected raw predictions. |
| include_page_images | Optional (false) | When true, returns straightened WebP page previews (page_images) matching normalized provenance coordinates. |
Response Object (ExtractOut)
| Property | Type | Meaning |
|---|---|---|
| status | "OPTIMAL" | "FEASIBLE" | "INFEASIBLE" | CP-SAT solve proof. Auto-approve OPTIMAL/FEASIBLE documents; route INFEASIBLE cases to exception review. |
| data | Record<string, unknown> | Extracted nested JSON typed to your ExtractionSchema (fixed-point currency, dates, booleans, arrays). |
| provenance | Record<string, FieldProvenance> | Keyed by JSON Pointer (e.g., /wages). All null for a blank field. Gives 0-based page, normalized [x0, y0, x1, y1] box, raw OCR text, and repaired boolean. |
| constraints | ConstraintsOut | Independent verifier audit: all_hard_satisfied, passed_hard_checks, total_hard_checks, and violated_rule_ids. |
| muc | MucDiagnostics | null | Minimal Unsatisfiable Core diagnostics: initial_feasible, initial_violated_rule_ids, Stage 1.5 implied_intervals, and repaired_pointers. |
| muc_repairs_triggered | number | Count of 350-DPI visual crop repair rounds executed to resolve initial OCR/constraint conflicts. |
| straightened_pages | number[] | 0-based indices of raster pages straightened via homography/deskew before OCR. |
| greedy_data | Record<string, unknown> | null | With include_greedy=true, the unconstrained per-field argmax JSON, to compare against the joint CP-SAT solution. |
| page_images | PagePreview[] | null | With include_page_images=true, straightened WebP previews (page, width, height, straightened, data_url) in provenance coordinates. |
| num_pages, source_kind | number, "pdf" | "image" | Pages read, and whether the upload was a PDF or an image. |
| model | ModelInfo | The served model: name, version, arch, and the checkpoint's sha256. |
| timings_ms | Record<string, number> | Stage latency telemetry in milliseconds: load_ms, ocr_and_layout_ms, neural_forward_ms, cpsat_total_ms, total_ms. |
Straight-Through Processing Pattern
- Check
status === "OPTIMAL"andconstraints.all_hard_satisfied === true. - If verified, commit
datadirectly to your ledger, tax engine, or LOS with zero manual touch. - If
INFEASIBLE, display only the fields inmuc.implied_intervalsalongside theirprovenance[ptr].bboxcrops to an analyst.
HTTP Status Codes
- 413
- Payload Too Large: Uploaded document exceeds the 20 MiB per-request limit.
- 415
- Unsupported Media Type: File suffix is not one of .pdf, .png, .jpg, .jpeg, .webp, .bmp, .tif, .tiff.
- 422
- Unprocessable Entity: Empty or corrupted document, malformed schema JSON, or a constraint referencing a missing field path.
- 429
- Too Many Requests: Public demo rate limit reached; upgrade to a dedicated API key or VPC deployment for high throughput.
- 502
- Bad Gateway: The extraction service could not be reached (for example during a cold start); retry with backoff.