# Idempotency

> Retry extraction requests safely with the Idempotency-Key header.

Networks fail. If a `POST /v1/extractions` times out, you cannot tell whether the job
was created. Send an `Idempotency-Key` header and retry with the same key: Parsefox
returns the job the first request created instead of starting (and charging) a second
one.

```bash
curl "$PARSEFOX_BASE_URL/v1/extractions" \
  -H "Authorization: Bearer $PARSEFOX_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: invoice-2026-0042" \
  -d '{"document_id": "doc_a624f2b16bfc", "schema_id": "sch_8f73a8efa4f34f87", "schema_version": 2}'
```

## Rules

- Supported on `POST /v1/extractions` and `POST /v1/schema-suggestions`.
- Use a value that identifies this request, such as
  `<document_id>:<schema_id>:<schema_version>`, or a random UUID you store before
  sending.
- Keys are scoped to your account and mode; a test key and a live key never share
  them. They do not expire.
- Reusing a key with a **different** request body (document, schema, template or
  `metadata`) returns `409 idempotency_conflict`.
- A retried request returns the original job with its current status.
- To run the same document again on purpose (for example after a failure), use a new
  key.

Uploads are not deduplicated: uploading the same file again creates a new document
with a new `document_id`. To process each of your files only once, even across
restarts, record the `document_id` and `job_id` in your own database after each step
and resume from them, rather than uploading again.

## Retry strategy

1. Create the extraction with an `Idempotency-Key`.
2. On a network error or `5xx`, retry with the same key after 1, 2, 4, 8 … seconds.
3. On `429`, wait for `Retry-After` and retry with the same key.
4. Do not retry other `4xx` responses; fix the request.

Webhook deliveries are idempotent on your side through `Parsefox-Event-Id`; see
[Webhooks](/docs/webhooks.md#respond-and-retry).
