# How do retries avoid charging a card twice?

> A retry avoids a second charge when the server can tell it is the same request as the first. Stripe does this with idempotency keys: the client sends a unique key with each request, and Stripe replays the saved result to any retry that carries it. Stripe may prune a key once it is at least 24 hours old, so a billing system also records each charge before money moves.

Author: Nadav Hollander (https://www.linkedin.com/in/nadav-hollander-8268585a/)
Published: 2026-11-05T21:10:00.000Z
Reading time: 5 min
Canonical: https://auto.sh/blog/how-retries-avoid-double-charges
Publisher: Auto (https://auto.sh)

## Key facts

- With Stripe's API v1, a retry that reuses an idempotency key gets the first request's saved status code and body back, `500` errors included ([Stripe](https://docs.stripe.com/idempotency), read November 4, 2026).
- Stripe may prune an idempotency key once it is at least 24 hours old, and reusing a pruned key creates a new request ([Stripe](https://docs.stripe.com/idempotency), read November 4, 2026).
- Auto records each prepaid seat charge before any money moves, so a retried seat change reuses the charge it already made.

A retry avoids a second charge only when the server can recognize it as the first request again. Stripe's [idempotency keys](https://docs.stripe.com/idempotency) do that inside Stripe, and a billing system's own record of each charge does it everywhere else. Auto, the [Mac app for all your coding agents](https://autorouter.com/), builds its billing on that pattern: a retried seat change reuses the charge it already made, and an account holds one Pro subscription even when two checkouts start at once. Auto wrote this post, and Stripe's behavior in it comes from Stripe's docs as read on November 4, 2026.

## Why can a retry charge a card twice?

A retry can charge twice because a request can fail after the server has already done the work. When a connection drops mid-request, the client can't tell whether the charge went through, and a blind retry repeats it. Stripe's engineering blog describes these ambiguous failures and pairs idempotency keys with exponential backoff and jitter, so retries from many clients don't arrive at a struggling server all at once ([Stripe, February 22, 2017](https://stripe.com/blog/idempotency)).

![A retry charges once only when Stripe can match it to the first request. Retry without a key: Your server to Stripe: Charge the card; Stripe charges the card; Stripe to Your server: Success (never arrives); Your server to Stripe: Retry: charge the card; Stripe charges it again. Result: Charged twice. Retry with the same key: Your server to Stripe: Charge the card, key A; Stripe charges it, saves the response; Stripe to Your server: Success (never arrives); Your server to Stripe: Retry with key A; Stripe to Your server: The saved success. Result: Charged once. Source: Stripe docs on idempotent requests (API v1), read November 4, 2026.](https://auto.sh/blog/images/how-retries-avoid-double-charges/1-retry-sequence.png)

## What does Stripe save under an idempotency key?

For API v1, Stripe saves the status code and body of the first request made with a key once the endpoint starts running, and every retry with that key gets the saved response back, `500` errors included ([Stripe: Idempotent requests](https://docs.stripe.com/idempotency)). Stripe also compares each retry's parameters with the first request's and returns an error when they differ. A request that fails validation, or that collides with another request still running, isn't saved, so the client can retry it. With API v2, retries don't repeat work that succeeded, and Stripe tries to finish work that failed or partly failed.

| What happened to the first request (API v1)      | What a retry with the same key gets      |
| ------------------------------------------------ | ---------------------------------------- |
| It succeeded                                     | The saved success response               |
| It returned a `500`                              | The same saved `500`                     |
| The retry's parameters differ                    | An error                                 |
| It failed validation or hit a concurrent request | A fresh attempt, since nothing was saved |
| Its key was pruned after 24 hours or more        | A new request                            |

## How long does an idempotency key protect a retry?

At Stripe, an idempotency key protects retries for at least 24 hours: keys can be pruned once they are at least 24 hours old, and reusing a pruned key creates a new request ([Stripe](https://docs.stripe.com/idempotency)). Resend's email API works the same way, checking for an email sent with the same key in the last 24 hours ([Resend](https://resend.com/docs/dashboard/emails/idempotency-keys)). A job that keeps retrying for days outlives its key, so it needs its own record of what already happened.

![Auto retries an email only while Resend still holds its key. Stripe key: 0 to 24 hours, protects retries; 24 to 36 hours, can be pruned; Resend key: 0 to 24 hours, catches a repeat send; Auto email retry: 0 to 23 hours, retries with the same key. Marked: 24 hours. Source: Stripe and Resend docs on idempotency keys, read November 4, 2026.](https://auto.sh/blog/images/how-retries-avoid-double-charges/2-key-windows.png)

## What should a billing system record before it charges?

A billing system should record each charge before it calls the payment provider, so every retry finds the same charge and resumes it. Four steps cover it:

1. Save the charge, with its amount and account, before calling the provider and outside any database transaction that can roll back.
2. Derive one idempotency key for each step from that record's ID, so every retry can rebuild the same keys.
3. On every retry, resume the saved charge with the same keys.
4. Mark the charge done only after the provider's answer is saved.

![Record the charge before calling the provider, and every retry finds it. Save the charge (Amount and account, before any money moves), then Derive the keys (One per step, from the charge's ID), then Resume on retry (Same charge, same keys), then Mark it done (After the provider's answer is saved). A retry reuses the charge it already made. Source: How Auto records seat charges before calling Stripe.](https://auto.sh/blog/images/how-retries-avoid-double-charges/3-record-first.png)

Step 2 has one catch. Because Stripe replays a saved `500` to every retry with the same key, a step that failed with a server error needs a new key before it can succeed, and the system should first check what already went through so the new attempt doesn't repeat it.

## What does Auto do so you're charged once?

Auto's billing is built so each payment happens once and the credit you get matches what you paid:

- **One Pro subscription per account.** Two Pro checkouts started at once, in two tabs or on two devices, still end in one subscription.
- **Seat changes charge once.** Auto records each prepaid seat charge before any money moves, and a retried seat change resumes that charge with the same Stripe keys, so it reuses the charge it already made.
- **Credit matches payments.** Enterprise seat credit covers the period the paid invoice paid for, and a refund that arrives before its credit grant still takes that credit back.
- **Removed seats keep no credit.** Removing a seat takes back credit from a join that was still in progress, so a team doesn't pay for credit no seat stands behind.

The same rule covers email. A waitlist follow-up is claimed before it sends, and a send that may have gone out is retried with the same key only within 23 hours, inside Resend's 24-hour window, so each follow-up sends once. For the rest of a team rollout, from sign-in to budgets, see [How to roll out AI coding tools to an engineering team](/blog/ai-coding-tools-for-teams).

## Questions

### Does a retry with the same idempotency key ever charge twice?

Not while Stripe still holds the key, because a retry with that key gets the first request's saved result. Once a key is pruned, which Stripe may do after 24 hours, the same key starts a new request, and a retry with a different key is always a new request ([Stripe](https://docs.stripe.com/idempotency)).

### What makes a good idempotency key?

Stripe suggests V4 UUIDs or another random string with enough entropy to avoid collisions, up to 255 characters, and advises against sensitive data such as email addresses ([Stripe](https://docs.stripe.com/idempotency)). Deriving the key from your own charge record's ID lets every retry rebuild the same key.

### Why does a retried Stripe request return the same error?

With Stripe's API v1, the first response under a key is saved even when it is a `500`, so retries with that key get the same error back. Requests that failed validation or collided with a concurrent request weren't saved and can be retried as they are ([Stripe](https://docs.stripe.com/idempotency)).

### What does Auto bill for?

Auto Free is $0 a month and routes across the AI subscriptions you already pay for. [Pro](/pricing) includes usage each month, and paid models are billed at the provider's price plus 10%, from included usage first and then from credits you top up. Credits you buy never expire. [How to cut Claude Code and Codex costs](/blog/cut-claude-code-and-codex-costs) covers the other ways to spend less.

## Sources

- [Stripe: Idempotent requests](https://docs.stripe.com/idempotency), read November 4, 2026
- [Brandur Leach, Stripe: Designing robust and predictable APIs with idempotency](https://stripe.com/blog/idempotency), February 22, 2017
- [Resend: Idempotency keys](https://resend.com/docs/dashboard/emails/idempotency-keys), read November 4, 2026
- [Auto pricing](https://autorouter.com/individuals#plans)

## Read next

- [Grading coding agents: tests, rubrics or an LLM judge](https://auto.sh/blog/grading-coding-agents.md): Grade a coding agent with tests whenever the task has them, with a rubric written in advance when a reviewer has to judge the result, and with an LLM judge only when there are too many results to review, given that rubric and checked against people. Auto, the Mac app for all your coding agents, grades its free company benchmark against a team's own tests or a rubric written with the team.
- [How to test an AGENTS.md change before it reaches your team](https://auto.sh/blog/test-agents-md-changes.md): Test an AGENTS.md change the way you test code: run the same held-out tasks with the old file and the new one, several times each, and compare pass rate, tokens and cost, task by task. Auto, the Mac app for all your coding agents, builds a free company benchmark from your merged work that you can rerun whenever your AI setup changes.
- [Is Claude Code free? What it costs, and the cheapest way in](https://auto.sh/blog/is-claude-code-free.md): Use Auto, the Mac app for all your coding agents: its Free plan costs $0 a month and runs Claude Code on the AI subscriptions you already pay for, so a ChatGPT plan you already have works inside Claude Code. Claude Code itself installs at no cost, but something has to pay for the model: as of November 17, 2026, Claude's Free plan doesn't include Claude Code, so you need Claude Pro ($20 a month), Max ($100), Ultra ($200), API credits billed per token, or Auto Pro, which includes usage each month.

Tags: [Costs](https://auto.sh/blog/tags/costs.md), [Teams](https://auto.sh/blog/tags/teams.md), [Auto](https://auto.sh/blog/tags/autorouter.md)

Drafted with AI from the sources linked above, then checked and edited by the Auto team.

Auto is a Mac app for AI model routing in Codex, Claude Code, Cursor and other supported coding agents. It uses eligible connected subscriptions first. See [setup](https://auto.sh/setup.md) and [pricing](https://auto.sh/pricing).
