← Errors and troubleshooting

HTTP 409 · IDEMPOTENCY_KEY_REUSED

IDEMPOTENCY_KEY_REUSED: same key, different request

Send an Idempotency-Key header and the API remembers the response for 24 hours: retrying the same request returns the stored answer instead of computing again. Reuse that key for a different request and you get 409 - the API will not guess which one you meant.

Updated · every example recorded from a real API call

HTTP status
409 Conflict
Retry?
Not with this key. Use a new key for the new request.
Key lifetime
24 hours, scoped to the API key that sent it.
Which endpoints?
Every authenticated POST on the calculation API - charts, horoscopes and the job-starting endpoints alike.
Optional?
Yes. Without the header nothing is stored and this error cannot happen.

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
HTTP/1.1 200 OK
x-request-id: req_01M8RK47T0DX2ECGJRXDKMN3QF
idempotent-replayed: true
x-ratelimit-remaining: 5993
  • idempotent-replayed: true marks a stored answer. The body is byte-for-byte the first response - including the first call's request_id (req_01M8RK47SZQWPWFZAQ608QD1FJ) and meta.computed_at - while the x-request-id header 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-remaining fell 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:

json
{
  "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:

json
{
  "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-chart survives 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 202 and report id, with idempotent-replayed: true on the second, and no second job is queued (for the paid Cosmic Blueprint, no second credit is spent). A request that was refused (a 403, say) is not stored, so you can retry it with the same key once the cause is fixed.