Skip to main content

Idempotency

Retry POST /v1/extract safely with the Idempotency-Key header: a duplicate request within 24 hours returns the cached response, marked cached: true, free.

Pass an Idempotency-Key header on POST requests to safely retry without creating duplicate work. If a request with the same key has already been processed, the API returns the cached response, marked with cached: true in the body.

Most integrations use idempotency keys when calling POST /v1/extract to guard against network timeouts or duplicate submissions. A typical workflow is to generate a UUID per logical operation, attach it as the Idempotency-Key header, and retry the same request on failure without risk of double-processing.

The cached response is guaranteed for 24 hours and is scoped to your organization, not to the individual API key: any key in the same workspace replaying the idempotency key gets the same cached result, while the same key string used by a different organization is treated independently. A duplicate request within the window returns the original result immediately, with no additional credit cost. Do not rely on reusing a key after the 24-hour window — mint a fresh key per logical operation instead.

A cached replay is a reduced response: it carries extraction_id, the original request_id, status, a slim document object, the extracted data, and cached: true — the confidence and processing blocks of the original response are not replayed. Document visibility is re-checked on every replay: if a Sources IAM rule has since hidden the underlying document from the calling key, the replay returns the same 404 document_not_found a fresh request would, rather than leaking the cached content.

Idempotency covers the retry side of resilient pipelines; for the delivery side, configure a webhook destination and listen for extraction.complete events instead of polling. Note that reusing a key with different request parameters will still return the first request's cached result — always generate a fresh key for each distinct operation.

Idempotency details

Header`Idempotency-Key: <your-unique-key>`
Supported endpoints`POST /v1/extract` (primary use case). Other POST endpoints may honor it in the future.
Key formatAny string up to 64 characters. UUIDs (36 characters) recommended.
TTL24 hours guaranteed. Do not rely on reuse after the window — generate a fresh key per logical operation.
ScopePer organization (workspace). Any API key in the same workspace shares the cache; the same key string used by a different organization is independent.

Behavior

  • First request — processed normally. The response and extraction ID are cached against the key.
  • Duplicate request (same key within 24h) — returns the cached response immediately with HTTP 200 and cached: true. No new extraction is created and no credits are consumed.
  • After the 24h window — treated as a new request.

Cached replay response (200 OK)

{
  "extraction_id": "d1a2b3c4-5678-9abc-def0-1234567890ab",
  "request_id": "req_x7y8z9a0b1c2d3e4",
  "status": "complete",
  "document": {
    "id": "d1a2b3c4-5678-9abc-def0-1234567890ab",
    "filename": "invoice.pdf",
    "type_detected": "Invoice"
  },
  "data": {
    "vendor_name": "Acme GmbH",
    "total_amount": 14250.00
  },
  "cached": true
}

Example — safe retry with idempotency

# Generate a unique key per logical operation
IDEMPOTENCY_KEY=$(uuidgen)

curl -X POST https://api.talonic.com/v1/extract \
  -H "Authorization: Bearer $TALONIC_API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -F "file=@invoice.pdf" \
  -F 'schema={"vendor_name":"string","total_amount":"number"}'

# Safe to retry on network timeout — same key returns cached result
curl -X POST https://api.talonic.com/v1/extract \
  -H "Authorization: Bearer $TALONIC_API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -F "file=@invoice.pdf" \
  -F 'schema={"vendor_name":"string","total_amount":"number"}'
Always use a new idempotency key for each distinct logical operation. Reusing a key with different parameters will return the cached result from the first request, not process the new parameters.

Frequently asked questions

How do I prevent duplicate extractions on retry?+
Pass an Idempotency-Key header with a unique value (e.g. UUID) on POST /v1/extract. Retries with the same key return the cached result, marked cached: true, and consume no additional credits.
How long are idempotency keys valid?+
The cached response is guaranteed for 24 hours. Do not build on reuse after the window — generate a fresh key per logical operation, and treat any replay past 24 hours as undefined.
What happens if I reuse an idempotency key with different parameters?+
The API returns the cached response from the first request; the new parameters are ignored. Generate a fresh key for every distinct logical operation.
Is the idempotency cache shared between my API keys?+
Yes. The cache is scoped to your organization, so any key in the same workspace replaying the idempotency key receives the same cached result. The same key string used by a different organization is completely independent.
Does a cached replay return the full original response?+
No — it is a reduced shape: extraction_id, the original request_id, status, a slim document object, the extracted data, and cached: true. The confidence and processing blocks are not replayed; fetch them from GET /v1/extractions/{id} if you need them again.