Skip to content

Idempotency

Network failures happen after the server has already accepted a request. Without protection, a retry uploads the document again, creates a second job and bills twice. Send an Idempotency-Key header and Deskew will replay the original response instead.

Terminal window
curl https://api.deskew.dev/v1/extract \
-H "Authorization: Bearer $DESKEW_API_KEY" \
-H "Idempotency-Key: 7c9e6679-7425-40de-944b-e07fc1f90ae7" \
-F "file=@invoice.pdf" \
-F "output=json"
  1. On the first request with a given key, Deskew stores the status code and body of its response (200 with the result, or 202 with the job) together with a hash of the request.
  2. A repeat request with the same key within 24 hours returns that stored response unchanged, with the header Idempotent-Replayed: true. No new job is created and nothing is billed.
  3. After 24 hours the key is forgotten and the request is processed as new.

The request hash covers the file bytes and every extraction option (output, tables, quality, schema, …). pdf_password is excluded from the hash, so a retry that corrects a password is still the same request.

Reusing a key with a different file or different options is an error:

{
"error": {
"type": "invalid_request_error",
"code": "idempotency_conflict",
"message": "Idempotency-Key was already used with a different request.",
"doc_url": "https://docs.deskew.dev/errors#idempotency_conflict"
}
}

It is returned with status 409. Generate a new key for a genuinely new request.

  • Use a UUID v4 or another random value with at least 128 bits of entropy.
  • Generate the key before the first attempt and reuse it on every retry of that attempt.
  • Keys are scoped to the project, so two projects can use the same value without colliding.
  • Only POST /v1/extract supports idempotency keys. GET requests are naturally safe to retry; DELETE /v1/jobs/:id is a no-op once the job is no longer running.

If the original response was a 202, the replay is the same 202 with the same job id, even if the job has since completed. Follow it with GET /v1/jobs/:id as usual.