What a replay looks like
We sent the sample birth to POST /v1/charts/birth twice with Idempotency-Key: order-8812-chart. The second response was a replay:
HTTP/1.1 200 OK x-request-id: req_01M8RK47T0DX2ECGJRXDKMN3QF idempotent-replayed: true x-ratelimit-remaining: 5993
idempotent-replayed: truemarks a stored answer. The body is byte-for-byte the first response - including the first call'srequest_id(req_01M8RK47SZQWPWFZAQ608QD1FJ) andmeta.computed_at- while thex-request-idheader is new. Log the header if you need to trace the retry itself.- A replay is a 2xx, so it still passes the rate limiter (
x-ratelimit-remainingfell from 5994 to 5993) and is billed like any successful call. Idempotency protects you from duplicate work and duplicate side effects, not from quota use. The 409 itself is not billed.
What triggers the 409
Then we reused the same key with the birth time changed to 17:35:
{
"request_id": "req_01M8RK47T15RM4NB0HQD5ZZ9VK",
"error": {
"code": "IDEMPOTENCY_KEY_REUSED",
"message": "Idempotency-Key was reused with a different request body"
}
}The comparison is a hash of the request body after parsing, so whitespace and the order of keys do not matter - the same five fields sent in a different order replayed normally. Any changed value does. Headers and the query string are not part of the comparison.
The body behind both requests, before the time change:
{
"date": "1973-04-24",
"time": "17:25:00",
"tz_offset_minutes": 330,
"lat": 19.076,
"lng": 72.8777
}Choosing keys
- Derive the key from the thing you are doing, not from the attempt:
order-8812-chartsurvives a crash and a retry; a fresh UUID per attempt protects nothing. - Include anything that changes the request in the key, or generate a new key whenever the user edits the input.
- Keys are scoped per API key, so two of your services using different API keys cannot collide.
- Maximum 255 characters; longer is a VALIDATION_ERROR.
- The endpoints that start a job - bulk matching and the PDF reports - honour it too, and that is where it matters most: the same body sent twice with the same key returns the same
202and report id, withidempotent-replayed: trueon the second, and no second job is queued (for the paid Cosmic Blueprint, no second credit is spent). A request that was refused (a403, say) is not stored, so you can retry it with the same key once the cause is fixed.