A small, self-hosted HTTP service that reads incoming German and European e-invoices and returns one uniform JSON document, whatever the input format, and validates them in the same call:
- ZUGFeRD 2.x / Factur-X PDFs (CII XML embedded in a PDF/A-3), all profiles from MINIMUM to EXTENDED
- XRechnung 3.x as CII or UBL XML (Invoice and CreditNote)
- Plain EN 16931 CII or UBL XML
Amounts come straight from the XML and are never recalculated. Validation uses the official rule sets: XSD, the KoSIT validator configuration for XRechnung and EN 16931 (same scenarios and severity overrides as the official KoSIT validator), and the Factur-X Schematron per profile.
docker run -p 127.0.0.1:8080:8080 -e API_KEY=change-me ghcr.io/effizienzagent/einvoice-reader:latest
curl -F file=@invoice.pdf http://localhost:8080/v1/invoices/parseFor production, pin a version from the releases instead of latest and upgrade on purpose: a new version can bring updated validation rules that change valid for the same invoice.
The OpenAPI documentation is at http://localhost:8080/docs.
| Endpoint | Purpose |
|---|---|
POST /v1/invoices/parse |
Read and validate one invoice |
GET /v1/health |
Health check, always open |
GET /v1/info |
Service version and rule set versions |
POST /v1/invoices/parse accepts the file in either of two ways:
- as
multipart/form-datain the fieldfile - as the raw request body (
application/pdf,application/xml,text/xml)
The service detects the format from the content, not from the file name.
Query parameters:
validate(defaulttrue): set tofalseto skip validation.include_xml(defaulttrue): set tofalseto leave out the original XML.
Responses:
| Status | Meaning |
|---|---|
200 |
Invoice read. Check validation.valid and validation.isEInvoice. An invalid but readable invoice still returns 200. |
422 |
No e-invoice could be read. error.code is one of the values below. |
400 |
Malformed multipart body (BAD_REQUEST) |
401 |
API_KEY is set and the X-API-Key header is missing or wrong |
408 |
Upload took longer than READ_TIMEOUT_S (REQUEST_TIMEOUT) |
413 |
File larger than MAX_UPLOAD_MB |
503 |
Too many documents queued (SERVICE_BUSY); retry later |
error.code values for 422:
| Code | Meaning | Typical next step |
|---|---|---|
NO_EMBEDDED_XML |
Not an e-invoice: a PDF without invoice XML, an image, an Office file, HTML, a scan, XML that is not an invoice | Send to OCR |
MALFORMED_PDF |
The PDF cannot be opened | Send to OCR |
UNSUPPORTED_FORMAT |
An e-invoice family document this service does not read: ZUGFeRD 1.0, Order-X, other UBL documents | Manual check |
MALFORMED_XML |
An XML invoice that is not well-formed or contains a DOCTYPE | Ask the supplier for a corrected file |
READ_FAILED |
A recognised CII/UBL invoice that could not be mapped | Manual check |
EMPTY_FILE |
The file is empty, or the multipart body has no file field |
Check the upload |
PROCESSING_TIMEOUT |
Reading the document took longer than PARSE_TIMEOUT_S |
Manual check; do not retry automatically |
PROCESSING_FAILED |
Reading this document crashed the reader | Manual check; do not retry automatically |
{
"format": { "syntax": "CII", "container": "PDF", "documentType": "Invoice",
"standard": "XRechnung", "profile": "XRECHNUNG", "version": "3.0",
"customizationId": "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0",
"embeddedFileName": "factur-x.xml" },
"invoice": {
"number": "123456XX", "type": "invoice", "isCreditNote": false, "issueDate": "2016-04-04", "currency": "EUR",
"seller": { "name": "[Seller name]", "vatId": "DE 123456789", "...": "..." },
"totals": { "netTotal": 314.86, "vatTotal": 22.04, "grossTotal": 336.9, "amountDue": 336.9, "...": "..." },
"vatBreakdown": [ { "categoryCode": "S", "rate": 7.0, "taxableAmount": 314.86, "taxAmount": 22.04 } ],
"lines": [ "..." ]
},
"validation": { "performed": true, "valid": true, "isEInvoice": true,
"ruleSets": ["XSD CII", "EN16931 CII (KoSIT 2026-08-31)", "XRechnung CII 3.0.2 (KoSIT 2026-08-31)"],
"messages": [] },
"warnings": [],
"xml": "<?xml ...",
"meta": { "serviceVersion": "0.1.0" }
}Every key is always present. Missing values are null and missing lists are []. Dates are YYYY-MM-DD. The full field list is in the design document.
Things to know when you book from this data:
isEInvoiceisfalsefor ZUGFeRD/Factur-X MINIMUM and BASIC WL, because German law does not accept those profiles as e-invoices. Filter onisEInvoice, not onvalid.validandisEInvoicecan benull. That happens whenvalidate=false, or when validation could not run in time (validation.performedisfalse, andwarningssays why). Treatnullas "unknown, check again", never asfalse.- Credit notes keep the amounts as written, usually positive. Use
isCreditNote(ortype) to flip the sign yourself. A credit note that already carries negative amounts must not be flipped again. - Several bank accounts are all listed in
payment.accounts. Ifpayeeis set, the accounts belong to the payee (factoring), not the seller. On credit notes the account can be your own (the buyer's) account to receive the refund. - IBAN and BIC are returned without spaces and in upper case. A value that does not look like an IBAN (for example a proprietary account number) stays as written. An IBAN that fails its checksum still comes through, but with a warning.
payment.meansCode59 means SEPA direct debit: the supplier collects, do not transfer.- Sub-lines: lines with a
parentLineIdare sub-lines (ZUGFeRD EXTENDED, XRechnung extension CII). Do not add them on top of their parent, and never sum lines withlineStatusReasonCodeINFORMATION; usetotalsfor amounts. UBLSubInvoiceLines are not listed (a warning says so). - Booking references:
buyerAccountingReference(BT-19),invoicedObjectIdentifier(BT-18, e.g. a VIN or contract), and per lineaccountingReference,objectIdentifier,attributesandclassifications. warningslists everything the reader had to repair or ignore: unreadable dates, repeated fields, invalid currency codes, a second invoice XML in the PDF,BT-115not matching the other totals.
Add an HTTP Request node and configure it like this:
- Method:
POST - URL:
http://einvoice-reader:8080/v1/invoices/parse - Body Content Type:
Form-Data - Body parameter: type
n8n Binary File, namefile, input data fielddata(or whichever field holds your file) - If you check the
422codes yourself: Options → Response → enable Include Response Headers and Status and Never Error - Route
422withNO_EMBEDDED_XMLorMALFORMED_PDFto your OCR branch, every other422to manual review. Retry only503, with a pause.
| Variable | Default | Meaning |
|---|---|---|
MAX_UPLOAD_MB |
20 |
Upload limit |
API_KEY |
unset | When set, requests need the header X-API-Key |
LOG_LEVEL |
INFO |
Python log level; the service does not log invoice content |
PARSE_TIMEOUT_S |
30 |
Hard time limit for reading one document (PDF, XML, mapping, XSD) |
PARSE_WORKERS |
2 |
Processes that read documents in parallel |
PARSE_MEMORY_MB |
1024 |
Memory limit per parser process (Linux); a document that needs more ends with PROCESSING_FAILED |
READ_TIMEOUT_S |
60 |
Time limit for receiving an upload |
VALIDATION_TIMEOUT_S |
30 |
Time limit per Schematron run; queued requests give up after twice this |
MAX_CONCURRENT_REQUESTS |
16 |
Uploads processed at the same time; more wait |
EXPOSE_DOCS |
true without API_KEY, else false |
Serve /docs, /redoc and /openapi.json |
WORKERS |
1 |
uvicorn worker processes; each starts its own parser and Schematron workers |
Memory: about 400 MB per uvicorn worker at rest (Schematron worker with all rules compiled, plus the parser workers). Each parser worker is capped at PARSE_MEMORY_MB, and memory a worker once used is not always returned to the system. Size the container with PARSE_WORKERS × PARSE_MEMORY_MB + 1 GB per uvicorn worker, so 3 GB with the defaults (mem_limit: 3g in Compose). Very large invoices (tens of thousands of lines) need about 550 MB in a parser worker and 600 MB in the Schematron worker. On slow CPUs raise PARSE_TIMEOUT_S if they hit PROCESSING_TIMEOUT.
Network: the service is meant for internal networks. Bind it to localhost or a private Docker network, set API_KEY, and put a reverse proxy with request timeouts in front if untrusted clients can reach it.
uv sync
uv run pytest # fast suite
uv run pytest -m slow # 5,000-run Schematron soak test
scripts/update_rules.sh # pull the latest KoSIT validator configurationReleases are created automatically from Conventional Commits via release-please. Images for amd64 and arm64 are published to GHCR.
Repository setup, needed once for releases to work:
- Settings → Actions → General: enable Allow GitHub Actions to create and approve pull requests. release-please opens its release PR with the default
GITHUB_TOKEN. CI does not run on that PR (GitHub never triggers workflows fromGITHUB_TOKENevents); it only changes the version andCHANGELOG.md, and the image is built after the merge. - After the first image push, set the GHCR package
einvoice-readerto public so that anonymousdocker pullworks.
Need help receiving, validating or sending e-invoices in your business, or integrating this service into n8n, your ERP or your bookkeeping? Write to oss@effizienzagent.de (English or German). German-speaking SMEs: see E-Rechnung anbinden.
The code is licensed under Apache-2.0. Bundled and installed third-party components keep their own licences; see THIRD_PARTY_NOTICES.md. In short:
- KoSIT validator configuration (
src/einvoice_reader/rules/kosit): Apache-2.0. The CEN EN 16931 Schematron it contains (resources/cii,resources/ubl) is EUPL-1.2, seeLICENSE-EUPL-1.2-CEN.txt - KoSIT XRechnung test suite (
tests/fixtures/kosit): Apache-2.0 - The Factur-X rules ship with the
factur-xpackage (BSD)