PDF to XRechnung · ZUGFeRD · EN 16931
PDF invoice to XRechnung API
Send a plain PDF invoice, get a validated EN 16931 draft (XRechnung, UBL) with a confidence score for every field. Same page in Deutsch.
No card needed. The result is always a draft for review before you send it.
Short answer: POST /einvoice/extract reads the text layer of a PDF invoice with AI, maps the fields into the JSON of /einvoice/create and builds an XRechnung that is validated against CEN EN 16931 and the KoSIT rules. Every field has a confidence score, the totals are recomputed, and the result is marked draft_for_review.
What the endpoint does
- PDF in, draft out. XRechnung (UBL), EN 16931 or Peppol BIS 3 from a PDF with a text layer. A ZUGFeRD/Factur-X PDF is not re-read; it is pointed to
/einvoice/parse. - Confidence per field. Model score plus checks: value found in the PDF text, VAT ID format, IBAN checksum, guessed country.
- Arithmetic check. Totals are recomputed from the lines and compared with the printed totals.
- Formal validation. As with
/einvoice/create: XML schema, EN 16931 and KoSIT XRechnung 3.0.2, with a rule ID and a fix hint for each error.
Example
$KEY is your API key. While you evaluate the endpoint, use test PDFs with synthetic data.
# Needs an API key. Send a plain PDF invoice (text layer), get a draft back
curl -s -X POST "https://api.wsystem.dev/einvoice/extract?format=xrechnung" \
-H "X-API-Key: $KEY" -H "Content-Type: application/pdf" \
--data-binary @invoice.pdf > draft.json
# What to look at first
jq '{status, low: .review.low_confidence, arith: .arithmetic_check.all_match, valid: .validation.valid}' draft.json
# The XML is built only if the amounts add up to the printed totals; check the fields first
jq -r .xml draft.json > INV-2026-001.xmlShape of the response, trimmed, with made-up synthetic values. The example shows the case that matters: the amounts do not add up to the printed totals, so the status is needs_review_amounts and no XML is built. When everything adds up the status is draft_for_review and the response includes the XML and the validation result.
{
"status": "needs_review_amounts",
"review_required": true,
"format": "xrechnung",
"fields": [
{
"path": "invoice_number",
"value": "RE-2026-0815",
"confidence": 0.98,
"checks": [
"found_in_pdf_text"
]
},
{
"path": "lines.1.unit_price_net",
"value": 778,
"confidence": 0.5,
"checks": [
"found_in_pdf_text",
"totals_mismatch"
]
}
],
"review": {
"low_confidence": [
"lines.1.unit_price_net"
],
"blocked": "extracted amounts do not match the printed totals; fix the lines, then POST the invoice JSON to /einvoice/create"
},
"arithmetic_check": {
"all_match": false,
"rows": [
{
"check": "sum of line nets (BT-106/109)",
"computed": "1556.00",
"printed": "778.00",
"match": false
}
]
},
"xml": null,
"disclaimer": "AI-extracted draft for review. Fields can be wrong or missing even when the invoice validates; check every value against the source PDF."
}Honest numbers from our tests
We built the extractor on 20 synthetic German invoices supplied by a software maker, then tested it on three further synthetic sets of 20 invoices each that we generated ourselves in other layouts, languages and currencies. Every field was checked against an answer key fixed in advance. We used the earlier test rounds to improve the extractor, so only the latest set was unseen by it.
- Development set (20 invoices): 19 of 20 fully correct on the live endpoint (1,112 of 1,113 fields, 99.9%). The first version got 12 of 20.
- Latest unseen test (20 invoices, 14 languages, 8 currencies, credit notes, sellers printed only in the footer): 19 of 20 fully correct. That is after correcting four errors in our own answer key (verified in the PDF text); as first graded it was 15 of 20.
- Two earlier unseen rounds scored 15 of 20 and 10 of 20. Their errors (credit-note signs, swapped seller/buyer, unit codes, postcodes) were fixed; the later rounds show the effect.
- “Fully correct” means every graded field is right. All invoices are synthetic, not real customer invoices; accuracy on real invoices can vary by layout.
- The arithmetic check blocks the XML when amounts do not match the printed totals. A schematron-valid XRechnung can still be wrong (in the first test: a total of 1,556.00 instead of 778.00).
- Built only from the extracted data, 0 of 20 were valid as XRechnung in the first test, because data the PDFs do not contain was missing (seller contact, e-mail addresses, mandate reference). With such master data from a company profile, 12 of 20 were valid. Expect your software to add master data. The result stays a draft for you to review before sending.
Data protection and limits
- The PDF text is sent to OpenAI for processing (subprocessor, see the DPA and privacy policy). Use it only if you may do that with your invoices.
- No OCR: scanned images are rejected.
- Not a certification, and not legal or tax advice.
Price
80 units per successful extraction: €0.157 on Pro (€49 for 25,000 units) and €0.304 on Starter (€19 for 5,000 units). Failed extractions are not charged. The free key includes 3 extractions a month to try it; after that a paid plan is needed. Platform plan keys use 80 of the plan's 25,000 fair-use units. Pricing
Questions
Is the result a finished e-invoice?
No. It is a draft for review. Every response has status draft_for_review. AI can misread or invent values, and a file can pass the KoSIT and EN 16931 rules and still carry wrong amounts. A person should check low-confidence fields against the PDF before the invoice is sent or booked.
What does the confidence score mean?
Each extracted field gets a score from 0 to 1. It combines the model's own score with deterministic checks: is the value in the PDF text, does the VAT ID have a valid format, does the IBAN checksum pass, was the country guessed. Fields below 0.8 are listed in review.low_confidence. It is a prioritisation aid, not a guarantee.
What is the arithmetic check?
The API recomputes line totals, net, VAT and gross from the extracted lines and compares them with the totals printed on the invoice. A mismatch lowers the confidence of the affected line fields, shows up in arithmetic_check and sets the status to needs_review_amounts; then no XML is built. In our first test it caught 3 of the 8 invoices with a wrong field. It cannot see wrong references or codes.
Which PDFs work?
PDFs with a text layer, up to 10 MB. Scanned images have no text layer and return 422 no_text_layer; OCR is not supported yet. A ZUGFeRD or Factur-X PDF already contains the data, so it is pointed to /einvoice/parse, which reads the embedded XML exactly.
Where is my PDF processed?
The text of the PDF is sent to OpenAI to read the fields. This is listed as a subprocessor in our DPA, and you should only send invoices you are allowed to process this way. Details: /legal/dpa and /privacy.
What does it cost?
80 units per successful extraction: €0.157 on Pro (€49 for 25,000 units) and €0.304 on Starter (€19 for 5,000 units). Failed extractions are not charged. The free key includes 3 extractions a month to try it; after that a paid plan is needed. Platform plan keys use 80 of the plan's 25,000 fair-use units. It needs an API key (not available without one or over x402).
Related
Technical check, not legal or tax advice.