Safe retries for AI integrations: idempotency keys explained
Why AI integrations must survive timeouts and repeated requests without creating duplicate CRM records or orders, and how idempotency keys solve it.

- Networks fail after the server has done the work but before the caller hears back.
- A caller that retries can then create a second record, order or task.
- An idempotency key lets the server recognise a retry and return the original result.
The problem
An AI workflow calls an API to create a CRM task. The request times out. Did the task get created? The caller can’t know. If it gives up, work may be lost. If it retries, the customer may get two tasks, two quotes or two orders.
AI workflows make this more likely than usual: model calls are slow, steps are chained, and an agent may retry a tool call on its own.
The pattern
- The caller creates a unique key for each logical operation, for example one per approved email, and sends it in an
Idempotency-Keyheader. - The server stores the key with the request body and the result before replying.
- A repeat request with the same key and the same body receives the stored result, with no second write.
- A request that reuses a key with a different body is rejected with HTTP 409, because it is a different operation pretending to be a retry.
Details that matter
- Store the body fingerprint, not just the key, so a changed request can’t slip through.
- Decide the retention. Keep keys at least as long as any caller might retry, for example 24 hours.
- Handle concurrent duplicates: if two identical requests arrive together, one does the work and the other waits or gets a clear ‘in progress’ answer.
- Log both outcomes, so you can show an auditor that a replay returned the original task.
I show the exact request and response sequence (201 for the original, 200 reusing the result, 409 for a changed request) in the safe API retries guide, and this website’s own enquiry form uses the same approach for its request IDs. A small open-source implementation with tests is in inbox-crm-approval.
When you need it
Any time an automated caller writes to a system of record: CRM updates, orders, invoices, tickets. If you’re connecting two systems and want records to sync reliably, see the Custom API service.
Discuss your workflow
The first call is free. If it fits, I send a written scope and a fixed price.