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 Playground
import 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)

FieldRequiredDescription
documentYesPDF, PNG, JPEG, WebP, BMP, or multi-page TIFF (max 20 MiB).
schemaYesJSON string defining fields, nested arrays, checksums, and hard/soft constraints. Browse ready-to-use templates in the Schema Library.
include_greedyOptional (false)When true, also returns greedy_data (unconstrained per-field argmax) for auditing how CP-SAT corrected raw predictions.
include_page_imagesOptional (false)When true, returns straightened WebP page previews (page_images) matching normalized provenance coordinates.

Response Object (ExtractOut)

PropertyTypeMeaning
status"OPTIMAL" | "FEASIBLE" | "INFEASIBLE"CP-SAT solve proof. Auto-approve OPTIMAL/FEASIBLE documents; route INFEASIBLE cases to exception review.
dataRecord<string, unknown>Extracted nested JSON typed to your ExtractionSchema (fixed-point currency, dates, booleans, arrays).
provenanceRecord<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.
constraintsConstraintsOutIndependent verifier audit: all_hard_satisfied, passed_hard_checks, total_hard_checks, and violated_rule_ids.
mucMucDiagnostics | nullMinimal Unsatisfiable Core diagnostics: initial_feasible, initial_violated_rule_ids, Stage 1.5 implied_intervals, and repaired_pointers.
muc_repairs_triggerednumberCount of 350-DPI visual crop repair rounds executed to resolve initial OCR/constraint conflicts.
straightened_pagesnumber[]0-based indices of raster pages straightened via homography/deskew before OCR.
greedy_dataRecord<string, unknown> | nullWith include_greedy=true, the unconstrained per-field argmax JSON, to compare against the joint CP-SAT solution.
page_imagesPagePreview[] | nullWith include_page_images=true, straightened WebP previews (page, width, height, straightened, data_url) in provenance coordinates.
num_pages, source_kindnumber, "pdf" | "image"Pages read, and whether the upload was a PDF or an image.
modelModelInfoThe served model: name, version, arch, and the checkpoint's sha256.
timings_msRecord<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

  1. Check status === "OPTIMAL" and constraints.all_hard_satisfied === true.
  2. If verified, commit data directly to your ledger, tax engine, or LOS with zero manual touch.
  3. If INFEASIBLE, display only the fields in muc.implied_intervals alongside their provenance[ptr].bbox crops 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.