Skip to content

API contract

All routes except /health need X-Internal-Token. JSON keys are camelCase.

POST /jobs

{
  "documentId": "doc-1",
  "source": "2026-01/contract.pdf",
  "docType": "contract",
  "fields": [
    { "name": "party", "kind": "text", "description": "counterparty name" },
    { "name": "fee", "kind": "integer" }
  ],
  "lines": false,
  "period": "2026-01",
  "sourceKind": null,
  "requestedBy": "user-42"
}
  • source is relative to QAECHI_SOURCE_DIR or QAECHI_SOURCE_URL. .. is rejected.
  • kind is one of text, integer, number, date.
  • lines: true also asks for line items and a total.
  • sourceKind lets one docType choose between parsers.
  • requestedBy is for audit logs only.

Returns 202 with a Job.

Job

{ "jobId": "…", "status": "succeeded", "documentId": "doc-1", "docType": "contract",
  "createdAt": "…", "finishedAt": "…", "error": null, "resultId": "…" }

Extraction

{
  "id": "…",
  "jobId": "…",
  "documentId": "doc-1",
  "docType": "contract",
  "route": "llm",
  "parser": null,
  "parserVersion": "llm-gpt-4o-mini-p1",
  "fields": {
    "fee": { "value": 1000, "confidence": 0.9,
             "provenance": { "documentId": "doc-1", "chunkId": 3, "page": 2, "quote": "Fee: 1,000" } }
  },
  "lines": [],
  "total": null,
  "groundedness": "yes",
  "quoteCheck": { "checked": 1, "notInSource": [] },
  "stub": false,
  "notes": [],
  "payload": {},
  "createdAt": "…"
}
Field Meaning
route How the document was read: parser, llm or stub
groundedness yes, no, unknown. unknown when it could not be graded
quoteCheck.notInSource fields whose quote was not found in the source text
stub nothing was read. Never accept stub values
notes what was skipped or truncated

Suggested gate on the caller side

Reject when stub is true, when quoteCheck.notInSource is not empty, or when a required value has no provenance. Treat groundedness: unknown as "needs a human".

GET /results

Query: documentId, limit (1 to 200, default 50), offset. Returns { items, total, limit, offset }, newest first.