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.
https://api.kanagu.dev/v1/ksef/generate- Price
- $0.04 per invoice, on successful calls only
- Authentication
- API key required.
- MCP
call_operationwithoperation: "ksef.generate"athttps://api.kanagu.dev/mcp- Markdown
- /docs/ksef.generate.md
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}]}}}}'{
"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)requiredissueDatestring (date)requiredcreatedAtstring (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)sellerobjectrequiredseller.nipstringrequired- Polish NIP, ten digits without the PL prefix.
seller.namestring (max 512 chars)requiredseller.addressLine1string (max 512 chars)requiredseller.addressLine2string (max 512 chars)buyerobjectrequiredbuyer.nipstringrequired- Polish NIP, ten digits without the PL prefix.
buyer.namestring (max 512 chars)requiredbuyer.addressLine1string (max 512 chars)requiredbuyer.addressLine2string (max 512 chars)cashAccountingbooleanrequired- Whether the invoice requires the cash accounting annotation (metoda kasowa).
linesarray of objectrequiredlines[].descriptionstring (max 512 chars)requiredlines[].unitstring (max 256 chars)requiredlines[].quantitystringrequiredlines[].unitNetPricestringrequiredlines[].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"requiredspecificationobjectrequiredspecification.version"1-0E"requiredspecification.date"2025-06-25"requiredspecification.url"https://crd.gov.pl/wzor/2025/06/25/13775/schemat.xsd"requiredissuesarray of objectrequiredissues[].severity"error" | "needs_review"requiredissues[].rulestringrequiredissues[].pathstringrequiredissues[].lineinteger (≤ 9007199254740991)issues[].expectedstringrequiredissues[].actualstringrequiredissues[].sourcestring (uri)requiredxmlstring- FA(3) XML when the local checks pass.
Try it
Errors
Errors are JSON {"error":{"code","message"}}. An operation may add its own 400 codes; the message says what to fix.
| Status | Code and meaning |
|---|---|
| 400 | invalid_inputThe body does not match the request schema. The message names each field. |
| 400 | invalid_jsonThe body is missing or is not valid JSON. |
| 400 | invalid_idempotency_keyIdempotency-Key must be 1–128 visible ASCII characters. |
| 401 | invalid_api_keyThe Bearer key is missing, malformed, invalid or inactive. |
| 402 | free_allowance_exhaustedThis 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_foundNo operation at this path. |
| 409 | idempotency_conflictThe Idempotency-Key was already used with a different body. |
| 413 | payload_too_largeJSON bodies may be at most 64 KiB. |
| 500 | internal_errorThe 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
}