Skip to content

Tax & e-invoicingPoland KSeF e-invoices

ksef.generate

Generate FA(3) XML for a domestic Polish PLN B2B VAT invoice with up to 500 lines and check it locally against the official XSD.

POSThttps://api.kanagu.dev/v1/ksef/generate
Price
$0.04 per invoice, on successful calls only
Authentication
API key required.
MCP
call_operation with operation: "ksef.generate" at https://api.kanagu.dev/mcp

Compliance coverage

Jurisdictions
Jurisdictions: PL
Standards
  • FA(3) XML schema (CRWDE 13775)1-0E2025-06-25Source
  • Ministry of Finance StrukturyDanych XSD10-0E2022-01-05Source
  • Ministry of Finance ElementarneTypyDanych XSD10-0E2022-01-05Source
  • Ministry of Finance KodyKrajow XSD10-0E2022-01-05Source
  • Ministry of Finance FA(3) information guideAugust 20262026-08-26Source
  • Polish VAT Act, Article 106eDz.U. 2026 poz. 12632026-09-28Source
  • KSeF invoice verification2026-04-092026-04-09Source
  • Extensible Markup Language (XML)1.0, fifth edition2008-11-26Source
Verification
ksef.generate checks generated XML and ksef.validate checks submitted XML against the Ministry's FA(3) XSD and supported invoice-level and arithmetic rules.
Last reviewed
2026-11-26
curl https://api.kanagu.dev/v1/ksef/generate \
  -H "Authorization: Bearer $KANAGU_KEY" \
  -H "Content-Type: application/json" \
  -d '{"invoiceNumber":"FV/2026/03/104","issueDate":"2026-03-02","createdAt":"2026-03-02T10:05:00Z","supplyDate":"2026-02-27","dueDate":"2026-03-16","seller":{"nip":"5260250274","name":"Przykładowy Dostawca sp. z o.o.","addressLine1":"ul. Wolska 14, 01-201 Warszawa"},"buyer":{"nip":"8567346215","name":"Przykładowy Nabywca sp. z o.o.","addressLine1":"ul. Długa 4, 31-146 Kraków"},"cashAccounting":false,"lines":[{"description":"Konserwacja urządzeń","unit":"godz.","quantity":"2.5","unitNetPrice":"120.00","vatRate":"23","annex15":false}]}'
const res = await fetch("https://api.kanagu.dev/v1/ksef/generate", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KANAGU_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "invoiceNumber": "FV/2026/03/104",
    "issueDate": "2026-03-02",
    "createdAt": "2026-03-02T10:05:00Z",
    "supplyDate": "2026-02-27",
    "dueDate": "2026-03-16",
    "seller": {
      "nip": "5260250274",
      "name": "Przykładowy Dostawca sp. z o.o.",
      "addressLine1": "ul. Wolska 14, 01-201 Warszawa"
    },
    "buyer": {
      "nip": "8567346215",
      "name": "Przykładowy Nabywca sp. z o.o.",
      "addressLine1": "ul. Długa 4, 31-146 Kraków"
    },
    "cashAccounting": false,
    "lines": [
      {
        "description": "Konserwacja urządzeń",
        "unit": "godz.",
        "quantity": "2.5",
        "unitNetPrice": "120.00",
        "vatRate": "23",
        "annex15": false
      }
    ]
  }),
});
if (!res.ok) throw new Error((await res.json()).error.message);
const result = await res.json();
curl https://api.kanagu.dev/mcp \
  -H "Authorization: Bearer $KANAGU_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"call_operation","arguments":{"operation":"ksef.generate","input":{"invoiceNumber":"FV/2026/03/104","issueDate":"2026-03-02","createdAt":"2026-03-02T10:05:00Z","supplyDate":"2026-02-27","dueDate":"2026-03-16","seller":{"nip":"5260250274","name":"Przykładowy Dostawca sp. z o.o.","addressLine1":"ul. Wolska 14, 01-201 Warszawa"},"buyer":{"nip":"8567346215","name":"Przykładowy Nabywca sp. z o.o.","addressLine1":"ul. Długa 4, 31-146 Kraków"},"cashAccounting":false,"lines":[{"description":"Konserwacja urządzeń","unit":"godz.","quantity":"2.5","unitNetPrice":"120.00","vatRate":"23","annex15":false}]}}}}'
Request body
{
  "invoiceNumber": "FV/2026/03/104",
  "issueDate": "2026-03-02",
  "createdAt": "2026-03-02T10:05:00Z",
  "supplyDate": "2026-02-27",
  "dueDate": "2026-03-16",
  "seller": {
    "nip": "5260250274",
    "name": "Przykładowy Dostawca sp. z o.o.",
    "addressLine1": "ul. Wolska 14, 01-201 Warszawa"
  },
  "buyer": {
    "nip": "8567346215",
    "name": "Przykładowy Nabywca sp. z o.o.",
    "addressLine1": "ul. Długa 4, 31-146 Kraków"
  },
  "cashAccounting": false,
  "lines": [
    {
      "description": "Konserwacja urządzeń",
      "unit": "godz.",
      "quantity": "2.5",
      "unitNetPrice": "120.00",
      "vatRate": "23",
      "annex15": false
    }
  ]
}

Request body

application/json

invoiceNumberstring (max 256 chars)required
issueDatestring (date)required
createdAtstring (date-time)required
Actual XML creation timestamp, in UTC (YYYY-MM-DDTHH:mm:ssZ).
supplyDatestring (date)
Common delivery or service date, when known and different from the issue date.
dueDatestring (date)
sellerobjectrequired
seller.nipstringrequired
Polish NIP, ten digits without the PL prefix.
seller.namestring (max 512 chars)required
seller.addressLine1string (max 512 chars)required
seller.addressLine2string (max 512 chars)
buyerobjectrequired
buyer.nipstringrequired
Polish NIP, ten digits without the PL prefix.
buyer.namestring (max 512 chars)required
buyer.addressLine1string (max 512 chars)required
buyer.addressLine2string (max 512 chars)
cashAccountingbooleanrequired
Whether the invoice requires the cash accounting annotation (metoda kasowa).
linesarray of objectrequired
lines[].descriptionstring (max 512 chars)required
lines[].unitstring (max 256 chars)required
lines[].quantitystringrequired
lines[].unitNetPricestringrequired
lines[].vatRate"5" | "8" | "23" | "0 KR"required
FA(3) P_12 code supplied by the issuer. 0 KR is domestic zero-rated sales.
lines[].annex15booleanrequired
Whether the goods or services fall under Annex 15 of the VAT Act.

Response

200 · application/json

status"valid" | "invalid" | "needs_review"required
Outcome of the local checks.
xsd"passed" | "failed" | "not_run"required
specificationobjectrequired
specification.version"1-0E"required
specification.date"2025-06-25"required
specification.url"https://crd.gov.pl/wzor/2025/06/25/13775/schemat.xsd"required
issuesarray of objectrequired
issues[].severity"error" | "needs_review"required
issues[].rulestringrequired
issues[].pathstringrequired
issues[].lineinteger (≤ 9007199254740991)
issues[].expectedstringrequired
issues[].actualstringrequired
issues[].sourcestring (uri)required
xmlstring
FA(3) XML when the local checks pass.

Try it

ksef.generate

$0.04/invoice

 

Response

Run the request to see the live response here.

Errors

Errors are JSON {"error":{"code","message"}}. An operation may add its own 400 codes; the message says what to fix.

StatusCode and meaning
400invalid_input

The body does not match the request schema. The message names each field.

400invalid_json

The body is missing or is not valid JSON.

400invalid_idempotency_key

Idempotency-Key must be 1–128 visible ASCII characters.

401invalid_api_key

The Bearer key is missing, malformed, invalid or inactive.

402free_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.

404not_found

No operation at this path.

409idempotency_conflict

The Idempotency-Key was already used with a different body.

413payload_too_large

JSON bodies may be at most 64 KiB.

500internal_error

The call failed on our side. It is not billed; retry with the same Idempotency-Key.

JSON Schema

Request schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "invoiceNumber": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "pattern": "\\S"
    },
    "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])))$"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:Z))$",
      "description": "Actual XML creation timestamp, in UTC (YYYY-MM-DDTHH:mm:ssZ)."
    },
    "supplyDate": {
      "description": "Common delivery or service date, when known and different from the issue date.",
      "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])))$"
    },
    "seller": {
      "type": "object",
      "properties": {
        "nip": {
          "type": "string",
          "pattern": "^[0-9]{10}$",
          "description": "Polish NIP, ten digits without the PL prefix."
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "\\S"
        },
        "addressLine1": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "\\S"
        },
        "addressLine2": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "\\S"
        }
      },
      "required": [
        "nip",
        "name",
        "addressLine1"
      ],
      "additionalProperties": false
    },
    "buyer": {
      "type": "object",
      "properties": {
        "nip": {
          "type": "string",
          "pattern": "^[0-9]{10}$",
          "description": "Polish NIP, ten digits without the PL prefix."
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "\\S"
        },
        "addressLine1": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "\\S"
        },
        "addressLine2": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "\\S"
        }
      },
      "required": [
        "nip",
        "name",
        "addressLine1"
      ],
      "additionalProperties": false
    },
    "cashAccounting": {
      "type": "boolean",
      "description": "Whether the invoice requires the cash accounting annotation (metoda kasowa)."
    },
    "lines": {
      "minItems": 1,
      "maxItems": 500,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "pattern": "\\S"
          },
          "unit": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "pattern": "\\S"
          },
          "quantity": {
            "type": "string",
            "pattern": "^(?:[1-9][0-9]{0,15}|0)(?:\\.[0-9]{1,6})?$"
          },
          "unitNetPrice": {
            "type": "string",
            "pattern": "^(?:[1-9][0-9]{0,13}|0)(?:\\.[0-9]{1,8})?$"
          },
          "vatRate": {
            "type": "string",
            "enum": [
              "5",
              "8",
              "23",
              "0 KR"
            ],
            "description": "FA(3) P_12 code supplied by the issuer. 0 KR is domestic zero-rated sales."
          },
          "annex15": {
            "type": "boolean",
            "description": "Whether the goods or services fall under Annex 15 of the VAT Act."
          }
        },
        "required": [
          "description",
          "unit",
          "quantity",
          "unitNetPrice",
          "vatRate",
          "annex15"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "invoiceNumber",
    "issueDate",
    "createdAt",
    "seller",
    "buyer",
    "cashAccounting",
    "lines"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "invoiceNumber": "FV/2026/03/104",
      "issueDate": "2026-03-02",
      "createdAt": "2026-03-02T10:05:00Z",
      "supplyDate": "2026-02-27",
      "dueDate": "2026-03-16",
      "seller": {
        "nip": "5260250274",
        "name": "Przykładowy Dostawca sp. z o.o.",
        "addressLine1": "ul. Wolska 14, 01-201 Warszawa"
      },
      "buyer": {
        "nip": "8567346215",
        "name": "Przykładowy Nabywca sp. z o.o.",
        "addressLine1": "ul. Długa 4, 31-146 Kraków"
      },
      "cashAccounting": false,
      "lines": [
        {
          "description": "Konserwacja urządzeń",
          "unit": "godz.",
          "quantity": "2.5",
          "unitNetPrice": "120.00",
          "vatRate": "23",
          "annex15": false
        }
      ]
    }
  ]
}
Response schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "status": {
      "type": "string",
      "enum": [
        "valid",
        "invalid",
        "needs_review"
      ],
      "description": "Outcome of the local checks."
    },
    "xsd": {
      "type": "string",
      "enum": [
        "passed",
        "failed",
        "not_run"
      ]
    },
    "specification": {
      "type": "object",
      "properties": {
        "version": {
          "type": "string",
          "const": "1-0E"
        },
        "date": {
          "type": "string",
          "const": "2025-06-25"
        },
        "url": {
          "type": "string",
          "const": "https://crd.gov.pl/wzor/2025/06/25/13775/schemat.xsd"
        }
      },
      "required": [
        "version",
        "date",
        "url"
      ],
      "additionalProperties": false
    },
    "issues": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "severity": {
            "type": "string",
            "enum": [
              "error",
              "needs_review"
            ]
          },
          "rule": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "line": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "expected": {
            "type": "string"
          },
          "actual": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "format": "uri"
          }
        },
        "required": [
          "severity",
          "rule",
          "path",
          "expected",
          "actual",
          "source"
        ],
        "additionalProperties": false
      }
    },
    "xml": {
      "description": "FA(3) XML when the local checks pass.",
      "type": "string"
    }
  },
  "required": [
    "status",
    "xsd",
    "specification",
    "issues"
  ],
  "additionalProperties": false
}