---
title: "Extract invoice data from PDF or image using AI"
method: POST
path: "/api/xrechnung/extract"
tags: ["XRechnung"]
---

# Extract invoice data from PDF or image using AI

`POST /api/xrechnung/extract`

## Request

- Base URL: `https://api.dokmatiq.com`
- URL: `https://api.dokmatiq.com/api/xrechnung/extract`
- Auth: API key in header `X-API-Key`

Extracts structured invoice data from a PDF invoice or photo (JPG, PNG) using the configured AI provider.

The endpoint handles two input types:
- **Text-based PDF**: Extracts text with PDFBox, sends it to AI for structured extraction
- **Scanned PDF / Photo**: Sends the file to an AI vision-capable provider for OCR + extraction

Returns structured InvoiceData as JSON, ready to pass to /generate or /zugferd/embed.
Missing fields (e.g. Leitweg-ID) are listed in `missingFields` — these should be
filled from user profile data in the portal before generating the e-invoice.

Configure one provider with `AI_PROVIDER` plus `OPENAI_API_KEY`, `GEMINI_API_KEY`,
`ANTHROPIC_API_KEY`, or `OPENROUTER_API_KEY`. Without a configured provider, only
PDF/DOCX text extraction is performed and `aiExtractionUsed` will be false.

## Response `200`

OK

---

[API](https://skmtc.dev/dokmatiq/apis/docgen-api.md) · [All operations](https://skmtc.dev/dokmatiq/apis/docgen-api/llms.txt) · [OpenAPI document](https://skmtc.dev/dokmatiq/apis/docgen-api/revisions/3fa1a922764d?raw)
