Key-value fields and schemas
Field extraction runs after the text is extracted. The premium engine reads the merged Markdown together with page images (the first four pages for PDFs and images) and returns structured JSON. It costs +2 credits per page on top of extraction.
Generic fields
Section titled “Generic fields”Set fields=true and the result gains a fields object with the default shape:
curl https://api.deskew.dev/v1/extract \ -H "Authorization: Bearer $DESKEW_API_KEY" \ -F "file=@invoice.pdf" \ -F "fields=true"{ "fields": { "document_type": "invoice", "title": "Invoice 2026-0193", "date": "2026-11-28", "parties": ["Northwind Studio", "Ledgerly Inc."], "identifiers": [ { "name": "Invoice number", "value": "2026-0193" }, { "name": "PO", "value": "PO-4471" } ], "total_amount": 1489.0, "currency": "EUR", "key_values": [ { "key": "Due date", "value": "2026-12-28" }, { "key": "Payment terms", "value": "Net 30" } ] }}| Field | Type |
|---|---|
document_type |
string, free text such as invoice, contract, receipt |
title |
string |
date |
string, the document’s main date as written or normalised when unambiguous |
parties |
string[] |
identifiers |
{name, value}[] for reference numbers |
total_amount |
number |
currency |
string |
key_values |
{key, value}[] for everything else that reads as a label and a value |
Keys that do not apply to the document are omitted or empty. Values are strings except total_amount.
Your own schema
Section titled “Your own schema”For a fixed shape, store a JSON Schema once and reference it by name. The schema must be an object schema ("type": "object").
curl https://api.deskew.dev/v1/schemas \ -H "Authorization: Bearer $DESKEW_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "invoice-v1", "json_schema": { "type": "object", "properties": { "invoice_number": { "type": "string" }, "issue_date": { "type": "string", "description": "ISO 8601 date" }, "supplier": { "type": "string" }, "total": { "type": "number" }, "currency": { "type": "string" }, "line_items": { "type": "array", "items": { "type": "object", "properties": { "description": { "type": "string" }, "quantity": { "type": "number" }, "amount": { "type": "number" } }, "required": ["description", "amount"] } } }, "required": ["invoice_number", "total"] } }'schema = { "type": "object", "properties": { "invoice_number": {"type": "string"}, "issue_date": {"type": "string", "description": "ISO 8601 date"}, "supplier": {"type": "string"}, "total": {"type": "number"}, "currency": {"type": "string"}, }, "required": ["invoice_number", "total"],}r = requests.post(f"{API}/v1/schemas", headers=HEADERS, json={"name": "invoice-v1", "json_schema": schema})r.raise_for_status() # 201const res = await fetch(`${API}/v1/schemas`, { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: JSON.stringify({ name: "invoice-v1", json_schema: { type: "object", properties: { invoice_number: { type: "string" }, issue_date: { type: "string", description: "ISO 8601 date" }, supplier: { type: "string" }, total: { type: "number" }, currency: { type: "string" }, }, required: ["invoice_number", "total"], }, }),});The response is 201 with the stored schema, including a version:
{ "id": "sch_01JE4KC7H2J3K4L5M6N7P8Q9R0", "name": "invoice-v1", "version": 1, "json_schema": { "...": "..." } }Then pass the name on an extract request. fields is implied:
curl https://api.deskew.dev/v1/extract \ -H "Authorization: Bearer $DESKEW_API_KEY" \ -F "file=@invoice.pdf" \ -F "schema=invoice-v1"{ "fields": { "invoice_number": "2026-0193", "issue_date": "2026-11-28", "supplier": "Northwind Studio", "total": 1489.0, "currency": "EUR", "line_items": [ { "description": "Design work", "quantity": 12, "amount": 1440.0 }, { "description": "Hosting", "quantity": 1, "amount": 49.0 } ] }}Versions
Section titled “Versions”Schema names are unique per project and append-only: posting invoice-v1 again creates version 2, and extraction always uses the latest version of a name. Keep the version in the name (invoice-v1, invoice-v2) if you need to pin a shape, and list what exists with GET /v1/schemas. Schemas cannot be deleted from the API today.
Names are 1–80 characters of letters, digits, _ and -.
Writing schemas that extract well
Section titled “Writing schemas that extract well”- Use
descriptionon properties to say how a value should be read ("Total including tax","ISO 8601 date"). - Keep
requiredto the fields that are always present; the model will otherwise be pushed to invent values. - Prefer flat objects and short arrays. Deeply nested schemas work but are slower and less consistent.
- Numbers are returned as numbers; keep currency as a separate string field rather than embedding it in the amount.
Failure modes
Section titled “Failure modes”If the premium engine is unavailable the extraction falls back to the tier-1 model and adds a warning. If that fails too, the result is returned without fields and warnings[] contains field extraction failed: …; the extraction itself still succeeds and is billed normally. A schema name that does not exist in the project is treated as fields=true with the generic shape.