Idempotency: The Contract
The What a payment is part established that your client and Stripe can permanently disagree about whether a request executed. This part is the external contract that lets you resolve that disagreement without guessing — what the key is, what it promises, and where it doesn't apply. The Idempotency: the machinery part is the internal machinery that makes the contract true; don't expect implementation detail here.
The Key Itself
| Header | Idempotency-Key |
|---|---|
| Max length | 255 characters |
| Recommended | V4 UUID, or any string with equivalent entropy |
| Retention | At least 24 hours, then eligible for pruning |
Stripe's own wording is precise and worth quoting exactly, because the difference between "24 hours" and "at least 24 hours" matters: "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." That's a floor, not a fixed TTL — Stripe doesn't promise the key disappears at exactly the 24-hour mark, only that it won't disappear before then. Either way, the trap is the same: a retry queue that sits on a failed request for more than a day and then replays it with the "same" key isn't safe by default — once the key is pruned, the retry is indistinguishable from a brand-new request, and you get a second resource, not the cached first one. If your retry/backoff schedule can plausibly exceed 24 hours (a dead-letter queue reprocessed the next morning, a human re-running a failed batch job), that's exactly the case idempotency keys stop protecting you and you need your own de-duplication (the Idempotency: the machinery part's closing table names the alternatives).
Which Methods It Applies To
Idempotency keys are meaningful only on POST — that's the only HTTP method Stripe's API uses for a non-idempotent-by-construction mutation (creating a new object, or executing a state transition like a capture or a refund). GET and DELETE are excluded, and Stripe is explicit about why: "Don't send idempotency keys in GET and DELETE requests because it has no effect. These requests are idempotent by definition." Sending a key on a GET isn't harmful, it's simply inert — nothing is stored or checked against it.
The Scoping Rule — Question #1
Idempotency keys are scoped per API key — that is, per Stripe account/user — not globally across Stripe. The identical key string order-42 sent by two different accounts creates two completely independent resources; Stripe never checks one account's keys against another's.
This is the only sane design, for two reasons. First, a global keyspace makes every integration's key-generation scheme a potential collision source with every other Stripe user's scheme on the planet — two unrelated merchants both deriving keys from "order-" + order_id would silently collide the moment their order IDs matched, which is not a hypothetical with small sequential integer IDs. Second, a global keyspace leaks information across account boundaries: if a lookup by key could return "conflict" for another account's in-flight request, you'd have a timing side-channel for enumerating another business's key usage. Per-account scoping makes both problems disappear structurally, at the cost of nothing you'd actually want — you were never going to want your idempotency keys to interact with a different Stripe account's requests.
The consequence that actually bites: on a Connect platform, "per API key" means per connected account, not per platform. If you make requests on behalf of connected accounts using Stripe-Account headers (or the equivalent), a key is scoped to that specific connected account's request context — reusing a key string across two different connected accounts is exactly the two-account diagram above, not a collision. And in a multi-tenant system that derives keys from something like an order ID, you must fold the tenant/account identity into the key yourself if there's any chance the same order-ID scheme is reused per-tenant against the same underlying Stripe account (e.g., a platform generating keys as str(order_id) across tenants that each start their own order numbering at 1) — Stripe's per-account scoping doesn't protect you from your own multi-tenant collisions inside a single account.
curl https://api.stripe.com/v1/charges \
-u sk_live_PLATFORM_KEY: \
-H "Stripe-Account: acct_CONNECTED_ACCOUNT_ID" \
-H "Idempotency-Key: payout-batch-2026-09-14-row-88" \
-d amount=500 -d currency=usd -d source=tok_visa
(the key "payout-batch-2026-09-14-row-88" is scoped to)
(acct_CONNECTED_ACCOUNT_ID specifically — the same string)
(sent with a different Stripe-Account header is unrelated)The Request-Fingerprint Rule
Reusing a key with a request body that doesn't match the original is not silently accepted and not silently ignored — it's rejected. Stripe's docs: "The idempotency layer compares incoming parameters to those of the original request and errors if they're not the same to prevent accidental misuse." This is the sharpest correctness feature in the whole mechanism, not an annoyance to work around: it's the thing that catches a retry loop that mutates the payload between attempts — the textbook case being a retry that recomputes amount against a fresher FX rate, or re-reads a cart total that changed between the first attempt and the retry. Without the fingerprint check, that bug would silently succeed on retry with a different amount than the one the customer actually agreed to, and you'd have no signal at all. With it, the retry fails loudly, in your own request path, before any money moves — which is a far cheaper place to catch "my retry logic recomputes state it shouldn't" than a reconciliation report three days later (see Money invariants).
What Is Replayed — and What Isn't
Stripe caches the full result of the first execution under the key, success or failure: "Stripe's idempotency works by saving the resulting status code and body of the first request made for any given idempotency key, regardless of whether it succeeds or fails." A retry of a card decline replays the same decline — it does not attempt the charge again. This is why "retry on idempotency key" is not the same tool as "retry the operation": if the underlying failure was a real decline, replaying the key gets you the decline again, forever, until you change something and get a new key.
There's a specific, important carve-out for which errors get cached at all, because it determines whether a retry can ever succeed:
| What happened | Cached under the key? | What a retry with the same key does |
|---|---|---|
Request executed — success, decline, or a 500 | Yes | Replays the exact cached status + body. A cached decline stays a decline. |
429 rate limited | No — the rate limiter runs before the idempotency layer | Can produce a genuinely new attempt and a different result |
401 missing/invalid API key, most parameter-validation 400s | No — execution never began | Can produce a genuinely new attempt once the request is fixed |
| Conflicts with a request executing concurrently under the same key | No | 409 Conflict — safe and expected to retry (see Idempotency: the machinery) |
Stripe states the underlying rule directly: "We save results only after the execution of an endpoint begins. 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." That's the exact distinction that determines whether "just retry with the same key" can ever get you a different, successful outcome — it can, but only for the class of errors that never reached execution in the first place.
Knowing You Got a Replay
A replayed response carries Idempotent-Replayed: true. Log it on every payment-path response. It's the cheapest signal you have for "this attempt didn't actually do anything new" — invaluable when debugging a support ticket that says "I was charged twice" and you need to know, from your own logs, whether your second request even reached Stripe's execution path or was served entirely from the idempotency cache.
Request and replayed response, annotated
curl https://api.stripe.com/v1/payment_intents \
-u sk_live_...: \
-H "Idempotency-Key: charge-order-42-v1" \
-d amount=2000 -d currency=usd -d payment_method=pm_card_visa \
-d confirm=true
(first attempt) 200 OK
(no Idempotent-Replayed header — this execution really happened)
(retry, connection had dropped, same key + same body) 200 OK
Idempotent-Replayed: true
(identical body to the first response — nothing re-executed)Stripe also exposes a Stripe-Should-Retry response header on some failures, precisely so a client doesn't have to reverse-engineer retry-safety from the status code alone: true means retry (after backoff), false means retrying has no further effect, and an absent header means fall back to status-code-based judgment. The built-in SDK retry logic already honors it; if you're retrying by hand, check it before you retry.
Key Design — Derive It, Don't Roll It
A key regenerated on every retry attempt is equivalent to having no idempotency key at all — each "retry" looks like a first-ever request. The key has to be stable across every attempt at the same logical operation, which means it has to come from something that already uniquely identifies that operation in your own system, generated once, before the first attempt, and reused verbatim on every subsequent retry of that same operation.
✗ Bad — regenerated per attempt
def charge_order(order):
key = uuid4() # NEW every call
stripe.PaymentIntent.create(
amount=order.total_cents,
currency="usd",
idempotency_key=key,
)
# A retry after a timeout calls
# charge_order() again -> new key
# -> Stripe sees a first-ever
# request -> second charge.✓ Good — derived from business identity
def charge_order(order):
key = f"charge-order-{order.id}-v{order.pricing_version}"
stripe.PaymentIntent.create(
amount=order.total_cents,
currency="usd",
idempotency_key=key,
)
# Every retry of THIS order's THIS
# charge attempt reuses the same
# key -> safe to retry indefinitely
# within the retention window.Note the pricing_version suffix: it's there on purpose. If the order's price can legitimately change (coupon reapplied, tax recalculated) between the moment you first tried and a deliberate second attempt, you want a new key — the request-fingerprint rule above would otherwise reject the retry as a mismatch, correctly, because it genuinely is a different request.
What Stripe's SDKs Already Do For You
Official client libraries can generate idempotency keys and retry certain requests automatically — but this is opt-in configuration, not default behavior. Stripe's own phrasing: "Most client libraries can generate idempotency keys and retry requests automatically, but need to be configured to do so." Concretely, that means setting something like Stripe.max_network_retries = 2 in the Ruby library; only network-class errors (timeouts, connection resets) get this automatic treatment, on a first-fast-retry-then-exponential-backoff schedule, because "a single failure is often a random occurrence, but a pattern of repeated failures likely represents a chronic problem." The SDK also respects a Stripe-Should-Retry response header when present, so it doesn't have to guess retry-safety purely from the status code. None of this fires for content errors (4xx other than the network/conflict classes above) — those are, by design, yours to fix and resend with a fresh key. If you're calling the API directly (no SDK, or an SDK with retries left off), all of the behavior in this part is something you must implement — Stripe does not silently retry on your behalf by default.
What the Key Doesn't Cover
An idempotency key deduplicates one call to Stripe's API. It says nothing about any other side effect your own code fires as part of handling that request — send a receipt email, decrement inventory, notify a fulfillment queue — unless you gate those effects on the same durable, replay-safe record. A request that's perfectly idempotent from Stripe's point of view can still email a customer twice if the email send isn't conditioned on the same commit as the charge. That's not a gap in Stripe's contract; it's the boundary of it — and it's exactly the problem the Idempotency: the machinery part solves for your own side effects with the same recovery-point machinery Stripe uses internally.
The Invariants
- Guarantees: Within the retention window, retrying the same
POSTwith the same key and the same body returns the exact original outcome — success, decline, or500— without a second execution; a key reused with a mismatched body is rejected rather than silently executed against the new parameters or the old ones. - Does not guarantee: Protection once the key is pruned (a "floor" of at least 24 hours, not a fixed TTL); a fresh, correct answer to a request that never began execution (rate-limited, unauthenticated, malformed); or safety across two different Stripe accounts, or two different connected accounts on a Connect platform, that happen to generate the same key string.