A timeout tells you nothing about whether the work happened. An idempotency key lets you ask again without risking a second charge, a second post or a second file.
AI disclosure. This longread was drafted by AI (Claude, from an earlier Grok Bot draft) for Apiary. It has not been reviewed or verified by the founder. Sources were opened and read on 26 November 2026; provider documentation changes often, so dated limits are marked. Worked examples are hypothetical.
When a request times out, you usually do not know whether it ran. The server may never have received it. It may have finished the work and lost the response on the way back. Or it may still be working. If the request was "create a payment," "publish this article" or "upload this file," a blind retry risks doing the job twice.
An idempotency key is a unique value the client attaches to one intended operation and reuses on every retry of that same operation. A server that supports keys remembers what happened the first time it saw the key. When the retry arrives, the server returns the first result (or finishes the first attempt) instead of repeating the side effect. The IETF's working draft on the subject describes the purpose in one line: the header "can be used to make non-idempotent HTTP methods such as POST or PATCH fault-tolerant" (IETF draft-ietf-httpapi-idempotency-key-header-09, 21 November 2026).
The key helps only when four conditions hold: the server actually supports keys for that endpoint; the client reuses the same key rather than generating a new one for the retry; the retry carries the same request body; and the retry arrives before the server has forgotten the key. Miss any one of those and the protection silently disappears. The rest of this article explains why, using the HTTP standard, the IETF draft, and the published behavior of Stripe, AWS and a few common tools, and then covers what a server has to store, the edge cases that break naive implementations, and a checklist for anyone building an automation or AI agent that writes to other systems.
1. The problem a timeout creates
Stripe's engineering blog lays out the three ways a call between two machines can fail: "The initial connection could fail as the client tries to connect to a server"; "The call could fail midway while the server is fulfilling the operation, leaving the work in limbo"; and "The call could succeed, but the connection break before the server can tell its client about it" (Leach, Stripe blog, 22 February 2017). The post notes that in some cases "the failure is definitive enough that the client knows with good certainty that it's safe to simply retry," such as "a total failure to even establish a connection," but that "in many others though, the success of the operation is ambiguous from the perspective of the client" (same source).
A client-side timeout sits squarely in the ambiguous group. The timer ran out on your side; it says nothing about the server's side. The IETF draft describes the same situation: a client sends a POST, "the request timed out," and "the client is left uncertain about the status of the resource. It doesn't know if the resource was created or updated, or if the server even completed processing the request. Furthermore, the client does not know if it can safely retry the request" (IETF draft-09).
AWS describes a version of this with real stakes. In a Builders' Library article, an AWS principal engineer imagines a customer whose workload must run on "at most one" EC2 instance. The provisioning process asks EC2 to launch it and, "perhaps due to a network timeout," gets no response. "Simply retrying the request could result in multiple workloads, which could have dire consequences" (Featonby, AWS Builders' Library, "Making retries safe with idempotent APIs"). The alternative, reconciling by looking for the instance, is "a lot of heavy lifting," and even then "there might still be some uncertainty. What if the resource is there but created by another provisioning process?" (same source). That last question is the one idempotency keys answer and a plain "does it exist?" check cannot.
2. What HTTP itself already promises
The HTTP standard defines idempotence at the level of request methods. RFC 9110 says: "A request method is considered 'idempotent' if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request. Of the request methods defined by this specification, PUT, DELETE, and safe request methods are idempotent" (RFC 9110 §9.2.2, June 2022). Safe methods are those whose semantics are "essentially read-only," such as GET and HEAD (RFC 9110 §9.2.1).
The point of the property, in the RFC's words, is retry: "Idempotent methods are distinguished because the request can be repeated automatically if a communication failure occurs before the client is able to read the server's response." Its example is a PUT whose connection closes before any response arrives; the client can reconnect and retry, because "repeating the request will have the same intended effect, even if the original request succeeded, though the response might differ" (RFC 9110 §9.2.2).
POST and PATCH are not in that list. For them, the RFC sets a clear default: "A client SHOULD NOT automatically retry a request with a non-idempotent method unless it has some means to know that the request semantics are actually idempotent, regardless of the method, or some means to detect that the original request was never applied." It adds that "a proxy MUST NOT automatically retry non-idempotent requests" and that "a client SHOULD NOT automatically retry a failed automatic retry" (RFC 9110 §9.2.2). The companion HTTP/1.1 document points back to the same rule when it discusses connections that close unexpectedly (RFC 9112 §9.3.1, June 2022).
Two details in RFC 9110 matter for API designers.
- Idempotence is about intended effect, not identical bytes. The RFC says "the idempotent property only applies to what has been requested by the user; a server is free to log each request separately, retain a revision control history, or implement other non-idempotent side effects for each idempotent request" (RFC 9110 §9.2.2). A second identical PUT may return a different status, such as 200 instead of 201, and still be idempotent.
- The method label is a promise the server has to keep. Nothing stops a careless implementation from making a GET increment a counter or a DELETE send an email. The RFC's definitions describe what clients are entitled to assume, not what every server actually does.
An idempotency key is, in RFC 9110's terms, a "means to know that the request semantics are actually idempotent." It turns one specific POST into an operation the client may safely repeat, provided the server honors it.
3. How an idempotency key works, step by step
The mechanism is simple to state. Stripe's blog describes it: "When performing a request, a client generates a unique ID to identify just that operation and sends it up to the server along with the normal payload. The server receives the ID and correlates it with the state of the request on its end. If the client notices a failure, it retries the request with the same ID, and from there it's up to the server to figure out what to do with it" (Leach, Stripe blog, 2017).
The same post then walks through what the server does in each failure case (vendor description of Stripe's design):
- Connection failure before the server saw anything. "On the second request the server will see the ID for the first time, and process it normally."
- Failure midway through. "The server picks up the work and carries it through. The exact behavior is heavily dependent on implementation, but if the previous operation was successfully rolled back by way of an ACID database, it'll be safe to retry it wholesale. Otherwise, state is recovered and the call is continued."
- Lost response after success. "The server simply replies with a cached result of the successful operation."
The IETF draft generalizes this into two cases for a key the server has already seen. If "the request was retried after the original request completed," the resource "SHOULD respond with a response consistent with the request being completed according to the user's intent." If "the request was retried before the original request completed," the resource "SHOULD respond with a resource conflict error" (IETF draft-09 §2.6).
Notice what the client does in all three cases: exactly the same thing. It resends the identical request with the identical key. That is the real benefit. As Stripe's blog puts it, the client "can continue to retry until it verifiably succeeds," which "fully addresses the problem of an ambiguous failure because the client knows that it can safely handle any failure using one simple technique" (Leach, Stripe blog, 2017).
4. Header, not body: the proposed standard
The existing Apiary page on this topic showed the key inside the JSON body ("idempotency_key": "abc123"). Some APIs do accept keys in the body, but the convention that is being standardized puts the key in an HTTP request header named Idempotency-Key.
As of 26 November 2026, the IETF HTTPAPI working group's document is at revision 09, published 21 November 2026 and expiring 25 May 2027, by J. Jena, S. Dalal and D. Tishkin, with an intended status of Standards Track (IETF draft-09). It is still an Internet-Draft, and its own boilerplate says it is "inappropriate to use Internet-Drafts as reference material or to cite them other than as 'work in progress.'" Individual APIs may differ from it. With that caveat, these are its main proposals:
- Syntax.
Idempotency-Keyis "an Item Structured Header Field" whose value "MUST be a String," so it is written in quotes, for exampleIdempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"(§2.1, §6). - Uniqueness. "The idempotency key MUST be unique and MUST NOT be reused with another request with a different request payload." It is "RECOMMENDED that a UUID [RFC9562] or a similar random identifier be used" (§2.2).
- Expiry. "The resource MAY require time based idempotency keys to be able to purge or delete a key upon its expiry. The resource SHOULD define such expiration policy and publish it in the documentation" (§2.3).
- Fingerprints. A resource "MAY compute a fingerprint of the request payload and store it together with the idempotency key, in order to detect a key being reused with a different request" (§2.4).
- Errors. A missing key on an operation that requires one gets 400; a key reused "with a different request payload" gets 422; a retry "while the original request is still being processed" gets 409 (§2.7).
- Client expectations. A client may send the header to signal intent, but "without a priori knowledge, a general client cannot assume the server will respect this request" (§2.5.1).
The draft's implementation-status section lists organizations that already use a header named Idempotency-Key, including Stripe, Adyen, Dwolla and Worldpay, and others that "implement the general concept" under different names, such as PayPal's PayPal-Request-Id and Chargebee's chargebee-idempotency-key (IETF draft-09 §4). AWS uses a request field rather than a header: "In many AWS API operations, the unique client request identifier is modeled by the ClientToken field" (Featonby, AWS Builders' Library). The practical rule is to read the documentation for the API you are calling, because the name and placement vary.
Correction to the Grok draft: the draft cited revision 07 (15 October 2025). When checked on 26 November 2026, datatracker showed revision 09, whose change log says it "Relaxed the requirement to document idempotency behavior from MUST to SHOULD" and "Clarified optional request fingerprints and duplicate-request handling" (IETF draft-09, Appendix A).
5. A worked reference: Stripe's documented behavior
Stripe is the most widely cited public implementation, and its documentation is unusually specific. Everything in this section is vendor documentation, checked on 26 November 2026; it describes Stripe and no one else.
What is stored, and when. "For API v1, Stripe saves the status code and body of the first request made with a given idempotency key after endpoint execution begins. Retries with the same key return the saved response, including 500 errors" (Stripe API reference, Idempotent requests). The phrase "after endpoint execution begins" is important. "If incoming parameters fail validation, or the request conflicts with another request that's executing concurrently, we don't save the idempotent result because no API endpoint initiates the execution. You can retry these requests" (same source). Stripe's advanced error-handling page adds that errors before execution, "such as invalid parameters, an invalid API key, or rate limiting, don't cache a result" (Stripe, Advanced error handling).
API v2 behaves differently. "With API v2, retries don't repeat successful operations. Stripe retries failed or partially failed work to completion when possible and returns an updated response. If a retry can't succeed, Stripe returns an error explaining why" (Stripe API reference). The advanced page says v2 "uses different replay behavior and a 30-day window" (Stripe, Advanced error handling). So even within one provider, "what does a retry return?" has two different answers depending on API version.
Key format. Stripe suggests "V4 UUIDs, or another random string with enough entropy to avoid collisions." Keys "are up to 255 characters long," and Stripe says to "avoid using sensitive data (for example, email addresses or personal identifiers) as idempotency keys" (Stripe API reference). The advanced page also allows a second strategy: "Derive the key from a user-attached object, like the ID of a shopping cart," which "provides a relatively straightforward way to protect against double submissions" (Stripe, Advanced error handling).
Retention. For v1, "you can remove keys from the system automatically after they're at least 24 hours old. We generate a new request if a key is reused after the original is pruned" (Stripe API reference). The error-handling guide turns this into an instruction: "Retry a connection error with the same key and parameters within the first 24 hours after the original request. After that window, Stripe can remove the key, and reusing it can execute a new request" (Stripe, Error handling).
Parameter checks. "The idempotency layer compares incoming parameters to those of the original request and errors if they're not the same to prevent accidental misuse" (Stripe API reference).
Which methods. "For API v1, all POST requests accept idempotency keys. Don't send idempotency keys in GET and DELETE requests because it has no effect. These requests are idempotent by definition" (same source).
Replay and retry signals. "To identify a previously executed response that's being replayed from the server, look for the header Idempotent-Replayed: true." Stripe also sends a Stripe-Should-Retry response header: true means retry "using exponential backoff," false means "Don't retry the request," and when it is absent you "use the status code and other response information to decide" (Stripe, Advanced error handling).
6. What a server has to store
If you are building the receiving side, the documented designs above imply a small record per key. The following is an editorial synthesis of those sources, not a quote from any one of them.
| Field | Why it is needed | Source of the idea |
|---|---|---|
| The key itself, scoped to a caller | Two customers might pick the same key; the lookup must include who sent it | AWS keys the "session" on "the customer identifier and their unique client request identifier"; the IETF draft recommends "a unique composite key" |
| A fingerprint of the request | To detect the same key reused for a different request | IETF draft §2.4; AWS stores "the parameters used to make the initial request"; Stripe compares parameters |
| A status: in progress, complete | To answer a concurrent retry with "still working" instead of running twice | IETF draft §2.6 (409); AWS Lambda Powertools INPROGRESS |
| The saved response (status and body) | To replay the first result on a retry | Stripe v1 saves "the status code and body"; AWS returns "a semantically equivalent response" |
| Created and expiry times | To purge old keys on a published schedule | IETF draft §2.3; Stripe's 24-hour minimum |
The hardest requirement is atomicity. AWS states it directly: "the process that combines recording the idempotent token and all mutating operations related to servicing the request must meet the properties for an atomic, consistent, isolated, and durable (ACID) operation." Otherwise you could "record the idempotent token and fail to create some resources or, alternatively, create the resources and fail to record the idempotent token" (Featonby, AWS Builders' Library). Either half-state defeats the purpose: in the first, a retry is told "done" when nothing was done; in the second, a retry does the work again.
In a relational database, the usual building block is a unique constraint on the key column plus an insert that cannot race. PostgreSQL documents that its ON CONFLICT clause "specifies an alternative action to raising a unique violation," that "ON CONFLICT DO NOTHING simply avoids inserting a row," and that "ON CONFLICT DO UPDATE guarantees an atomic INSERT or UPDATE outcome; provided there is no independent error, one of those two outcomes is guaranteed, even under high concurrency" (PostgreSQL 19 documentation, INSERT). The same current documentation describes an ON CONFLICT DO SELECT form, "also known as idempotent insert or get or create" (same source); check that your server version supports it before relying on it. The pattern (insert the key row first, inside the same transaction as the business write) is a general technique, not a PostgreSQL-only one.
7. Saved results versus re-execution: implementations disagree
A subtle question has no single answer: if the first attempt failed with a server error, should a retry with the same key return that saved error, or try again?
- Stripe API v1 replays the saved error. Retries "return the saved response, including 500 errors" (Stripe API reference). The advanced guide says that for a 500, "the operation might have produced side effects even though you received an error," so "don't retry with a new idempotency key until you've resolved the original outcome" (Stripe, Advanced error handling). It also notes that during incident recovery Stripe "attempts to reconcile failed operations and send webhook events," but "the cached response doesn't change, and reconciliation isn't guaranteed to resolve every operation" (same source).
- Stripe API v2 tries to finish the work. It "retries failed or partially failed work to completion when possible" (Stripe API reference).
- AWS Lambda Powertools deletes the record on an unhandled exception. Its documentation lists "unhandled exception" among the cases that "can cause new invocations to execute your code again despite having the same payload": "We catch them to delete the idempotency record to prevent inconsistencies, then propagate them" (Powertools for AWS Lambda (Python), Idempotency). A retry then runs the function again.
Each choice has a logic. Replaying the error is conservative: the server does not know how far the failed attempt got, so it refuses to guess. Deleting the record and re-running is convenient, but it is only safe if the failed attempt left no side effects, which in practice means the work was inside a transaction that rolled back. The editorial suggestion for clients is simple: never assume which behavior an API has. Read its documentation, and if a retry with the same key returns the same 500, treat that as "outcome unknown" and reconcile, rather than switching to a new key.
8. Expiry: the window that quietly closes
A key is useful only while the server remembers it. Stripe v1 keeps keys for at least 24 hours and may prune them afterwards; a reused key after pruning creates a new request (Stripe API reference). Other systems choose very different windows:
| System (documented, checked 26 Nov 2026) | Default window |
|---|---|
| Stripe API v1 | Keys kept "for at least 24 hours" (Stripe) |
| Stripe API v2 | "a 30-day window" (Stripe) |
| Amazon SQS FIFO queues, message deduplication | "the 5-minute deduplication interval" (AWS SQS Developer Guide) |
| Powertools for AWS Lambda idempotency utility | "By default, we expire idempotency records after an hour (3600 seconds)," configurable with expires_after_seconds (Powertools) |
AWS EC2 RunInstances (per the Builders' Library article) | "the lifetime of the resource, plus an interval" (Featonby) |
The spread, from five minutes to thirty days, is the reason the IETF draft asks servers to "publish" their expiration policy. It also creates a trap for long-running automations. A job that queues a request, crashes, and is restarted the next morning may retry with the right key and still create a duplicate, because the window has closed. Stripe's guidance for that case is explicit: "If the outcome is still unknown after that window, don't retry with either the old key or a new one. Retrieve the relevant object, inspect the request in the Dashboard, and use webhook events to reconcile the outcome" (Stripe, Advanced error handling).
Why not keep keys forever? AWS gives two reasons: "it's impractical to retain that knowledge indefinitely," and "indefinite retention could also have an undesirable impact on the customer experience if some future request identifier collides with one used much earlier" (Featonby, AWS Builders' Library).
9. Same key, different payload
Suppose a client sends POST /payments with key K and an amount of 10.00, times out, and then a bug or a user edit causes the retry to send key K with 12.00. What should happen?
The documented answer is consistent across sources: refuse. The IETF draft proposes a 422 (§2.7). Stripe "errors if they're not the same" (Stripe API reference) and its error list includes the case where "you used an idempotency key for something unexpected, like replaying a request but passing different parameters" (Stripe, Error handling). AWS explains the reasoning: "We find that it is safest to assume that the customer intended a different outcome, and that this might not be the same request. In response to this situation, we return a validation error indicating a parameter mismatch between idempotent requests" (Featonby, AWS Builders' Library).
Two caveats from the IETF draft are worth knowing. A server that does not fingerprint "cannot detect a key reused with a different payload, and handles such a request as a duplicate" — it would silently return the 10.00 result for a 12.00 request. And "if the fingerprint covers only part of the payload, requests that differ only outside that part are treated as the same request" (IETF draft-09 §2.4).
For clients, this has a concrete consequence. If you genuinely need to change the request, do not reuse the key. Stripe's sequence is: "first establish that the original operation didn't succeed and isn't still executing. Use a new key for the corrected operation. If the original outcome remains unknown, reconcile it before starting another operation" (Stripe, Advanced error handling).
10. Retrying while the first attempt is still running
A timeout does not stop the server. If your client gives up after 10 seconds and the operation takes 15, your retry may arrive while the first attempt is mid-flight. Without protection, both could run to completion.
The IETF draft's answer is a 409 Conflict: "If the request is retried, while the original request is still being processed, the resource SHOULD reply with an HTTP 409 status code," and unlike the 400 and 422 cases, the client needs no correction before trying again (§2.7). Stripe's guidance matches: "If a 409 indicates that another request with the same key is still executing, wait and retry with that key and the same parameters. A new key can start a second operation" (Stripe, Advanced error handling). Powertools for AWS Lambda implements the same idea with an INPROGRESS record that "prevents concurrent invocations with the same payload" and raises IdempotencyAlreadyInProgressError (Powertools).
An in-progress marker introduces its own failure mode: what if the worker holding it dies? Powertools handles this by recording "when record expires while in progress (in case of the invocation times out)"; "if a second invocation happens after this timestamp, and the record is marked as INPROGRESS, we will run the invocation again as if it was in the EXPIRED state" (Powertools). That is a reasonable design, but it means the in-progress timeout must be longer than the longest legitimate run, or a slow first attempt and a retry can both complete.
11. Duplicate detection without a key, and why AWS prefers explicit keys
An alternative some teams try is to treat any two identical requests as duplicates, using a hash of the parameters. AWS describes this and explains why it does not adopt it as the general approach: identical requests to create a DynamoDB table "received very close together in time" are probably duplicates, but "if those requests were for launching an Amazon EC2 instance, then our assumption might not hold. It's possible that the caller actually wants two identical EC2 instances" (Featonby, AWS Builders' Library). AWS's stated preference is "a unique caller-provided client request identifier," which also makes intent "readily auditable because the unique identifier is present in logs like AWS CloudTrail" (same source).
Content-based deduplication does have legitimate uses where the window is short and duplicates are never wanted. Amazon SQS FIFO queues offer it as an option: "Enable content-based deduplication. This instructs Amazon SQS to use a SHA-256 hash to generate the message deduplication ID using the body of the message—but not the attributes of the message" (AWS SQS Developer Guide). Note the detail that attributes are excluded: two messages with the same body and different attributes count as duplicates.
A third approach avoids keys by making the operation naturally idempotent. Stripe's blog gives a hypothetical DNS API where the client sends a PUT to the full record path; if "the domain already exists, it simply ignores the request and responds with a successful status code" (Leach, Stripe blog, 2017). HTTP also offers a conditional form: RFC 9110 says If-None-Match: * "can also be used ... to prevent an unsafe request method (e.g., PUT) from inadvertently modifying an existing representation of the target resource when the client believes that the resource does not have a current representation" (RFC 9110 §13.1.2). When the client can choose the resource's identifier, "create at this exact address, only if nothing is there" is often simpler than an idempotency key.
12. When the server's answer is "already exists"
There is a quieter design question: what should a retry return? AWS considers a CreateResource call with request ID 123 whose response was lost. One possible reply to the retry is ResourceAlreadyExists. That "meets the basic tenets for idempotency because there is no side effect for retrying the call," but "it's not clear whether the resource was created as a result of this request or the resource was created as the result of an earlier request" (Featonby, AWS Builders' Library).
AWS's preferred alternative is "to deliver a semantically equivalent response in every case for the same unique request identifier for some interval," so the retry looks like the original success (same source). The article's EC2 example shows the AWS CLI generating a ClientToken automatically, and notes that a later retry with the same token gets a response that is "very similar but not identical to the first response" (same source).
AWS also describes a "late arriving" edge case. A retry is delayed; meanwhile someone else deletes the resource; then the retry lands. For EC2 RunInstances, AWS chose "to honor the initial idempotent contract even in the scenario we just described," returning a semantically equivalent response that shows the instance as terminated, rather than launching a new one, following "the principle of least astonishment" (same source). A naive "check, then create" approach would launch a fresh instance here.
13. Generating and keeping keys on the client
Most client bugs with idempotency keys are not in the server; they are in where the key is created. Stripe's SDKs can generate keys for you, but the documentation warns: "If your application retries across separate SDK calls or process restarts, generate and persist a key for the operation and supply it to every attempt" (Stripe, Advanced error handling). A key generated inside the function that makes the HTTP call is regenerated every time the function runs, which is exactly when you need it to stay the same.
Rules that follow from the documented behavior (editorial suggestion):
- Create the key when the operation is decided, not when it is sent. Store it in the same record as the job ("publish article 42," key K) before the first attempt.
- Reuse it for every attempt of that operation, including after a crash and restart.
- Never reuse it for a different operation, even one with the same content. Two genuinely separate payments of 10.00 need two keys.
- Prefer random keys (UUID v4) unless you have a business object whose ID naturally identifies "this one action," such as a cart ID.
- Keep personal data out of keys, as Stripe advises (Stripe API reference); keys end up in logs.
- Respect length limits (Stripe: 255 characters).
- Keep the payload byte-for-byte stable. Serialize the request once, store it, and resend the stored version. Re-serializing can reorder fields or change timestamps that the server fingerprints.
- Know the window. Record when the first attempt was made, and stop retrying with the key before the server's documented expiry.
14. Security considerations
Keys are lookup values into a server's cache of past responses, which makes them an attack surface. The IETF draft lists two risks for servers that "do not implement strong idempotency keys, such as UUIDs, or have appropriate controls to validate the idempotency keys": injection attacks, when "the resource does not validate the idempotency key in the client request and performs an idempotent cache lookup," and data leaks, because "when an idempotency implementation allows low entropy keys, attackers MAY determine other keys and use them to fetch existing idempotent cache entries, belonging to other clients" (IETF draft-09 §5).
The draft's recommended practices are to "establish a fixed format for the idempotency key and publish the key's specification," to "always validate the key as per its published specification before processing any request," and to "implement a unique composite key as the idempotent cache lookup key," for example "combining the idempotency key sent by the client with other client specific attributes known only to the resource" (same source). Scoping by authenticated caller means a guessed key from another account simply misses. The draft's own example of a structured, predictable key, "tenant-4821:1007", comes with a pointer to that section for exactly this reason (§2.2).
15. Worked example: a publishing script (hypothetical)
This example is hypothetical and simplified. The API, names and timings are invented.
A small newsroom tool publishes approved articles to a CMS through POST /articles. The CMS documentation says it accepts an Idempotency-Key header, stores results for 24 hours, returns 409 while a request with the same key is running, and 422 if a key is reused with a different body.
The naive version. The script builds the request, sends it with a fresh UUID, and on any error waits two seconds and calls the same function again, which builds a new UUID. One evening the CMS is slow. The first attempt times out at 30 seconds on the client, but the CMS finishes at 34 seconds and creates article 9001. The retry, with a new key, creates article 9002. Readers see the same story twice.
The fixed version.
- When an editor approves the article, the tool writes a job row: article draft ID, the serialized request body, a new UUID key, and
first_attempt_at. - The sender reads the job row and sends the stored body with the stored key.
- On a timeout, it retries with the same key and body after a backoff delay.
- If it gets 409, it waits and tries again with the same key.
- If it gets 201 or a replayed 201, it records the returned article ID and marks the job done.
- If it gets 422, it stops and flags the job: something changed the body, which is a bug.
- If 24 hours pass without a definite answer, it stops retrying and asks a person to check whether the article exists, rather than reusing a key the CMS may have pruned.
On the slow evening, the retry arrives at 32 seconds, while the first attempt is still running, and gets 409. The next retry, after the first attempt finishes, gets the stored 201 with article ID 9001. One article, and a job record that says exactly what happened.
16. Idempotency keys in AI agents and automations
Language-model agents add a twist: the component deciding to retry may be the model itself. If an agent calls a "send invoice" tool, sees a timeout in the tool result, and decides "the request failed, I'll try again," it may issue a new tool call that your code treats as a new operation with a new key.
An editorial suggestion follows from the sections above: put key generation and retry logic in ordinary code underneath the tool, not in the model's hands. The tool wrapper creates the key when the model first proposes the action, stores it with the proposal, and reuses it for retries the wrapper itself performs. If the model calls the tool again with the same arguments, the wrapper can recognize the pending operation and return its status instead of starting another. This mirrors the AWS SDK behavior the Builders' Library describes, where the SDK "will generate a unique client request identifier and add it to the request if one is not provided by the caller," and "this generated identifier is then reused in the event of a retry, thus ensuring we meet the 'at most once' commitment" (Featonby, AWS Builders' Library).
17. What idempotency keys do not do
- They do not tell you whether the original succeeded unless the server replays the original result. A key protects against duplicates; it is not a status query.
- They do nothing if the server ignores them. The IETF draft is explicit that a general client "cannot assume the server will respect this request" (IETF draft-09 §2.5.1). Sending a header to an API that never documented it gives no protection.
- They do not cover downstream effects outside the server's transaction. If an endpoint charges a card and also triggers an email through a separate system, the replay protects the charge only to the extent the server's implementation covers the email too.
- They expire. Past the window, a "retry" is a new request.
- They are not a substitute for backoff. Retrying a key-protected request in a tight loop is still a load problem; see the companion articles on retry strategies and uncontrolled retries.
18. Checklist
For clients calling an API:
- Confirm in the docs that the endpoint supports idempotency keys, and note the header or field name.
- Note the retention window and the documented behavior for saved errors.
- Generate one key per intended operation, persist it with the job, and reuse it on every attempt.
- Store and resend the exact request body.
- Treat 409 as "still running": wait, same key.
- Treat a payload-mismatch error as a bug, not a retry signal.
- If the outcome is still unknown when the window closes, stop and reconcile.
- Log the key, every attempt, and the final result.
For teams building an API: scope keys to the caller, validate them before lookup, store the fields in the table in section 6, write the key and the business change in one transaction, and publish both the expiry window and whether a retry replays a saved error.
Related reading on Apiary
- biggie-idempotency
- biggie-idempotency-api
- biggie-idempotent-operations
- request-failure-vs-unknown-execution-outcome
- biggie-retry-strategies
- guide-make-a-small-automation-retry-without-duplicating-the-work
Sources
Last checked: 2026-11-26.
- Fielding, R., Nottingham, M., Reschke, J. (eds.). "RFC 9110: HTTP Semantics." IETF, June 2022. https://www.rfc-editor.org/rfc/rfc9110 - definitions of safe and idempotent methods (§9.2.1, §9.2.2), automatic-retry rules, If-None-Match (§13.1.2).
- Fielding, R., Nottingham, M., Reschke, J. (eds.). "RFC 9112: HTTP/1.1." IETF, June 2022. https://www.rfc-editor.org/rfc/rfc9112 - §9.3.1 retrying requests after a connection closes.
- Jena, J., Dalal, S., Tishkin, D. "The Idempotency-Key HTTP Header Field." IETF Internet-Draft draft-ietf-httpapi-idempotency-key-header-09, 21 November 2026 (work in progress). https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-idempotency-key-header - header syntax, uniqueness, expiry, fingerprints, 400/409/422 errors, implementations, security considerations.
- Stripe. "Idempotent requests," API reference. https://docs.stripe.com/api/idempotent_requests - v1 saved responses including 500s, v2 behavior, key format and length, 24-hour pruning, parameter comparison.
- Stripe. "Advanced error handling." https://docs.stripe.com/error-low-level - 409 handling, 500 as indeterminate, v2 30-day window, Idempotent-Replayed and Stripe-Should-Retry headers, persisting keys across restarts.
- Stripe. "Error handling." https://docs.stripe.com/error-handling - decision table, retry within 24 hours, idempotency error type.
- Leach, B. "Designing robust and predictable APIs with idempotency." Stripe blog, 22 February 2017. https://stripe.com/blog/idempotency - three failure cases, server behavior per case.
- Featonby, M. "Making retries safe with idempotent APIs." Amazon Builders' Library. https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/ - ClientToken, ACID requirement, semantically equivalent responses, late-arriving requests, parameter mismatch, retention.
- Amazon Web Services. "Exactly-once processing in Amazon SQS." SQS Developer Guide. https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues-exactly-once-processing.html - 5-minute deduplication interval, content-based deduplication.
- Powertools for AWS Lambda (Python). "Idempotency." https://docs.powertools.aws.dev/lambda/python/latest/utilities/idempotency/ - INPROGRESS records, 3600-second default expiry, record deletion on unhandled exceptions.
- PostgreSQL Global Development Group. "INSERT," PostgreSQL 19 documentation. https://www.postgresql.org/docs/current/sql-insert.html - ON CONFLICT DO NOTHING / DO UPDATE atomicity, DO SELECT.