Skip to content

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.

Set fields=true and the result gains a fields object with the default shape:

Terminal window
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.

For a fixed shape, store a JSON Schema once and reference it by name. The schema must be an object schema ("type": "object").

Terminal window
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"]
}
}'

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:

Terminal window
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 }
]
}
}

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 -.

  • Use description on properties to say how a value should be read ("Total including tax", "ISO 8601 date").
  • Keep required to 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.

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.