# ksef.validate

Check KSeF FA(3) XML against the official XSD and selected invoice rules. Results cover local preflight validation.

- REST: `POST https://api.kanagu.dev/v1/ksef/validate`
- MCP: `call_operation` with `operation: "ksef.validate"` at https://api.kanagu.dev/mcp
- Price: $0.04 USD per invoice, on successful calls only.
- Auth: `Authorization: Bearer <key>` for REST and `call_operation`. Retries: reuse `Idempotency-Key` (MCP: `idempotencyKey`).

## Compliance coverage

- Domain: Tax & e-invoicing
- Jurisdictions: PL
- Standard: FA(3) XML schema (CRWDE 13775) 1-0E (2025-06-25) — https://crd.gov.pl/wzor/2025/06/25/13775/schemat.xsd
- Standard: Ministry of Finance StrukturyDanych XSD 10-0E (2022-01-05) — https://crd.gov.pl/xml/schematy/dziedzinowe/mf/2022/01/05/eD/DefinicjeTypy/StrukturyDanych_v10-0E.xsd
- Standard: Ministry of Finance ElementarneTypyDanych XSD 10-0E (2022-01-05) — https://crd.gov.pl/xml/schematy/dziedzinowe/mf/2022/01/05/eD/DefinicjeTypy/ElementarneTypyDanych_v10-0E.xsd
- Standard: Ministry of Finance KodyKrajow XSD 10-0E (2022-01-05) — https://crd.gov.pl/xml/schematy/dziedzinowe/mf/2022/01/05/eD/DefinicjeTypy/KodyKrajow_v10-0E.xsd
- Standard: Ministry of Finance FA(3) information guide August 2026 (2026-08-26) — https://ksef.podatki.gov.pl/media/nuclnu0w/broszura-informacyjna-dotyczaca-struktury-logicznej-fa-3.pdf
- Standard: Polish VAT Act, Article 106e Dz.U. 2026 poz. 1263 (2026-09-28) — https://eli.gov.pl/eli/DU/2026/1263/ogl
- Standard: KSeF invoice verification 2026-04-09 (2026-04-09) — https://github.com/CIRFMF/ksef-api/blob/c67c589c4bc695bfde9541133b35ec6b8e794562/faktury/weryfikacja-faktury.md
- Standard: Extensible Markup Language (XML) 1.0, fifth edition (2008-11-26) — https://www.w3.org/TR/2008/REC-xml-20081126/
- 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

## Request body

- `xml` (string (max 1048576 chars), required)

## Response

- `status` ("valid" | "invalid" | "needs_review", required): Outcome of the local checks.
- `xsd` ("passed" | "failed" | "not_run", required)
- `specification` (object, required)
- `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)
- `issues` (array of object, required)
- `issues[].severity` ("error" | "needs_review", required)
- `issues[].rule` (string, required)
- `issues[].path` (string, required)
- `issues[].line` (integer (≤ 9007199254740991))
- `issues[].expected` (string, required)
- `issues[].actual` (string, required)
- `issues[].source` (string (uri), required)

## Example

```sh
curl https://api.kanagu.dev/v1/ksef/validate \
  -H "Authorization: Bearer $KANAGU_KEY" \
  -H "Content-Type: application/json" \
  -d '{"xml":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Faktura xmlns=\"http://crd.gov.pl/wzor/2025/06/25/13775/\"><Naglowek><KodFormularza kodSystemowy=\"FA (3)\" wersjaSchemy=\"1-0E\">FA</KodFormularza><WariantFormularza>3</WariantFormularza><DataWytworzeniaFa>2026-03-02T10:05:00Z</DataWytworzeniaFa><SystemInfo>Kanagu</SystemInfo></Naglowek><Podmiot1><DaneIdentyfikacyjne><NIP>5260250274</NIP><Nazwa>Przykładowy Dostawca sp. z o.o.</Nazwa></DaneIdentyfikacyjne><Adres><KodKraju>PL</KodKraju><AdresL1>ul. Wolska 14, 01-201 Warszawa</AdresL1></Adres></Podmiot1><Podmiot2><DaneIdentyfikacyjne><NIP>8567346215</NIP><Nazwa>Przykładowy Nabywca sp. z o.o.</Nazwa></DaneIdentyfikacyjne><Adres><KodKraju>PL</KodKraju><AdresL1>ul. Długa 4, 31-146 Kraków</AdresL1></Adres><JST>2</JST><GV>2</GV></Podmiot2><Fa><KodWaluty>PLN</KodWaluty><P_1>2026-03-02</P_1><P_2>FV/2026/03/104</P_2><P_6>2026-02-27</P_6><P_13_1>300.00</P_13_1><P_14_1>69.00</P_14_1><P_15>369.00</P_15><Adnotacje><P_16>2</P_16><P_17>2</P_17><P_18>2</P_18><P_18A>2</P_18A><Zwolnienie><P_19N>1</P_19N></Zwolnienie><NoweSrodkiTransportu><P_22N>1</P_22N></NoweSrodkiTransportu><P_23>2</P_23><PMarzy><P_PMarzyN>1</P_PMarzyN></PMarzy></Adnotacje><RodzajFaktury>VAT</RodzajFaktury><FaWiersz><NrWierszaFa>1</NrWierszaFa><P_7>Konserwacja urządzeń</P_7><P_8A>godz.</P_8A><P_8B>2.5</P_8B><P_9A>120.00</P_9A><P_11>300.00</P_11><P_12>23</P_12></FaWiersz><Platnosc><TerminPlatnosci><Termin>2026-03-16</Termin></TerminPlatnosci></Platnosc></Fa></Faktura>"}'
```

```ts
const res = await fetch("https://api.kanagu.dev/v1/ksef/validate", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KANAGU_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Faktura xmlns=\"http://crd.gov.pl/wzor/2025/06/25/13775/\"><Naglowek><KodFormularza kodSystemowy=\"FA (3)\" wersjaSchemy=\"1-0E\">FA</KodFormularza><WariantFormularza>3</WariantFormularza><DataWytworzeniaFa>2026-03-02T10:05:00Z</DataWytworzeniaFa><SystemInfo>Kanagu</SystemInfo></Naglowek><Podmiot1><DaneIdentyfikacyjne><NIP>5260250274</NIP><Nazwa>Przykładowy Dostawca sp. z o.o.</Nazwa></DaneIdentyfikacyjne><Adres><KodKraju>PL</KodKraju><AdresL1>ul. Wolska 14, 01-201 Warszawa</AdresL1></Adres></Podmiot1><Podmiot2><DaneIdentyfikacyjne><NIP>8567346215</NIP><Nazwa>Przykładowy Nabywca sp. z o.o.</Nazwa></DaneIdentyfikacyjne><Adres><KodKraju>PL</KodKraju><AdresL1>ul. Długa 4, 31-146 Kraków</AdresL1></Adres><JST>2</JST><GV>2</GV></Podmiot2><Fa><KodWaluty>PLN</KodWaluty><P_1>2026-03-02</P_1><P_2>FV/2026/03/104</P_2><P_6>2026-02-27</P_6><P_13_1>300.00</P_13_1><P_14_1>69.00</P_14_1><P_15>369.00</P_15><Adnotacje><P_16>2</P_16><P_17>2</P_17><P_18>2</P_18><P_18A>2</P_18A><Zwolnienie><P_19N>1</P_19N></Zwolnienie><NoweSrodkiTransportu><P_22N>1</P_22N></NoweSrodkiTransportu><P_23>2</P_23><PMarzy><P_PMarzyN>1</P_PMarzyN></PMarzy></Adnotacje><RodzajFaktury>VAT</RodzajFaktury><FaWiersz><NrWierszaFa>1</NrWierszaFa><P_7>Konserwacja urządzeń</P_7><P_8A>godz.</P_8A><P_8B>2.5</P_8B><P_9A>120.00</P_9A><P_11>300.00</P_11><P_12>23</P_12></FaWiersz><Platnosc><TerminPlatnosci><Termin>2026-03-16</Termin></TerminPlatnosci></Platnosc></Fa></Faktura>"
  }),
});
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.
- 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": {
    "xml": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1048576
    }
  },
  "required": [
    "xml"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Faktura xmlns=\"http://crd.gov.pl/wzor/2025/06/25/13775/\"><Naglowek><KodFormularza kodSystemowy=\"FA (3)\" wersjaSchemy=\"1-0E\">FA</KodFormularza><WariantFormularza>3</WariantFormularza><DataWytworzeniaFa>2026-03-02T10:05:00Z</DataWytworzeniaFa><SystemInfo>Kanagu</SystemInfo></Naglowek><Podmiot1><DaneIdentyfikacyjne><NIP>5260250274</NIP><Nazwa>Przykładowy Dostawca sp. z o.o.</Nazwa></DaneIdentyfikacyjne><Adres><KodKraju>PL</KodKraju><AdresL1>ul. Wolska 14, 01-201 Warszawa</AdresL1></Adres></Podmiot1><Podmiot2><DaneIdentyfikacyjne><NIP>8567346215</NIP><Nazwa>Przykładowy Nabywca sp. z o.o.</Nazwa></DaneIdentyfikacyjne><Adres><KodKraju>PL</KodKraju><AdresL1>ul. Długa 4, 31-146 Kraków</AdresL1></Adres><JST>2</JST><GV>2</GV></Podmiot2><Fa><KodWaluty>PLN</KodWaluty><P_1>2026-03-02</P_1><P_2>FV/2026/03/104</P_2><P_6>2026-02-27</P_6><P_13_1>300.00</P_13_1><P_14_1>69.00</P_14_1><P_15>369.00</P_15><Adnotacje><P_16>2</P_16><P_17>2</P_17><P_18>2</P_18><P_18A>2</P_18A><Zwolnienie><P_19N>1</P_19N></Zwolnienie><NoweSrodkiTransportu><P_22N>1</P_22N></NoweSrodkiTransportu><P_23>2</P_23><PMarzy><P_PMarzyN>1</P_PMarzyN></PMarzy></Adnotacje><RodzajFaktury>VAT</RodzajFaktury><FaWiersz><NrWierszaFa>1</NrWierszaFa><P_7>Konserwacja urządzeń</P_7><P_8A>godz.</P_8A><P_8B>2.5</P_8B><P_9A>120.00</P_9A><P_11>300.00</P_11><P_12>23</P_12></FaWiersz><Platnosc><TerminPlatnosci><Termin>2026-03-16</Termin></TerminPlatnosci></Platnosc></Fa></Faktura>"
    }
  ]
}
```

Response:
```json
{
  "$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
      }
    }
  },
  "required": [
    "status",
    "xsd",
    "specification",
    "issues"
  ],
  "additionalProperties": false
}
```
