> This documentation belongs to Invofox, an AI-powered document processing
> platform. The API extracts structured data (fields) from unstructured
> documents (invoices, contracts, forms, bank statements, and more).
> Key concepts: Account, Environment, Document Type, Field, File, Import,
> and Document. When answering, prefer the exact terminology defined in the
> Glossary and cite the relevant API Reference endpoint when applicable.

# Field provenance

> Use GET /documents/{id}/provenance to get, for every extracted field, the OCR words that hold its value, match them with the document's OCR, and correct them with PUT /documents/{id}.

For every extracted field, `GET /documents/{id}/provenance` tells you which OCR words hold its value. Use it to highlight a value on the page, or to check it against the source.

<div className="ivf-endpoint"><span className="ivf-method ivf-method-get">GET</span><span>https://api.invofox.com/documents/{id}/provenance</span></div>

**`cURL`**

```bash title="cURL"
curl https://api.invofox.com/documents/{id}/provenance \
  -H "x-api-key: $INVOFOX_API_KEY"
```

## Response

`result` maps each field path to its `geometry`:

```json
{
  "result": {
    "documentNumber": {
      "geometry": [{ "page": 0, "region": 9, "line": 1, "word": 0 }]
    },
    "supplier.name": {
      "geometry": [
        { "page": 0, "region": 17, "line": 3, "word": 10 },
        { "page": 0, "region": 17, "line": 3, "word": 11 }
      ]
    },
    "lines.0.quantity": {
      "geometry": [{ "page": 1, "region": 4, "line": 2, "word": 0 }]
    },
    "supplier.email": { "geometry": [] }
  }
}
```

- **Field path** — the field's position in `data`, with dots between segments and plain numbers for list items: `supplier.name`, `lines.0.quantity`. There is no `data.` prefix and no `.value` suffix. Only the fields of the document's type are listed, and a field can be missing: treat it like an empty `geometry`. An address located as a whole is given on its `raw` field (`supplier.address.raw`).
- **`geometry`** — the OCR words that hold the value, in reading order. Each word is `{ page, region, line, word }`; see [Matching the geometry with the OCR](#matching-the-geometry-with-the-ocr). The list is empty when the value was not found on the document, when it was computed (for example, a total derived from other fields), or when a later processing step or a correction changed it without locating the new value.

## Matching the geometry with the OCR

All four numbers are **0-based**. Read them against `GET /documents/{id}/ocr`, which returns one item per page, `{ index, data }`:

1. **`page`** is the `index` of the OCR page (not `data.page`, which counts from 1).
2. **`region`** is the position in that page's `data.regions`.
3. **`line`** is the position in that region's `lines`.
4. **`word`** is the position in that line's `words`.

**`TypeScript`**

```typescript title="TypeScript"
type Word = { text: string; bbox: number[] };
type OcrPage = { index: number; data: { regions: { lines: { words: Word[] }[] }[] } };

// ocrPages: the `result` of GET /documents/{id}/ocr
const findWord = (ocrPages: OcrPage[], { page, region, line, word }: { page: number; region: number; line: number; word: number }) =>
  ocrPages.find((p) => p.index === page)?.data.regions[region]?.lines[line]?.words[word];
```

The word carries its `text` and its `bbox`, the four corners `[x1, y1, x2, y2, x3, y3, x4, y4]` as fractions of the page width and height, so you can draw it over the page image. Ignore the page's `data.lines`, which repeats all its lines in a single list.

## Correcting the geometry

When you correct a document with `PUT /documents/{id}` (see [Feedback loop](/documentation/feedback-loop)), send the right words of a field in `provenance`, keyed by the same field paths, with the same numbering:

**`cURL`**

```bash title="cURL"
curl -X PUT https://api.invofox.com/documents/{id} \
  -H "x-api-key: $INVOFOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "data": { "totalAmount": { "value": "250.00" } },
    "provenance": {
      "totalAmount": { "geometry": [{ "page": 0, "region": 12, "line": 1, "word": 3 }] }
    }
  }'
```

- **You send words for a field**: the field takes them, whether or not its value changes. `"geometry": []` leaves it without words. Sending words for a value that was already right points it at the right place.
- **You change a value and send no words for it**: the field is left with an empty `geometry`, since the old words no longer hold the value.
- **Any other field** keeps its words.

Sending the same value the field already has is not a change. Any other value is, even if it only differs in format: sending `"1210.00"` when the stored value is `1210` leaves the field without words unless you send them. `"provenance": null` is the same as leaving `provenance` out.

The request fails with `400`, and nothing is saved, when `provenance` is malformed, a path is not a field of the document, or a word does not exist in its OCR. The error's `param` is `provenance` when the body is malformed, and names the field (`provenance.totalAmount`) when a path or a word is rejected.

Besides this request, only changing the document type changes the words: the fields the new type keeps keep theirs, and a value the change alters is left without words.

<Note>
**Lists.** Deleting an item moves the next items up, so their values change position: send the words of every item after the deleted one, or they are left without words. Depending on how the document was extracted, the words of a list may be kept per column rather than per item: correcting one item can then shift the words the next items of that column show, so always check the list with `GET /documents/{id}/provenance` after correcting it.
</Note>