xtract.bot

Document table extraction

Try it interactively →

POST /api/document-table-extraction5 quota units per call · cache hits free

Find the rows and cells of a printed/scanned table using OpenCV morphological line detection. Returns JSON cell rectangles ready for downstream OCR.

Detects the cells of a **ruled-grid table** in a document image using OpenCV morphological line detection. The pipeline: 1. Convert to grayscale + adaptive-threshold (binarise). 2. Extract horizontal lines (morph-open with a long horizontal kernel) and vertical lines (long vertical kernel). 3. Find connected components on `~(horiz ∪ vert)` — each component is a candidate cell. 4. Filter by area; sort top→bottom, then group rows by y-clustering; sort each row left→right. **Output:** JSON with `rows` (array of rows, each an array of cell rectangles) plus a flat `cells` list. Use the returned boxes to crop each cell and feed it through `document-ocr` for text extraction. When `output=annotated-png` is set, returns a PNG with detected cells outlined in red — useful for visually verifying the detection before kicking off a per-cell OCR loop. **Limitations:** - Only works on tables with **visible grid lines**. Borderless tables (e.g. invoices with whitespace-separated columns) need a different algorithm — use ML table-detection for those. - Tilted scans should be deskewed first via `image-deskew`.

Inputs

NameTypeDefaultDescription
image*fileDocument image bytes (PNG/JPEG).
minCellAreanumber (16…1000000)200Minimum cell area in pixels² — filters out noise components.
maxCellAreanumber (16…100000000)1000000Maximum cell area in pixels² — filters out the whole-page background component.
lineKernelDivisornumber (5…200)30Line-extraction kernel length = image_dim / divisor. Smaller = more permissive (detects shorter lines).
rowClusterTolerancenumber (1…200)12Pixels of y-difference within which cells are considered the same row.
outputenum (json | annotated-png)"json"JSON cells (default) or a PNG with cell rectangles drawn for visual debug.

Response

Modes: json, binary. Cache: yes (24h TTL).

Every response carries x-cache (HIT / MISS / BYPASS), x-cache-signature (stable across identical inputs), and the rate-limit headers listed below.

Quota & limits

Cost per call5 units against the 10,000-unit monthly quota. Cache hits are free — only cache misses decrement.
Burst limit200 requests per rolling minute, shared across all tools.
Max request size10 MiB (base64 inflates file payloads ~33% — the limit applies to the decoded bytes).
Max response size25 MiB
Timeout30s wall clock.
Rate-limit headersX-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Burst-Limit on every response; X-Quota-Warning once 80% of the monthly quota is spent; Retry-After on 429s.

Errors

Errors are JSON with an error string; schema failures add a details object (Zod's flattened field errors).

StatusWhenBody
400Input fails the tool's schema (wrong type, missing required field, malformed base64) or the file bytes can't be parsed as the expected format.{ "error": "invalid inputs", "details": { "fieldErrors": { … } } }
401Missing or invalid X-Api-Key / X-Account-Id headers (or no session when called from the browser).{ "error": "unauthorized" }
404Unknown tool id, or calling /api/* on the website hostname instead of api.xtract.bot.{ "error": "not found" }
413Request body over the tool's max request size, or an image header declaring more megapixels than the tool's pixel budget.{ "error": "…exceeds maxRequestBytes…" }
415Content-Type isn't application/json on the json-body transport.{ "error": "unsupported content-type; expected application/json" }
429Monthly quota or the 200/min burst limit exhausted. Check Retry-After and the X-RateLimit-* headers.{ "error": "monthly quota exceeded", "monthRemaining": 0, … }
5xxConversion engine failure. Safe to retry; if it persists, the input is hitting a bug — please report it.{ "error": "…" }

Code samples

Built from the default example.

# Download or substitute the example input:
#   curl -O https://xtract.bot/examples/document-split-pages/sample.png
IMAGE=$(base64 -w0 < sample.png)

curl -X POST https://api.xtract.bot/api/document-table-extraction \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
  -H "X-Api-Key: $XTRACT_API_KEY" \
  -d '{
  "minCellArea": 200,
  "lineKernelDivisor": 30,
  "rowClusterTolerance": 12,
  "output": "json",
  "image": "'"$IMAGE"'"
}'