Guides
Idempotency
Use X-Idempotency-Key to retry calls safely after a timeout or a network failure.
Idempotency guarantees that repeating the same call produces the same result as making it once. It prevents double deposits, withdrawals or accounts when you resend a request after a timeout.
The X-Idempotency-Key header
Every POST, PUT or PATCH call requires the X-Idempotency-Key header with a UUID you generate.
curl --request POST \
--url https://trace.mimicr.dev/v1/operations/withdrawals \
--header 'Authorization: Bearer <token>' \
--header 'X-Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000' \
--header 'Content-Type: application/json' \
--data '{ ... }'GET and DELETE do not need it. In Mimicr there are two exceptions where the header is optional: the token endpoint and the Webhooks API (/v1/subscriptions), whose examples in Trace's docs do not send it.
| Situation | Response |
|---|---|
| Header missing | 400 MISSING_REQUIRED_HEADER, details.header: "X-Idempotency-Key" |
| Value is not a UUID | 400 INVALID_DATA with INVALID_UUID on field header:X-Idempotency-Key |
| Same key, same request | The original status and body are returned again |
| Same key, different request | 409 IDEMPOTENCY_CONFLICT |
{
"code": "IDEMPOTENCY_CONFLICT",
"message": "Idempotency key already used with a different request",
"details": {}
}Trace's idempotency guide calls this code IDEMPOTENT_ID_CONFLICT, but every endpoint page uses IDEMPOTENCY_CONFLICT. Mimicr follows the endpoint pages.
How Mimicr compares requests
- "Same request" means same method, same path and same body.
- For multipart uploads the boundary changes on every send, so only method and path count.
- Keys are scoped to the customer and kept for 24 hours, on the sandbox clock.
- Only responses below 500 are stored. After a
500, you can retry with the same key and the call runs again. - A replayed response carries the
Idempotent-Replayed: trueheader.
These rules are Mimicr's choices; Trace does not document key lifetime or scope.
Generate one key per operation
import uuid idempotency_key = str(uuid.uuid4())
const idempotencyKey = crypto.randomUUID();
Store the key with the business intent (for example, the order that triggered the withdrawal) and reuse the same key when retrying that order.
# first attempt: timeout curl ... --header 'X-Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000' # retry with the same key: returns the original result curl ... --header 'X-Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000'
Never reuse a key for a different operation. Each business operation gets its own.
Test it
Turn on chaos for the operations area with errors after processing (apiErrorWhen: "after"): the call runs, but you get a 500. Retry with the same key and check that no duplicate operation shows up. See Sandbox control.