# einvoice.generate

Generate a KoSIT-validated XRechnung UBL or CII invoice, or a ZUGFeRD PDF/A-3.

- REST: `POST https://api.kanagu.dev/v1/einvoice/generate`
- MCP tool: `einvoice.generate` at https://api.kanagu.dev/mcp
- Price: $0.02 USD per successful call. Trial: 10 calls per IP per UTC day without a key, shared by REST and MCP.
- Auth: `Authorization: Bearer <key>` for billed calls. Retries: reuse `Idempotency-Key`.

## Request body

- `format` ("ubl" | "cii" | "zugferd", required)
- `invoiceNumber` (string (max 50 chars), required)
- `issueDate` (string (date), required)
- `dueDate` (string (date), required)
- `deliveryDate` (string (date))
- `currency` (string)
- `buyerReference` (string (max 120 chars), required)
- `seller` (object, required)
- `seller.name` (string (max 160 chars), required)
- `seller.email` (string (email, max 160 chars), required)
- `seller.street` (string (max 160 chars), required)
- `seller.city` (string (max 100 chars), required)
- `seller.postalCode` (string (max 20 chars), required)
- `seller.country` (string, required)
- `seller.vatId` (string, required)
- `seller.contact` (object, required)
- `seller.contact.name` (string (max 120 chars), required)
- `seller.contact.phone` (string (max 60 chars), required)
- `seller.contact.email` (string (email, max 160 chars), required)
- `buyer` (object, required)
- `buyer.name` (string (max 160 chars), required)
- `buyer.email` (string (email, max 160 chars), required)
- `buyer.street` (string (max 160 chars), required)
- `buyer.city` (string (max 100 chars), required)
- `buyer.postalCode` (string (max 20 chars), required)
- `buyer.country` (string, required)
- `buyer.vatId` (string)
- `iban` (string, required)
- `lines` (array of object, required)
- `lines[].description` (string (max 300 chars), required)
- `lines[].quantity` (string, required)
- `lines[].unitPrice` (string, required): Net item price per base quantity.
- `lines[].baseQuantity` (string): Quantity covered by the item price. Defaults to one.
- `lines[].baseQuantityUnit` (string): Unit of the base quantity. Defaults to the line unit.
- `lines[].grossUnitPrice` (string): Item price before the item price discount.
- `lines[].unitPriceDiscount` (string): Discount on the item price per base quantity.
- `lines[].unit` (string)
- `lines[].vatRate` (string, required)

## Response

- `format` ("ubl" | "cii" | "zugferd", required)
- `xml` (string, required)
- `validation` (object, required)
- `validation.valid` (boolean, required)
- `validation.validator` ("KoSIT 1.6.3 / XRechnung 3.0.2 (2026-08-31)", required)
- `validation.issues` (array of object, required)
- `validation.issues[].ruleId` (string, required)
- `validation.issues[].severity` (string, required)
- `validation.issues[].xpath` (string, required)
- `validation.issues[].field` (string, required)
- `validation.issues[].message` (string, required)
- `validation.issues[].fixHint` (string, required)
- `pdfBase64` (string (base64)): PDF/A-3 for format zugferd

## Example

```sh
curl https://api.kanagu.dev/v1/einvoice/generate \
  -H "Authorization: Bearer $KANAGU_KEY" \
  -H "Content-Type: application/json" \
  -d '{"format":"ubl","invoiceNumber":"2026-0417","issueDate":"2026-11-23","deliveryDate":"2026-11-20","dueDate":"2026-12-23","buyerReference":"90000000-03083-72","seller":{"name":"Linden Consulting GmbH","vatId":"DE123456789","email":"billing@example.com","street":"Lindenstraße 12","city":"Berlin","postalCode":"10117","country":"DE","contact":{"name":"Kai Weber","phone":"+49 30 5550100","email":"kai@example.com"}},"buyer":{"name":"Nordhafen Verwaltungs GmbH","email":"invoices@example.org","street":"Hafenstraße 8","city":"Hamburg","postalCode":"20457","country":"DE"},"iban":"DE79000000001234567890","lines":[{"description":"Software integration workshop","quantity":"2","unitPrice":"475.00","vatRate":"19"}]}'
```

```ts
const res = await fetch("https://api.kanagu.dev/v1/einvoice/generate", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KANAGU_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "format": "ubl",
    "invoiceNumber": "2026-0417",
    "issueDate": "2026-11-23",
    "deliveryDate": "2026-11-20",
    "dueDate": "2026-12-23",
    "buyerReference": "90000000-03083-72",
    "seller": {
      "name": "Linden Consulting GmbH",
      "vatId": "DE123456789",
      "email": "billing@example.com",
      "street": "Lindenstraße 12",
      "city": "Berlin",
      "postalCode": "10117",
      "country": "DE",
      "contact": {
        "name": "Kai Weber",
        "phone": "+49 30 5550100",
        "email": "kai@example.com"
      }
    },
    "buyer": {
      "name": "Nordhafen Verwaltungs GmbH",
      "email": "invoices@example.org",
      "street": "Hafenstraße 8",
      "city": "Hamburg",
      "postalCode": "20457",
      "country": "DE"
    },
    "iban": "DE79000000001234567890",
    "lines": [
      {
        "description": "Software integration workshop",
        "quantity": "2",
        "unitPrice": "475.00",
        "vatRate": "19"
      }
    ]
  }),
});
if (!res.ok) throw new Error((await res.json()).error.message);
const result = await res.json();
```

## Errors

JSON `{"error":{"code","message"}}`.

- 400 `invalid_input`: The body does not match the request schema. The message names each field.
- 400 `invalid_json`: The body is missing or is not valid JSON.
- 400 `invalid_idempotency_key`: Idempotency-Key must be 1–128 visible ASCII characters.
- 401 `invalid_api_key`: The Bearer key is missing, malformed, invalid or inactive.
- 402 `free_allowance_exhausted`: This month's free usage is used up and the account has no subscription. Subscribe from the dashboard, or wait for the next UTC month; Retry-After gives the seconds left.
- 404 `not_found`: No operation at this path.
- 409 `idempotency_conflict`: The Idempotency-Key was already used with a different body.
- 413 `payload_too_large`: JSON bodies may be at most 64 KiB.
- 429 `trial_limit`: The anonymous trial allows 10 calls per IP per UTC day, shared by REST and MCP. Retry-After gives the seconds left.
- 500 `internal_error`: The call failed on our side. It is not billed; retry with the same Idempotency-Key.

## JSON Schema

Request:
```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "format": {
      "type": "string",
      "enum": [
        "ubl",
        "cii",
        "zugferd"
      ]
    },
    "invoiceNumber": {
      "type": "string",
      "minLength": 1,
      "maxLength": 50
    },
    "issueDate": {
      "type": "string",
      "format": "date",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
    },
    "dueDate": {
      "type": "string",
      "format": "date",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
    },
    "deliveryDate": {
      "type": "string",
      "format": "date",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
    },
    "currency": {
      "default": "EUR",
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "buyerReference": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "seller": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "email": {
          "type": "string",
          "maxLength": 160,
          "format": "email",
          "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
        },
        "street": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "city": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "postalCode": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "country": {
          "type": "string",
          "pattern": "^[A-Z]{2}$"
        },
        "vatId": {
          "type": "string",
          "pattern": "^[A-Z]{2}[A-Z0-9]{3,16}$"
        },
        "contact": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            },
            "phone": {
              "type": "string",
              "minLength": 1,
              "maxLength": 60
            },
            "email": {
              "type": "string",
              "maxLength": 160,
              "format": "email",
              "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
            }
          },
          "required": [
            "name",
            "phone",
            "email"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "name",
        "email",
        "street",
        "city",
        "postalCode",
        "country",
        "vatId",
        "contact"
      ],
      "additionalProperties": false
    },
    "buyer": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "email": {
          "type": "string",
          "maxLength": 160,
          "format": "email",
          "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
        },
        "street": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "city": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "postalCode": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "country": {
          "type": "string",
          "pattern": "^[A-Z]{2}$"
        },
        "vatId": {
          "type": "string",
          "pattern": "^[A-Z]{2}[A-Z0-9]{3,16}$"
        }
      },
      "required": [
        "name",
        "email",
        "street",
        "city",
        "postalCode",
        "country"
      ],
      "additionalProperties": false
    },
    "iban": {
      "type": "string",
      "pattern": "^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$"
    },
    "lines": {
      "minItems": 1,
      "maxItems": 500,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300
          },
          "quantity": {
            "type": "string",
            "pattern": "^\\d{1,8}(?:\\.\\d{1,4})?$"
          },
          "unitPrice": {
            "type": "string",
            "pattern": "^\\d{1,8}(?:\\.\\d{1,18})?$",
            "description": "Net item price per base quantity."
          },
          "baseQuantity": {
            "description": "Quantity covered by the item price. Defaults to one.",
            "type": "string",
            "pattern": "^\\d{1,8}(?:\\.\\d{1,4})?$"
          },
          "baseQuantityUnit": {
            "description": "Unit of the base quantity. Defaults to the line unit.",
            "type": "string",
            "pattern": "^[A-Z0-9]{2,3}$"
          },
          "grossUnitPrice": {
            "description": "Item price before the item price discount.",
            "type": "string",
            "pattern": "^\\d{1,8}(?:\\.\\d{1,18})?$"
          },
          "unitPriceDiscount": {
            "description": "Discount on the item price per base quantity.",
            "type": "string",
            "pattern": "^\\d{1,8}(?:\\.\\d{1,18})?$"
          },
          "unit": {
            "default": "C62",
            "type": "string",
            "pattern": "^[A-Z0-9]{2,3}$"
          },
          "vatRate": {
            "type": "string",
            "pattern": "^\\d{1,3}(?:\\.\\d{1,2})?$"
          }
        },
        "required": [
          "description",
          "quantity",
          "unitPrice",
          "vatRate"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "format",
    "invoiceNumber",
    "issueDate",
    "dueDate",
    "buyerReference",
    "seller",
    "buyer",
    "iban",
    "lines"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "format": "ubl",
      "invoiceNumber": "2026-0417",
      "issueDate": "2026-11-23",
      "deliveryDate": "2026-11-20",
      "dueDate": "2026-12-23",
      "buyerReference": "90000000-03083-72",
      "seller": {
        "name": "Linden Consulting GmbH",
        "vatId": "DE123456789",
        "email": "billing@example.com",
        "street": "Lindenstraße 12",
        "city": "Berlin",
        "postalCode": "10117",
        "country": "DE",
        "contact": {
          "name": "Kai Weber",
          "phone": "+49 30 5550100",
          "email": "kai@example.com"
        }
      },
      "buyer": {
        "name": "Nordhafen Verwaltungs GmbH",
        "email": "invoices@example.org",
        "street": "Hafenstraße 8",
        "city": "Hamburg",
        "postalCode": "20457",
        "country": "DE"
      },
      "iban": "DE79000000001234567890",
      "lines": [
        {
          "description": "Software integration workshop",
          "quantity": "2",
          "unitPrice": "475.00",
          "vatRate": "19"
        }
      ]
    }
  ]
}
```

Response:
```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "format": {
      "type": "string",
      "enum": [
        "ubl",
        "cii",
        "zugferd"
      ]
    },
    "xml": {
      "type": "string"
    },
    "validation": {
      "type": "object",
      "properties": {
        "valid": {
          "type": "boolean"
        },
        "validator": {
          "type": "string",
          "const": "KoSIT 1.6.3 / XRechnung 3.0.2 (2026-08-31)"
        },
        "issues": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "ruleId": {
                "type": "string"
              },
              "severity": {
                "type": "string"
              },
              "xpath": {
                "type": "string"
              },
              "field": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "fixHint": {
                "type": "string"
              }
            },
            "required": [
              "ruleId",
              "severity",
              "xpath",
              "field",
              "message",
              "fixHint"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "valid",
        "validator",
        "issues"
      ],
      "additionalProperties": false
    },
    "pdfBase64": {
      "description": "PDF/A-3 for format zugferd",
      "type": "string",
      "format": "base64",
      "contentEncoding": "base64",
      "pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$"
    }
  },
  "required": [
    "format",
    "xml",
    "validation"
  ],
  "additionalProperties": false
}
```
