> For the complete documentation index, see [llms.txt](https://typless.gitbook.io/typlessapi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://typless.gitbook.io/typlessapi/automation-use-cases/pretrained-invoice.md). Agents can also search and read this documentation through its [MCP server](https://typless.gitbook.io/typlessapi/~gitbook/mcp).

# Pretrained invoice

Extracting invoice data and VAT rates with a pretrained model, without training, with examples in Python and Node.

### Overview

This guide covers how to extract metadata and VAT rates from invoices of any supplier with examples in **Python** and **Node**. For this example, we will use the **Pretrained model**: there is no dataset to build and no training, so the first invoice of a new supplier is extracted as well as the hundredth.\
You will extract the following fields:

* Supplier and buyer name and VAT ID
* Invoice number, payment reference, IBAN and payment purpose code
* Invoice date, payment due date and service date
* Net, VAT and total amount, and currency
* Purchase orders
* VAT rates

**This guide shows you how to**

1. [Create a pretrained invoice document type](#id-1.-create-a-new-document-type)
2. [Extract data from documents](#id-2.-extract-data-from-documents)
3. [Get the results with a webhook](#id-3.-get-the-results)
4. [Confirm the correct values](#id-4.-confirm-the-correct-values)

## Get your API Key

The *Authorization* header for your API key is: `Token YOUR-API-KEY` ([Login](https://app.typless.com/login/?redirect=https://docs.typless.com/) if you do not see one).\
You can also obtain the **API key** by visiting the [API Keys page](https://app.typless.com/settings/api-keys).

<figure><img src="https://2174127710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FePXqOCeLb4FOuZhmYG8X%2Fuploads%2Fgit-blob-05bd0b7a3f05edcaa4e7e94708a8c16da9596015%2Fimage.png?alt=media" alt=""><figcaption><p>Getting your API key</p></figcaption></figure>

## 1. Create a new document type

Before you start extracting data, you need to define a document type. Navigate to the [Document types page](https://app.typless.com) and click on the ***New document type*** button in the top right corner. Next, click ***Select Pretrained*** on the ***Pretrained model*** card, followed by ***Choose Template*** on ***Use a Predefined Template***. Then, click on the ***Metadata invoice*** card. The wizard pre-fills all the [extraction fields](https://typless.gitbook.io/typlessapi/typless/extraction-fields.md), each with a [preset and a description](https://typless.gitbook.io/typlessapi/typless/document-type/descriptions-and-presets.md).

Before you click ***Create document type***:

1. Change the ***Name*** to **pretrained-invoice**.
2. Enter a ***Description*** of your documents, for example *Invoices from different suppliers.*
3. In ***Plugins***, check ***Extract vat rates***. It uses the fields with the ***Net Amount*** and ***Total Amount*** presets, which the template already has.

This creates the document type **pretrained-invoice** with the following fields:

* **`supplier_name`**, **`supplier_vat_id`**, **`buyer_name`**, **`buyer_vat_id`**
* **`invoice_number`**, **`payment_reference`**, **`IBAN`** (multiple values), **`payment_purpose_code`**
* **`invoice_date`**, **`payment_due_date`**, **`service_date`**
* **`net_amount`**, **`vat_amount`**, **`total_amount`**, **`currency`**
* **`purchasing_order`** (multiple values)

The document type is ready right away: its status is ***Training not required***.

{% hint style="info" %}
Need a field the template doesn't have? Click ***Add field***, choose a ***Preset*** if one fits, and write a ***Description*** that tells the model what to look for. See [Descriptions and presets](https://typless.gitbook.io/typlessapi/typless/document-type/descriptions-and-presets.md).
{% endhint %}

## 2. Extract data from documents

Pretrained models extract data asynchronously. You can send the file content in `file`, or let Typless download it from a URL in `file_url`, for example a presigned link to the file in your storage. Here we use the public demo invoice from Amazing Company:

* [Amazing Company - download](https://typless-public.s3-eu-west-1.amazonaws.com/use_cases/metadata-invoice/amazing_company_1.pdf)

<details>

<summary><strong>1 Create payload</strong> <em><mark style="color:green;">(Lines 3-7)</mark></em></summary>

* `document_type_name` - the document type you just created
* `file_name` - name of the file, with a supported extension
* `file_url` - a public `https` URL of the file (or `file` with the base64 content)

</details>

<details>

<summary><strong>2 Specify headers</strong> <em><mark style="color:green;">(Lines 9-13)</mark></em></summary>

Put your API key, prepended with the word Token, in the Authorization header.

</details>

<details>

<summary><strong>3 Start the extraction</strong> <em><mark style="color:green;">(Lines 15-17)</mark></em></summary>

The response is `202 Accepted` with the `extraction_id`. Store it with your document so you can match the result to it.

</details>

{% tabs %}
{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
import requests

payload = {
    "document_type_name": "pretrained-invoice",
    "file_name": "amazing_company_1.pdf",
    "file_url": "https://typless-public.s3-eu-west-1.amazonaws.com/use_cases/metadata-invoice/amazing_company_1.pdf"
}

headers = {
    "Accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": "<<apiKey>>"
}

url = "https://developers.typless.com/api/v1/extract-data-async"
response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

{% endcode %}
{% endtab %}

{% tab title="Node" %}

```javascript
const payload = {
  document_type_name: 'pretrained-invoice',
  file_name: 'amazing_company_1.pdf',
  file_url: 'https://typless-public.s3-eu-west-1.amazonaws.com/use_cases/metadata-invoice/amazing_company_1.pdf'
};

const headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json',
  'Authorization': '<<apiKey>>'
};

fetch('https://developers.typless.com/api/v1/extract-data-async', {
  method: 'POST',
  headers: headers,
  body: JSON.stringify(payload)
})
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));
```

{% endtab %}
{% endtabs %}

Response:

{% tabs %}
{% tab title="JSON" %}

```json
{
    "extraction_id": "177a264b4d832343fc442d6a116d01109c744e48"
}
```

{% endtab %}
{% endtabs %}

## 3. Get the results

Instead of polling, let Typless tell you when the extraction is finished. In the Typless hub, open ***Settings*** → ***Webhooks***, click ***Add webhook***, enter the URL of your endpoint and choose the **pretrained-invoice** document type. See [Webhooks](https://typless.gitbook.io/typlessapi/typless-hub/webhooks.md).

When the extraction is finished, your endpoint gets an `extraction.finished` message. Its `data.id` is the `extraction_id`; use it to fetch the result:

{% tabs %}
{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
# A minimal webhook endpoint with Flask
import requests
from flask import Flask, request

app = Flask(__name__)
headers = {"Authorization": "<<apiKey>>"}


@app.post("/typless-webhook")
def typless_webhook():
    message = request.get_json()
    if message["type"] == "extraction.finished":
        url = "https://developers.typless.com/api/v2/get-extraction-data"
        result = requests.get(url, headers=headers, params={"extraction_id": message["data"]["id"]}).json()
        if result["status"] == "SUCCESS":
            for field in result["result"]["extracted_fields"]:
                print(field["name"], field["values"][0]["value"])
    return "", 200
```

{% endcode %}
{% endtab %}

{% tab title="Node" %}

```javascript
// A minimal webhook endpoint with Express (Node.js 18 or newer)
const express = require('express');

const app = express();
app.use(express.json());
const headers = { 'Authorization': '<<apiKey>>' };

app.post('/typless-webhook', async (req, res) => {
  res.sendStatus(200);
  const message = req.body;
  if (message.type !== 'extraction.finished') return;
  const url = `https://developers.typless.com/api/v2/get-extraction-data?extraction_id=${message.data.id}`;
  const result = await (await fetch(url, { headers })).json();
  if (result.status === 'SUCCESS') {
    result.result.extracted_fields.forEach(field => console.log(`${field.name}: ${field.values[0].value}`));
  }
});

app.listen(3000);
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
A message can arrive more than once, and it is also sent for extractions that failed. Process each `event_id` once and check the `status` of the result.
{% endhint %}

Response from `get-extraction-data` for an invoice with two VAT rates (shortened to five fields):

{% tabs %}
{% tab title="JSON" %}

```json
{
  "status": "SUCCESS",
  "error": {},
  "result": {
    "object_id": "177a2167dfa242eb5276333d755265eb5221b34b",
    "file_name": "harborpine-catering-0077.pdf",
    "customer": null,
    "extracted_fields": [
      {
        "name": "supplier_name",
        "data_type": "AUTHOR",
        "values": [
          {
            "x": 124,
            "y": 132,
            "width": 1023,
            "height": 85,
            "page_number": 0,
            "value": "Harborpine Catering d.o.o.",
            "confidence_score": 0.95
          }
        ],
        "multiple_values": false
      },
      {
        "name": "invoice_number",
        "data_type": "STRING",
        "values": [
          {
            "x": 1908,
            "y": 228,
            "width": 449,
            "height": 41,
            "page_number": 0,
            "value": "HC-0077/2026",
            "confidence_score": 0.95
          }
        ],
        "multiple_values": false
      },
      {
        "name": "invoice_date",
        "data_type": "DATE",
        "values": [
          {
            "x": 1906,
            "y": 275,
            "width": 417,
            "height": 38,
            "page_number": 0,
            "value": "2026-10-21",
            "confidence_score": 0.95
          }
        ],
        "multiple_values": false
      },
      {
        "name": "total_amount",
        "data_type": "NUMBER",
        "values": [
          {
            "x": 2066,
            "y": 1329,
            "width": 280,
            "height": 50,
            "page_number": 0,
            "value": "300.1200",
            "confidence_score": 0.95
          }
        ],
        "multiple_values": false
      },
      {
        "name": "currency",
        "data_type": "STRING",
        "values": [
          {
            "x": -1,
            "y": -1,
            "width": -1,
            "height": -1,
            "page_number": -1,
            "value": "EUR",
            "confidence_score": 0.95
          }
        ],
        "multiple_values": false
      }
    ],
    "line_items": [],
    "vat_rates": [
      [
        {
          "name": "vat_rate_percentage",
          "data_type": "NUMBER",
          "values": [
            {
              "x": -1,
              "y": -1,
              "width": -1,
              "height": -1,
              "page_number": -1,
              "value": "13.0000",
              "confidence_score": 0
            }
          ],
          "multiple_values": false
        },
        {
          "name": "vat_rate_net",
          "data_type": "NUMBER",
          "values": [
            {
              "x": -1,
              "y": -1,
              "width": -1,
              "height": -1,
              "page_number": -1,
              "value": "174.0000",
              "confidence_score": 0
            }
          ],
          "multiple_values": false
        },
        {
          "name": "vat_rate_vat",
          "data_type": "NUMBER",
          "values": [
            {
              "x": -1,
              "y": -1,
              "width": -1,
              "height": -1,
              "page_number": -1,
              "value": "22.6200",
              "confidence_score": 0
            }
          ],
          "multiple_values": false
        }
      ],
      [
        {
          "name": "vat_rate_percentage",
          "data_type": "NUMBER",
          "values": [
            {
              "x": -1,
              "y": -1,
              "width": -1,
              "height": -1,
              "page_number": -1,
              "value": "25.0000",
              "confidence_score": 0
            }
          ],
          "multiple_values": false
        },
        {
          "name": "vat_rate_net",
          "data_type": "NUMBER",
          "values": [
            {
              "x": -1,
              "y": -1,
              "width": -1,
              "height": -1,
              "page_number": -1,
              "value": "82.8000",
              "confidence_score": 0
            }
          ],
          "multiple_values": false
        },
        {
          "name": "vat_rate_vat",
          "data_type": "NUMBER",
          "values": [
            {
              "x": -1,
              "y": -1,
              "width": -1,
              "height": -1,
              "page_number": -1,
              "value": "20.7000",
              "confidence_score": 0
            }
          ],
          "multiple_values": false
        }
      ]
    ],
    "number_of_pages": 1,
    "markdown_content": null,
    "text_blocks": null,
    "adjusted_s3_url": null,
    "supplier_id": null
  }
}
```

{% endtab %}
{% endtabs %}

Values are returned in the standard format of their field type: dates as `YYYY-MM-DD`, numbers with 4 decimals, the currency as an ISO 4217 code. Every VAT rate has `vat_rate_percentage`, `vat_rate_net` and `vat_rate_vat`, see [VAT rate plugin](https://typless.gitbook.io/typlessapi/typless/plugins/vat-rate-plugin.md).

{% hint style="info" %}
**Need a more in-depth explanation of the response?**\
You can read about it [here](https://typless.gitbook.io/typlessapi/typless/data-extraction.md#understanding-response).
{% endhint %}

## 4. Confirm the correct values

When your users have checked an invoice, send the correct values back with [**add-document-feedback**](https://typless.gitbook.io/typlessapi/api-docs/api-schema.md#api-add-document-feedback) and the [**object\_id**](https://typless.gitbook.io/typlessapi/typless/data-extraction.md#response-base-params) of the result. Send every field of the document type, with `""` for fields that are not on the invoice.

Feedback doesn't retrain a pretrained model, but it creates the invoice's **supplier** in your document type. Once a supplier exists, you can give it a description that fixes its quirks for all its next invoices. The [Supplier descriptions](https://typless.gitbook.io/typlessapi/automation-use-cases/supplier-descriptions.md) use case shows how.

## Running Typless live

The only thing that you need to do to automate your manual data entry is to integrate those simple API calls into your system.

{% hint style="success" %}
Have any questions, or do you need some help? Contact us via email <mark style="color:green;">**<support@typless.com>**</mark>**.**
{% endhint %}
