Skip to main content

Idempotency keys

A network can fail after Lurk got your request but before you got the answer. If you send it again, you do not want it counted twice. An idempotency key makes that safe: the same key means the same request.
  • An event carries it in the body, as idempotency_key. Every other write carries it in the Idempotency-Key header. The SDKs do both for you.
  • The same key with the same request returns the first answer again, byte for byte, and changes nothing.
  • The same key with a different request is idempotency_conflict (409): a key names one request, so use a new key for a new request.
  • Keys are remembered for 30 days.
  • A key in the Idempotency-Key header, or in the idempotency_key argument of an MCP tool, has the spaces, tabs and line breaks at its start and end dropped: k and k are the same key, and a key made only of them counts as no key (an operation that needs one answers validation_failed, “An idempotency key is required.”). A tab or line break inside the key is refused (validation_failed). A key in an event’s body (idempotency_key of events.send, over REST or MCP) is used exactly as sent, and a tab or line break anywhere in it is refused.
Build the key from something that is the same every time you retry the same thing: the order ID, the scan ID, the ID of the webhook delivery that started it. Never from Date.now() or a random value made per attempt, which makes a retry look like a new request.
The SDKs make a key for each call and reuse it on every retry of that call. Pass your own when you have an ID worth using (idempotencyKey in TypeScript, RequestOptions(idempotency_key=…) in Python), so a retry that comes from your own queue, hours later, is also safe.

What to retry

Every error says which side it is on: the SDKs have isRetryable / is_retryable, and the body has a next_step. A retry loop that never gives up is a bug: stop after a few tries and keep the event to send later. The SDKs already retry twice for you, with a jittered delay, on the cases marked Yes. A call that makes a secret shown once (a new API key, a new webhook endpoint) is not retried after a connection failure or server error, because a second call could make a second secret. It can be retried after 429, which refuses the call before anything changes. Cancelling a TypeScript call stops its retries. An interrupted response is a body that stops before the end, after the headers arrived. The TypeScript and Python SDKs both treat it like a dropped connection: a read, or a write that carries a key, is retried with the same key and the same body, and a write without a key (such as one that makes a secret) fails with LurkConnectionError instead of being repeated. Because the API may already have done the work, an interrupted response on a write is exactly why the key must stay the same.

Limits

Lurk limits how fast one key and one project can call it, to keep everyone’s calls quick. The numbers are per minute. Every answer carries RateLimit-Policy and RateLimit, which say what the nearest limit is and how much is left. Past a limit the answer is 429 with Retry-After, in seconds, and the usual error body. Wait that long and retry with the same key. If you hit it often, spread requests out, or send one event per thing that happened and let rules do the rest.

Tracing

Send a traceparent header and Lurk joins your trace. Every answer carries request-id (also x-request-id): quote it to support and we can find the call.