> ## Documentation Index
> Fetch the complete documentation index at: https://docs.levanto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenRouter Extractions API

> Sage extraction in OpenRouter's Extractions format.

If your code already calls OpenRouter's `POST /api/alpha/extractions`, change the base URL to `https://api.levanto.ai` and use your Levanto key. Set `model` to `levanto-sage-2` or `sage-latest`. It runs the same extraction as [`/v1/extract`](https://docs.levanto.ai/extract).

## Request

```bash theme={"theme":"github-light"}
curl -s https://api.levanto.ai/api/alpha/extractions \
  -H "Authorization: Bearer $LEVANTO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "sage-latest",
  "state": "Invoice INV-2291 issued 2026-09-02, net 30. Contacts: Dana Ruiz, Priya Shah. Total $1080.",
  "fields": {
    "invoice_number": {"type": "text"},
    "issued": {"type": "date"},
    "total": {"type": "number", "decimals": 2, "unit": "USD"},
    "contacts": {"type": "list", "items": "text", "instructions": "A contact person"}
  }
}'
```

```json theme={"theme":"github-light"}
{
  "answers": {
    "invoice_number": {"type": "text", "value": "INV-2291", "guess": "INV-2291", "p_null": 0.0001,
                       "confidence": 0.9999, "span": [8, 16], "text": "INV-2291"},
    "issued": {"type": "date", "value": "2026-09-02", "guess": "2026-09-02", "p_null": 0.0136,
               "confidence": 0.9864, "span": [24, 34], "text": "2026-09-02"},
    "total": {"type": "number", "value": 1080.0, "guess": 1080.0, "p_null": 0.0009,
              "confidence": 0.9991, "span": [83, 88], "text": "$1080", "currency": "USD"},
    "contacts": {"type": "list", "value": ["Dana Ruiz", "Priya Shah"], "spans": [[54, 63], [65, 75]],
                 "confidences": [0.9638, 0.9491], "texts": ["Dana Ruiz", "Priya Shah"]}
  },
  "model": "levanto-sage-2",
  "truncated": false,
  "usage": {"input_tokens": 219, "output_tokens": 244, "passes": 1}
}
```

| Member | Meaning |
| - | - |
| `state` | The text to read. |
| `fields` | `{name: field}`. Names are unique ignoring case and `_`. |
| `reference_date` | `YYYY-MM-DD`. Fills in the year of a date written without one: the nearest such date. With `2026-10-28`, `15 November` reads as `2026-11-15`. |

## Field types

Every field takes `instructions` (what it should contain, up to 4,000 characters; a question works too) and `null_threshold`.

| `type` | Options |
| - | - |
| `text` | |
| `number` | `integer`: whole numbers only. `decimals`: decimal places kept, 0 to 6. `unit`: a currency (`USD`, `$`, `euros`) reads the amount in that currency; any other unit is a label. |
| `date`, `time`, `datetime` | |
| `duration` | `unit` (`seconds` to `years`) converts to a number in that unit, with a month as 30 days and a year as 365. Without it, an ISO 8601 duration such as `P3Y`. `integer` and `decimals` need `unit`. |
| `list` | `items`: the type of each item, any of the above. `unit`, `integer` and `decimals` apply to the items. |

## Answers

`answers` has one entry per field, keyed by its name.

| Member | Meaning |
| - | - |
| `value` | The value, or `null` when `p_null` is above the field's `null_threshold` (default 0.5). |
| `guess` | The most likely value either way. |
| `p_null` | How likely it is that there is no value. |
| `confidence` | How likely the value is right. |
| `span` | `[start, end)`: where it was read in `state`, in Unicode code points. |
| `text` | The text it was read from. |
| `currency` | A number read as money: the ISO 4217 code stated, `null` when none is. |
| `unit` | A converted duration: the unit it is in. |

With a currency `unit`, an amount stated in another currency gives `value: null`, the amount in `guess` and the stated `currency`. `Total due: 540.00 EUR.` read with `"unit": "USD"`:

```json theme={"theme":"github-light"}
{"type": "number", "value": null, "guess": 540.0, "p_null": 0.0078, "currency": "EUR"}
```

A `list` answer has `value`, `spans`, `confidences` and `texts`, one entry per item.

The response also carries `model` and `usage`: `input_tokens`, `output_tokens` and `passes`.

## Options

Sage's own options go under `provider.options.levanto`, or at the top level of the body.

| Option | What it does |
| - | - |
| `return_state_text` | Returns `state` as `state_text`, the text the spans index. |
| `candidates` | Adds `candidates` to each answer: every candidate with its span and probability. |

```json theme={"theme":"github-light"}
{
  "model": "sage-latest",
  "state": "Acme Corp. signed a three (3) year lease with Beacon Realty on 2 May 2026. Notice: 90 days.",
  "fields": {
    "term_months": {"type": "duration", "unit": "months", "integer": true},
    "notice": {"type": "duration", "unit": "days"},
    "signed": {"type": "date", "null_threshold": 0.3},
    "parties": {"type": "list", "items": "text", "instructions": "Companies that sign"}
  },
  "provider": {
    "options": {
      "levanto": {"return_state_text": true, "candidates": true}
    }
  }
}
```

One answer from the response. `p_null` is above 0.5, so `value` is `null` and `guess` still carries the 36 months:

```json theme={"theme":"github-light"}
"term_months": {
  "type": "duration", "value": null, "guess": 36, "p_null": 0.5142, "unit": "months",
  "candidates": [
    {"value": 36, "text": "three (3) year lease", "span": [20, 40], "probability": 0.4858}
  ]
}
```

## Differences from OpenRouter

* `estimate` and `forecast` fields, `assets` and `questions` return 400. Send questions to [`/v1/systemone`](https://docs.levanto.ai/systemone).
* Unknown keys return 400. `session_id`, `user` and `trace` are accepted and ignored.

## Limits and errors

* Up to 64 fields are read at once. With more, the text is read again, and charged again, for each further 64 (`usage.passes`).
* The state plus the field definitions of one read: up to 16,384 tokens. Longer returns **413**.
* Errors use OpenRouter's body. See [Errors](https://docs.levanto.ai/reference/errors.md#openrouter-extractions).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.