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.

Example screen; the company is fictional.
In short
  • 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

  1. The caller creates a unique key for each logical operation, for example one per approved email, and sends it in an Idempotency-Key header.
  2. The server stores the key with the request body and the result before replying.
  3. A repeat request with the same key and the same body receives the stored result, with no second write.
  4. 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

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.