{
 "openapi": "3.1.0",
 "info": {
  "title": "eRechnungsAmpel API",
  "version": "1.0.0",
  "summary": "Validierung und Konvertierung deutscher E-Rechnungen (XRechnung, ZUGFeRD) mit dem offiziellen KoSIT-Validator.",
  "description": "Öffentliche API von eRechnungsAmpel. Authentifizierung mit API-Schlüssel (`Authorization: Bearer era_live_…`), erstellt im Dashboard. Die API ist im Tarif Pro enthalten; mit einem anderen Tarif antwortet sie `403` mit `plan_without_api`.\n\n**Prüfung:** `POST /v1/validate` prüft XRechnung (UBL/CII) und ZUGFeRD/Factur-X mit dem offiziellen Validator der KoSIT und liefert die Ampel (`green` grün, `yellow` gelb, `red` rot) mit jeder Regelverletzung. Ein Bericht wird nur vollständig und in sich stimmig ausgeliefert; Fehler, Zeitüberschreitung oder ein nicht erreichbarer Dienst sind immer ein Fehler (`problem+json`), nie ein grünes Ergebnis. Der Bericht enthält zusätzlich `invoice`: die aus der Datei gelesenen Rechnungsdaten (Nummer, Datum, Verkäufer, Käufer, Positionen, Summen, Zahlungsangaben) als Text, oder `null`, wenn sie nicht vorliegen.\n\n**Lesbares PDF:** `POST /v1/visualize` nimmt dieselbe Datei an wie die Prüfung und liefert die Rechnung als lesbares PDF (`rechnung.pdf`). Das Ergebnis der Prüfung steht in den Antwort-Headern `X-Erechnung-*`; das PDF wird auch für eine rote Rechnung geliefert. Ein Aufruf kostet so viel wie eine Prüfung.\n\n**Konvertierung:** `POST /v1/conversions` nimmt ein PDF an (asynchron, `202`), liefert die erkannten Felder nach EN 16931 mit Fundstellen im Dokument (`needsReview` ist immer `true`), und `POST /v1/conversions/{id}/confirm` erzeugt aus den bestätigten Feldern XRechnung oder ZUGFeRD, die nur bei bestandener Prüfung ausgeliefert wird.\n\n**Datenschutz:** Rechnungsdaten werden spätestens nach 30 Minuten gelöscht und nie protokolliert. Verarbeitung auf einem Server in Frankfurt.\n\n**Limits (pro Benutzer):** Prüfung, lesbares PDF, Abruf und Löschen 120 Anfragen pro Minute und 4 gleichzeitig; Konvertierung anlegen und bestätigen 20 pro Minute und 2 gleichzeitig. Bei Überschreitung `429` mit `Retry-After`. Guthaben: jede ausgelieferte Prüfung, jedes ausgelieferte lesbare PDF und jede Konvertierung verbraucht Credits; ein lesbares PDF kostet so viel wie eine Prüfung. Abgelehnte Dateien und eigene Fehler werden nicht berechnet.\n\n**Fehler** folgen RFC 9457 (`application/problem+json`); `code` ist stabil, `title` lokalisiert (`Accept-Language: de` oder `en`). Jede Antwort trägt `X-Request-Id`.\n\nDas Produkt prüft das Format, keine steuerliche Beratung: Steuersatz und Steuerbefreiung entscheiden Sie und Ihr Steuerberater.",
  "license": {
   "name": "Proprietär",
   "identifier": "LicenseRef-Proprietary"
  }
 },
 "servers": [
  {
   "url": "/",
   "description": "Gleiche Herkunft wie dieses Dokument"
  }
 ],
 "security": [
  {
   "apiKey": []
  }
 ],
 "tags": [
  {
   "name": "Prüfung",
   "description": "Prüfung von XRechnung und ZUGFeRD mit dem offiziellen KoSIT-Validator."
  },
  {
   "name": "Konvertierung",
   "description": "PDF-Rechnung in XRechnung oder ZUGFeRD umwandeln, mit Bestätigung der Felder."
  },
  {
   "name": "Betrieb",
   "description": "Status und Beschreibung der API, ohne Authentifizierung."
  }
 ],
 "paths": {
  "/v1/health": {
   "get": {
    "tags": [
     "Betrieb"
    ],
    "operationId": "health",
    "summary": "Betriebsstatus und Version",
    "security": [],
    "responses": {
     "200": {
      "description": "Bereit",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Health"
        }
       }
      }
     },
     "503": {
      "description": "Nicht bereit oder wird neu gestartet",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Health"
        }
       }
      }
     }
    }
   }
  },
  "/v1/openapi.json": {
   "get": {
    "tags": [
     "Betrieb"
    ],
    "operationId": "openapi",
    "summary": "Dieses Dokument",
    "security": [],
    "responses": {
     "200": {
      "description": "OpenAPI 3.1",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/v1/validate": {
   "post": {
    "tags": [
     "Prüfung"
    ],
    "operationId": "validate",
    "summary": "E-Rechnung prüfen",
    "description": "Rohdaten der Datei im Body (kein Multipart), höchstens 10 MiB. Ein PDF muss die Rechnungs-XML eingebettet haben (ZUGFeRD/Factur-X).",
    "parameters": [
     {
      "$ref": "#/components/parameters/AcceptLanguage"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/xml": {
       "schema": {
        "type": "string",
        "contentMediaType": "application/xml"
       }
      },
      "text/xml": {
       "schema": {
        "type": "string",
        "contentMediaType": "text/xml"
       }
      },
      "application/pdf": {
       "schema": {
        "type": "string",
        "contentMediaType": "application/pdf"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Prüfbericht mit den gelesenen Rechnungsdaten (`invoice`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ValidationReport"
        }
       }
      }
     },
     "400": {
      "description": "Datei abgelehnt (z. B. `malformed_xml`, `xml_doctype`, `malformed_pdf`, `protected_pdf`, `empty_body`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "402": {
      "description": "Nicht genügend Guthaben (`insufficient_credits`) oder Konto gesperrt (`account_blocked`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "403": {
      "$ref": "#/components/responses/PlanWithoutAPI"
     },
     "413": {
      "description": "Größer als 10 MiB (`body_too_large`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "415": {
      "description": "Weder XML noch PDF (`unsupported_media_type`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     },
     "502": {
      "description": "Validator-Fehler oder unvollständiger Bericht (`validator_failed`, `invalid_report`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/visualize": {
   "post": {
    "tags": [
     "Prüfung"
    ],
    "operationId": "visualize",
    "summary": "E-Rechnung als lesbares PDF",
    "description": "Gleiche Anfrage wie `POST /v1/validate`: Rohdaten der Datei im Body (kein Multipart), höchstens 10 MiB. Die Antwort ist die Rechnung als lesbares PDF; das Ergebnis der Prüfung steht in den Headern `X-Erechnung-*`. Das PDF wird auch für eine rote Rechnung geliefert. Ein ausgeliefertes PDF kostet so viel wie eine Prüfung und erscheint im Verlauf als Prüfung. Kann die Datei nicht als PDF dargestellt werden, antwortet die API mit `422` und berechnet nichts.",
    "parameters": [
     {
      "$ref": "#/components/parameters/AcceptLanguage"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/xml": {
       "schema": {
        "type": "string",
        "contentMediaType": "application/xml"
       }
      },
      "text/xml": {
       "schema": {
        "type": "string",
        "contentMediaType": "text/xml"
       }
      },
      "application/pdf": {
       "schema": {
        "type": "string",
        "contentMediaType": "application/pdf"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Die Rechnung als lesbares PDF (`rechnung.pdf`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       },
       "Content-Disposition": {
        "schema": {
         "type": "string",
         "const": "attachment; filename=\"rechnung.pdf\""
        }
       },
       "X-Erechnung-Traffic-Light": {
        "description": "Ergebnis der Prüfung der eingereichten Datei",
        "schema": {
         "type": "string",
         "enum": [
          "green",
          "yellow",
          "red"
         ]
        }
       },
       "X-Erechnung-Format": {
        "description": "Erkanntes Format, wie `format` im Prüfbericht",
        "schema": {
         "type": "string",
         "examples": [
          "xrechnung-cii",
          "zugferd"
         ]
        }
       },
       "X-Erechnung-Profile": {
        "description": "Erkanntes Profil, wie `profile` im Prüfbericht; fehlt, wenn kein Profil erkannt wurde",
        "schema": {
         "type": "string",
         "examples": [
          "XRECHNUNG",
          "EN16931"
         ]
        }
       },
       "X-Erechnung-Errors": {
        "description": "Anzahl der Fehler",
        "schema": {
         "type": "integer",
         "minimum": 0
        }
       },
       "X-Erechnung-Warnings": {
        "description": "Anzahl der Warnungen",
        "schema": {
         "type": "integer",
         "minimum": 0
        }
       }
      },
      "content": {
       "application/pdf": {
        "schema": {
         "type": "string",
         "contentMediaType": "application/pdf"
        }
       }
      }
     },
     "400": {
      "description": "Datei abgelehnt (z. B. `malformed_xml`, `xml_doctype`, `malformed_pdf`, `protected_pdf`, `empty_body`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "402": {
      "description": "Nicht genügend Guthaben (`insufficient_credits`) oder Konto gesperrt (`account_blocked`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "403": {
      "$ref": "#/components/responses/PlanWithoutAPI"
     },
     "413": {
      "description": "Größer als 10 MiB (`body_too_large`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "415": {
      "description": "Weder XML noch PDF (`unsupported_media_type`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "422": {
      "description": "Die Datei kann nicht als PDF dargestellt werden (`visual_unsupported_syntax`, `visual_unavailable`). Es wird nichts berechnet.",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     },
     "502": {
      "description": "Validator-Fehler (`validator_failed`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/conversions": {
   "post": {
    "tags": [
     "Konvertierung"
    ],
    "operationId": "createConversion",
    "summary": "PDF zur Konvertierung einreichen",
    "description": "Rohes PDF im Body, höchstens 20 MiB und 10 Seiten. Asynchron: die Antwort `202` enthält die Konvertierung im Status `processing`. Gleicher `Idempotency-Key` mit gleichem Inhalt liefert dieselbe Konvertierung.",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 1,
       "maxLength": 255,
       "pattern": "^[\\x21-\\x7e]+$"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/pdf": {
       "schema": {
        "type": "string",
        "contentMediaType": "application/pdf"
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Angenommen",
      "headers": {
       "Location": {
        "schema": {
         "type": "string"
        }
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Conversion"
        }
       }
      }
     },
     "400": {
      "description": "`missing_idempotency_key`, `invalid_idempotency_key`, `empty_body`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "402": {
      "description": "`insufficient_credits`, `account_blocked`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "403": {
      "description": "Tarif ohne API-Zugang (`plan_without_api`) oder ohne Konvertierung (`plan_without_conversion`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "409": {
      "description": "Anfrage mit diesem Schlüssel läuft noch (`idempotency_in_progress`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "413": {
      "description": "`body_too_large`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "415": {
      "description": "Kein PDF (`unsupported_media_type`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "422": {
      "description": "Schlüssel mit anderem Inhalt (`idempotency_conflict`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/conversions/{id}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ConversionId"
    }
   ],
   "get": {
    "tags": [
     "Konvertierung"
    ],
    "operationId": "getConversion",
    "summary": "Status und erkannte Felder",
    "parameters": [
     {
      "$ref": "#/components/parameters/AcceptLanguage"
     }
    ],
    "responses": {
     "200": {
      "description": "Konvertierung",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Conversion"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/PlanWithoutAPI"
     },
     "404": {
      "description": "`conversion_not_found`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "410": {
      "description": "Abgelaufen, gelöscht oder bereits ausgeliefert (`conversion_expired`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   },
   "delete": {
    "tags": [
     "Konvertierung"
    ],
    "operationId": "deleteConversion",
    "summary": "Sofort löschen",
    "responses": {
     "204": {
      "description": "Gelöscht; noch reservierte Credits werden zurückgebucht"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/PlanWithoutAPI"
     },
     "404": {
      "description": "`conversion_not_found`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "410": {
      "description": "`conversion_expired`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/conversions/{id}/confirm": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ConversionId"
    }
   ],
   "post": {
    "tags": [
     "Konvertierung"
    ],
    "operationId": "confirmConversion",
    "summary": "Bestätigte Felder in eine E-Rechnung umwandeln",
    "description": "Sendet die geprüften und ggf. korrigierten Felder (das `draft` der Konvertierung) im Modell EN 16931 (Schlüssel BT/BG). Fehlt BT-23 bei XRechnung, wird der übliche Wert ergänzt. Es wird nichts berechnet oder ergänzt: falsche Summen ergeben `422` mit dem Bericht.",
    "parameters": [
     {
      "$ref": "#/components/parameters/AcceptLanguage"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ConfirmRequest"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "E-Rechnung, grün oder gelb geprüft",
      "headers": {
       "X-Erechnung-Traffic-Light": {
        "schema": {
         "type": "string",
         "enum": [
          "green",
          "yellow"
         ]
        }
       },
       "X-Erechnung-Report": {
        "description": "Vollständiger Prüfbericht als JSON, Base64url ohne Padding",
        "schema": {
         "type": "string"
        }
       },
       "Content-Disposition": {
        "schema": {
         "type": "string"
        }
       }
      },
      "content": {
       "application/xml": {
        "schema": {
         "type": "string",
         "contentMediaType": "application/xml"
        }
       },
       "application/pdf": {
        "schema": {
         "type": "string",
         "contentMediaType": "application/pdf"
        }
       }
      }
     },
     "400": {
      "description": "`invalid_json`, `invalid_format`, `missing_invoice`, `invalid_field` (`detail` nennt das Feld, z. B. `BT-2`), `multiple_bg3_cii` (in CII nur eine vorausgehende Rechnung, `detail` `BG-3`)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/PlanWithoutAPI"
     },
     "404": {
      "description": "`conversion_not_found`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "409": {
      "description": "`conversion_not_ready`, `conversion_not_needed` (das PDF ist bereits eine E-Rechnung)",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "410": {
      "description": "`conversion_expired`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "422": {
      "description": "Die erzeugte Rechnung wäre ungültig: der rote Prüfbericht. Die Konvertierung bleibt bereit für eine Korrektur.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Report"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     },
     "502": {
      "description": "`validator_failed`, `invalid_report`",
      "headers": {
       "X-Request-Id": {
        "$ref": "#/components/headers/RequestId"
       }
      },
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "apiKey": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "era_live_<48 hex>",
    "description": "API-Schlüssel aus dem Dashboard."
   }
  },
  "parameters": {
   "ConversionId": {
    "name": "id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "pattern": "^[a-f0-9]{32}$"
    }
   },
   "AcceptLanguage": {
    "name": "Accept-Language",
    "in": "header",
    "required": false,
    "description": "Sprache von `title` und `message` (`de` Standard, `en`).",
    "schema": {
     "type": "string"
    }
   }
  },
  "headers": {
   "RequestId": {
    "description": "Kennung der Anfrage für den Support.",
    "schema": {
     "type": "string",
     "pattern": "^[a-f0-9]{32}$"
    }
   },
   "RetryAfter": {
    "description": "Sekunden bis zum nächsten Versuch.",
    "schema": {
     "type": "integer",
     "minimum": 1
    }
   }
  },
  "responses": {
   "Unauthorized": {
    "description": "API-Schlüssel fehlt oder ist ungültig (`missing_key`, `invalid_key`)",
    "headers": {
     "WWW-Authenticate": {
      "schema": {
       "type": "string"
      }
     }
    },
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "TooManyRequests": {
    "description": "Limit erreicht (`rate_limited`)",
    "headers": {
     "Retry-After": {
      "$ref": "#/components/headers/RetryAfter"
     }
    },
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "Unavailable": {
    "description": "Vorübergehend nicht verfügbar: nie ein Ergebnis (`validator_unavailable`, `timeout`, `service_busy`, `service_unavailable`, `conversion_unavailable`)",
    "headers": {
     "Retry-After": {
      "$ref": "#/components/headers/RetryAfter"
     }
    },
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "PlanWithoutAPI": {
    "description": "Tarif ohne API-Zugang (`plan_without_api`)",
    "headers": {
     "X-Request-Id": {
      "$ref": "#/components/headers/RequestId"
     }
    },
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   }
  },
  "schemas": {
   "Problem": {
    "type": "object",
    "required": [
     "type",
     "title",
     "status",
     "code"
    ],
    "properties": {
     "type": {
      "type": "string",
      "format": "uri"
     },
     "title": {
      "type": "string"
     },
     "status": {
      "type": "integer"
     },
     "code": {
      "type": "string",
      "enum": [
       "subscription_active",
       "multiple_bg3_cii",
       "invalid_field",
       "missing_key",
       "invalid_key",
       "invalid_confirmation",
       "account_deleted",
       "account_blocked",
       "invalid_content_length",
       "conversion_not_needed",
       "conversion_expired",
       "conversion_unavailable",
       "conversion_not_found",
       "conversion_not_ready",
       "body_too_large",
       "empty_body",
       "insufficient_credits",
       "dispute_open",
       "extraction_failed",
       "extraction_unavailable",
       "extractor_unavailable",
       "missing_invoice",
       "invalid_format",
       "generation_rejected",
       "missing_idempotency_key",
       "idempotency_conflict",
       "idempotency_in_progress",
       "invalid_idempotency_key",
       "missing_ip",
       "invalid_json",
       "daily_limit",
       "rate_limited",
       "malware_detected",
       "method_not_allowed",
       "unauthorized",
       "too_many_pages",
       "pdf_too_complex",
       "malformed_pdf",
       "protected_pdf",
       "pdf_rejected",
       "unexpected_visual_pdf",
       "invalid_visual_pdf",
       "visual_pdf_not_pdfa",
       "visual_unsupported_syntax",
       "visual_unavailable",
       "plan_without_api",
       "plan_without_conversion",
       "plan_without_inbox",
       "plan_without_forwarding",
       "invalid_report",
       "invalid_request",
       "route_not_found",
       "service_shutting_down",
       "service_unavailable",
       "service_busy",
       "timeout",
       "unsupported_media_type",
       "missing_turnstile",
       "invalid_turnstile",
       "validator_failed",
       "validator_unavailable",
       "validator_busy",
       "scan_outdated",
       "scan_incomplete",
       "xml_doctype",
       "embedded_xml_too_large",
       "malformed_xml",
       "invalid_zugferd_xml",
       "inbox_not_found",
       "inbox_disabled",
       "inbox_quota_reached",
       "invalid_destination",
       "destination_forbidden",
       "destination_blocked",
       "destination_datev_upload",
       "forwarding_unavailable",
       "forwarding_not_configured",
       "forwarding_already_confirmed",
       "resend_limit_reached",
       "confirm_token_invalid"
      ]
     },
     "detail": {
      "type": "string"
     },
     "requestId": {
      "type": "string"
     }
    }
   },
   "Health": {
    "type": "object",
    "required": [
     "status",
     "service",
     "commit"
    ],
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "ok",
       "unavailable",
       "stopping"
      ]
     },
     "service": {
      "type": "string",
      "const": "api"
     },
     "commit": {
      "type": "string"
     }
    }
   },
   "Violation": {
    "type": "object",
    "required": [
     "rule",
     "severity",
     "field",
     "location",
     "original_message",
     "message",
     "explanation"
    ],
    "properties": {
     "rule": {
      "type": "string",
      "examples": [
       "BR-DE-15"
      ]
     },
     "severity": {
      "type": "string",
      "enum": [
       "error",
       "warning"
      ]
     },
     "field": {
      "type": [
       "string",
       "null"
      ],
      "examples": [
       "BT-10"
      ]
     },
     "location": {
      "type": [
       "string",
       "null"
      ],
      "description": "XPath der Fundstelle"
     },
     "original_message": {
      "type": "string",
      "description": "Originaltext der Regel"
     },
     "message": {
      "type": [
       "string",
       "null"
      ],
      "description": "Eigene Meldung der Regel in der angefragten Sprache, falls vorhanden (für BR-* null: dann gelten mensagem_original und explicacao)"
     },
     "explanation": {
      "type": [
       "string",
       "null"
      ],
      "format": "uri-reference",
      "description": "Link zur Erklärung der Regel auf der Website: /regeln/<ID> (Deutsch) oder /en/rules/<ID> (Englisch)",
      "examples": [
       "https://erechnungsampel.de/regeln/BR-DE-15"
      ]
     }
    }
   },
   "Report": {
    "type": "object",
    "required": [
     "traffic_light",
     "format",
     "profile",
     "rules_version",
     "violations",
     "duration_ms"
    ],
    "properties": {
     "traffic_light": {
      "type": "string",
      "enum": [
       "green",
       "yellow",
       "red"
      ],
      "description": "verde: keine Verletzung; amarelo: nur Warnungen; vermelho: mindestens ein Fehler"
     },
     "format": {
      "type": "string",
      "examples": [
       "xrechnung-cii",
       "xrechnung-ubl",
       "zugferd",
       "en16931-ubl",
       "unknown"
      ]
     },
     "profile": {
      "type": [
       "string",
       "null"
      ],
      "examples": [
       "XRECHNUNG",
       "EN16931"
      ]
     },
     "rules_version": {
      "type": "string"
     },
     "violations": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Violation"
      }
     },
     "duration_ms": {
      "type": "integer"
     }
    }
   },
   "ValidationReport": {
    "description": "Prüfbericht von `POST /v1/validate`: der Bericht und die gelesenen Rechnungsdaten.",
    "allOf": [
     {
      "$ref": "#/components/schemas/Report"
     },
     {
      "type": "object",
      "required": [
       "invoice"
      ],
      "properties": {
       "invoice": {
        "$ref": "#/components/schemas/Invoice"
       }
      }
     }
    ]
   },
   "Invoice": {
    "type": [
     "object",
     "null"
    ],
    "description": "Aus der Datei gelesene Rechnungsdaten, zum Anzeigen. Alle Werte sind Text oder `null`. `null` als Ganzes, wenn die Daten nicht vorliegen. Die Daten ändern das Ergebnis der Prüfung nicht.",
    "additionalProperties": false,
    "required": [
     "number",
     "type_code",
     "issue_date",
     "due_date",
     "currency",
     "buyer_reference",
     "order_reference",
     "seller",
     "buyer",
     "lines",
     "lines_truncated",
     "totals",
     "vat_breakdown",
     "payment",
     "notes"
    ],
    "properties": {
     "number": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Rechnungsnummer",
      "examples": [
       "RE-2026-0042"
      ]
     },
     "type_code": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Rechnungsart (Code)",
      "examples": [
       "380"
      ]
     },
     "issue_date": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Rechnungsdatum",
      "examples": [
       "2026-11-20"
      ]
     },
     "due_date": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Fälligkeitsdatum",
      "examples": [
       "2026-12-04"
      ]
     },
     "currency": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Währung (Code)",
      "examples": [
       "EUR"
      ]
     },
     "buyer_reference": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Käuferreferenz, z. B. die Leitweg-ID"
     },
     "order_reference": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Bestellnummer"
     },
     "seller": {
      "$ref": "#/components/schemas/InvoiceParty"
     },
     "buyer": {
      "$ref": "#/components/schemas/InvoiceParty"
     },
     "lines": {
      "type": "array",
      "maxItems": 200,
      "items": {
       "$ref": "#/components/schemas/InvoiceLine"
      }
     },
     "lines_truncated": {
      "type": "boolean",
      "description": "`true`, wenn die Rechnung mehr Positionen hat als hier geliefert werden (höchstens 200)."
     },
     "totals": {
      "$ref": "#/components/schemas/InvoiceTotals"
     },
     "vat_breakdown": {
      "type": "array",
      "maxItems": 20,
      "items": {
       "$ref": "#/components/schemas/InvoiceVatRow"
      }
     },
     "payment": {
      "$ref": "#/components/schemas/InvoicePayment"
     },
     "notes": {
      "type": "array",
      "maxItems": 10,
      "items": {
       "type": "string",
       "maxLength": 2000
      },
      "description": "Bemerkungen der Rechnung"
     }
    }
   },
   "InvoiceParty": {
    "type": "object",
    "description": "Verkäufer oder Käufer, wie in der Datei angegeben.",
    "additionalProperties": false,
    "required": [
     "name",
     "street",
     "postal_code",
     "city",
     "country",
     "vat_id",
     "tax_number",
     "email"
    ],
    "properties": {
     "name": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Name"
     },
     "street": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Straße und Hausnummer"
     },
     "postal_code": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Postleitzahl"
     },
     "city": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Ort"
     },
     "country": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Ländercode",
      "examples": [
       "DE"
      ]
     },
     "vat_id": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Umsatzsteuer-Identifikationsnummer",
      "examples": [
       "DE123456789"
      ]
     },
     "tax_number": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Steuernummer"
     },
     "email": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "E-Mail-Adresse"
     }
    }
   },
   "InvoiceLine": {
    "type": "object",
    "description": "Eine Rechnungsposition.",
    "additionalProperties": false,
    "required": [
     "id",
     "name",
     "description",
     "quantity",
     "unit",
     "unit_price",
     "net_amount",
     "vat_category",
     "vat_rate"
    ],
    "properties": {
     "id": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Positionsnummer"
     },
     "name": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Bezeichnung"
     },
     "description": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Beschreibung"
     },
     "quantity": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Menge",
      "examples": [
       "12.5"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Einheit (Code)",
      "examples": [
       "HUR"
      ]
     },
     "unit_price": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Einzelpreis netto",
      "examples": [
       "48.00"
      ]
     },
     "net_amount": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Nettobetrag der Position",
      "examples": [
       "600.00"
      ]
     },
     "vat_category": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Umsatzsteuerkategorie (Code)",
      "examples": [
       "S"
      ]
     },
     "vat_rate": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Umsatzsteuersatz in Prozent",
      "examples": [
       "19"
      ]
     }
    }
   },
   "InvoiceTotals": {
    "type": "object",
    "description": "Summen der Rechnung.",
    "additionalProperties": false,
    "required": [
     "net",
     "vat",
     "gross",
     "prepaid",
     "payable"
    ],
    "properties": {
     "net": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Summe netto"
     },
     "vat": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Umsatzsteuer gesamt"
     },
     "gross": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Summe brutto"
     },
     "prepaid": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Bereits gezahlter Betrag"
     },
     "payable": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Zahlbetrag"
     }
    }
   },
   "InvoiceVatRow": {
    "type": "object",
    "description": "Eine Zeile der Umsatzsteueraufschlüsselung.",
    "additionalProperties": false,
    "required": [
     "category",
     "rate",
     "taxable",
     "tax",
     "exemption_reason"
    ],
    "properties": {
     "category": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Umsatzsteuerkategorie (Code)",
      "examples": [
       "S"
      ]
     },
     "rate": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Umsatzsteuersatz in Prozent",
      "examples": [
       "19"
      ]
     },
     "taxable": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Steuerbasis"
     },
     "tax": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Steuerbetrag"
     },
     "exemption_reason": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Befreiungsgrund, wie in der Datei angegeben"
     }
    }
   },
   "InvoicePayment": {
    "type": "object",
    "description": "Zahlungsangaben.",
    "additionalProperties": false,
    "required": [
     "terms",
     "means_code",
     "iban",
     "account_name",
     "bic"
    ],
    "properties": {
     "terms": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 2000,
      "description": "Zahlungsbedingungen"
     },
     "means_code": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Zahlungsart (Code)",
      "examples": [
       "58"
      ]
     },
     "iban": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "IBAN"
     },
     "account_name": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "Kontoinhaber"
     },
     "bic": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 500,
      "description": "BIC"
     }
    }
   },
   "Source": {
    "type": "object",
    "required": [
     "page",
     "line",
     "quote"
    ],
    "properties": {
     "page": {
      "type": "integer",
      "minimum": 1
     },
     "line": {
      "type": "integer",
      "minimum": 1
     },
     "quote": {
      "type": "string",
      "description": "Wörtlicher Ausschnitt der Zeile"
     }
    }
   },
   "Warning": {
    "type": "object",
    "required": [
     "code"
    ],
    "properties": {
     "code": {
      "type": "string",
      "examples": [
       "FIELD_MISSING",
       "CITATION_NOT_FOUND",
       "ARITHMETIC_MISMATCH",
       "VAT_TOTAL_COMPUTED"
      ]
     },
     "field": {
      "type": "string"
     },
     "item": {
      "type": "integer"
     },
     "page": {
      "type": "integer"
     },
     "line": {
      "type": "integer"
     }
    }
   },
   "Hint": {
    "type": "object",
    "required": [
     "kind",
     "sources"
    ],
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "REVERSE_CHARGE",
       "KLEINUNTERNEHMER",
       "INTRA_COMMUNITY_SUPPLY",
       "EXPORT",
       "SKONTO"
      ]
     },
     "sources": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Source"
      }
     }
    }
   },
   "Conversion": {
    "type": "object",
    "required": [
     "id",
     "status",
     "createdAt",
     "expiresAt",
     "needsReview",
     "warnings"
    ],
    "properties": {
     "id": {
      "type": "string",
      "pattern": "^[a-f0-9]{32}$"
     },
     "status": {
      "type": "string",
      "enum": [
       "processing",
       "ready",
       "failed"
      ]
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     },
     "expiresAt": {
      "type": "string",
      "format": "date-time",
      "description": "Spätestens dann ist alles gelöscht (unter 30 Minuten)"
     },
     "source": {
      "type": "string",
      "enum": [
       "text",
       "ocr",
       "zugferd"
      ]
     },
     "needsReview": {
      "type": "boolean",
      "const": true
     },
     "fields": {
      "type": "object",
      "description": "Felder nach EN 16931 (BT/BG wie im Rechnungsmodell); jedes Blatt ist {\"value\": string, \"sources\": [Source]}"
     },
     "draft": {
      "type": "object",
      "description": "Dieselben Felder ohne Fundstellen: nach Prüfung an /confirm senden"
     },
     "hints": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Hint"
      }
     },
     "warnings": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Warning"
      }
     },
     "report": {
      "$ref": "#/components/schemas/Report",
      "description": "Nur wenn das PDF bereits eine E-Rechnung enthält"
     },
     "error": {
      "type": "object",
      "required": [
       "code"
      ],
      "properties": {
       "code": {
        "type": "string"
       }
      }
     }
    }
   },
   "ConfirmRequest": {
    "type": "object",
    "required": [
     "format",
     "invoice"
    ],
    "additionalProperties": false,
    "properties": {
     "format": {
      "type": "string",
      "enum": [
       "xrechnung-cii",
       "xrechnung-ubl",
       "zugferd-en16931",
       "zugferd-xrechnung"
      ]
     },
     "invoice": {
      "type": "object",
      "description": "Rechnungsmodell EN 16931: Schlüssel BT-…/BG-…, Beträge als Dezimal-Strings (\"1234.56\"), Datum \"JJJJ-MM-TT\""
     }
    }
   }
  }
 }
}