Overview
Retrying a timed-out KSeF submission blindly can create a duplicate invoice, because the request may have reached KSeF even though you never saw the response. The safe pattern is to attach a stable idempotency key to every submission, check the invoice's status before resubmitting, and only send a new attempt when you are certain no earlier attempt succeeded.
Why timeouts are dangerous
KSeF (Krajowy System e-Faktur) is Poland's national e-invoicing platform run by the Ministry of Finance (Ministerstwo Finansów). When you submit a FA(3) invoice over the network, a timeout is ambiguous: the request may have failed before reaching KSeF, or it may have been accepted and only the response was lost. If you assume the worst and resend the same document, you can end up with two structured invoices for one transaction.
The idempotency-key pattern
The fix is to make each submission identifiable. The KSeF API itself does not accept a native idempotency-key parameter, so the key lives in the layer that calls KSeF. Derive it from your own invoice identifier, store it with your invoice record, and reuse it for every retry of that invoice. A key generated fresh on every run, such as a new random UUID per request, protects nothing.
Check status before you retry
Before resubmitting anything, find out whether the earlier attempt landed. If it did, the correct action is to stop and read the result (the KSeF number, and the UPO when KSeF issues it) instead of sending again.
Backoff, not hammering
When KSeF or your own connection is unavailable, retry with backoff — a short delay that grows with each attempt — rather than firing requests in a tight loop. A timeout is a signal to slow down and verify, not to resend immediately.
How Notaly handles it
POST /invoices accepts an Idempotency-Key header. If your call to Notaly times out, repeat it with the same key: Notaly returns the invoice it already stored, with its current status, and does not call KSeF again. Without the header, every POST creates a new invoice.
If the stored invoice is submitted, the submission reached KSeF and you only wait for the final status. If the response is draft with error: "ksef_submitting", KSeF has not confirmed the submission yet. Do not send a new POST and do not issue the invoice again under a new number: Notaly resends the same XML automatically. Poll GET /invoices/{id} until the status is submitted. If the status is submitted with error: "ksef_duplicate_review", KSeF already has this invoice from an earlier attempt. Do not reissue it with another number; we link it to the KSeF record on our side. If you need it sooner, write to hello@getnotaly.com with the invoice id. If the invoice is draft with error: "ksef_retry_exhausted", Notaly has stopped resending it automatically (after 24 hours, or earlier if KSeF returned a definitive error). Do not create a new invoice: write to hello@getnotaly.com with the invoice id, and we check in KSeF whether it arrived before anything is resent.
The final result — accepted with a KSeF number, or rejected with an error code — reaches you through a signed webhook, or through GET /invoices/{id}.
Disclaimer
Notaly is not a tax, accounting or legal advisor. This article is general information, not tax advice, and may be outdated. You are responsible for your own VAT compliance; confirm with a qualified accountant where required.
Sources
Source: api-test.ksef.mf.gov.pl