Rotate › Stripe

# How to rotate Stripe API keys safely

A leaked Stripe key is a direct line to your money, so rotation needs to be quick but can't break checkout. Stripe gives you up to 7 days of overlap; this is how to use it, and how to come out with narrower keys than you went in with.

Keysquid team · Updated November 28, 2026 · Checked against Stripe's docs on November 28, 2026

**Rather not keep track of this?** Keysquid reminds you on schedule, checks the key you paste and pushes it everywhere. We never see the value.

[Try it free for 7 days](https://keysquid.com/signup)

- **Key formats**: `sk_live_` secret, `rk_live_` restricted, `pk_live_` publishable (safe to expose); `_test_` in sandboxes. Organization keys: `sk_org_`.
- **Where**: Dashboard → [API keys](https://dashboard.stripe.com/apikeys): create, reveal, rotate and expire.
- **Overlap**: When you rotate in the Dashboard, the old and new keys both work for up to 7 days. Choosing “Now” deletes the old key at once.
- **Shown once**: A live key you create is displayed one time. Only keys Stripe generated for you can be revealed again.
- **Permissions**: Restricted keys get per-resource None, Read or Write. Stripe recommends them over secret keys for new work.
- **Usage limits**: Access policies limit a key to IP ranges, or by ASN, country and source (Tor, VPNs, proxies). They replaced IP restrictions.
- **Usage logs**: Each key's menu → View request logs opens its requests in Workbench.
- **Webhook secrets**: `whsec_` secrets are separate, per endpoint, and roll with their own up-to-7-day overlap.
- **Keysquid**: Assisted: you create the key in the Dashboard, Keysquid verifies and distributes it.

## First, which key are you rotating?

| Key | Can it move money? | What to do |
| --- | --- | --- |
| `sk_live_…` | Yes: unrestricted access to every API | Rotate, and replace it with restricted keys while you're at it |
| `rk_live_…` | Only what its permissions allow | Rotate; the replacement keeps the same name and permissions |
| `pk_live_…` | No; it only identifies your account and creates tokens | Nothing urgent: it's designed to be public |
| `whsec_…` | No, but it can forge webhook events to your server | Roll the endpoint's signing secret (below) |
| `sk_test_ / rk_test_` | No (sandbox) | Rotate if shared; no real-money risk |

## Rotate a Stripe key without downtime

1. **List every consumer.** Search for `STRIPE_SECRET_KEY` (and any restricted-key variable names) across your hosting platforms, CI, workers and serverless functions. Stripe’s request logs for the key show which servers call it.
2. **Rotate with an overlap.** On [API keys](https://dashboard.stripe.com/apikeys), open the key’s menu (⋯), choose *Rotate key*, and pick an *Expiration* for the old key: long enough to deploy everywhere, up to 7 days. Copy the new value and note where you stored it.
3. **Roll out gradually.** Deploy the new key to a small slice first and watch for errors, as Stripe suggests, then everywhere. A restricted key that lacks a permission fails loudly with a permission error, so you find gaps on the first request, not weeks later.
4. **Watch the old key’s request logs** (⋯ → View request logs). Stripe’s advice is to expire it only once its request volume has been at zero for a few hours or days.
5. **Expire the old key** (⋯ → Expire key) if you don’t want to wait for the scheduled expiry. Any code still using it gets an authentication error.

**Need more than 7 days?** Create a new key manually instead of rotating, migrate to it at your own pace, then expire the old one. That’s Stripe’s own recommendation for long migrations.

## Come out with a restricted key

Stripe now recommends restricted keys for most uses and migrating existing secret-key usage to them. A rotation is the cheapest moment to do it: you are already touching every consumer. Give each service its own restricted key with only the resources it uses, so a leak from your email worker can’t issue refunds. Two related features are worth turning on at the same time:

- **Access policies** on every live key, so requests from anywhere but your servers are blocked and you are notified.
- **Agent-tagged restricted keys** for AI agents: Stripe applies approval rules to sensitive actions such as payouts and refunds.

## Roll webhook signing secrets too

Webhook signing secrets aren’t API keys and don’t change when you rotate one. Roll them separately: in Workbench’s [Webhooks](https://dashboard.stripe.com/webhooks) tab, open each endpoint, choose *Roll secret* from the menu, and delay the old secret’s expiry by up to 7 days. While both are active, Stripe signs every event once per secret, so code that accepts any valid `v1` signature keeps working while you deploy the new secret.

```bash
# After deploying the new whsec_ value, send a test event and check it verifies:
stripe trigger payment_intent.succeeded
```

## How Keysquid handles Stripe keys

Assisted Stripe doesn't offer an API that Keysquid can use to create keys, so rotation is assisted: Keysquid reminds you on schedule, you create the key, and Keysquid does the rest. Stripe only lets you create restricted keys in the Dashboard. Paste a new key and Keysquid distributes it everywhere.

**Setup, as the app shows it:**

1. When reminded, create a restricted key in Stripe → Developers → API keys and paste it.
2. Use Stripe's “expire old key” option with a short delay so the previous key dies on its own.

- **Writes to:** Secret or restricted key (default variable STRIPE_SECRET_KEY), in every platform and secret store you map it to.
- **Interval:** from every 1 week to every 4 weeks, subject to your plan’s minimum.
- **Restricted permissions, IP allowlist and expiry (set in Stripe):** Use a restricted key with only the permissions your app needs, add an IP allowlist, and set the old key to expire when you roll it. Stripe only offers these in the Dashboard.

When you paste the new key, Keysquid verifies it against Stripe, writes it everywhere it is mapped, and redeploys where a platform needs it. If any write fails, the previous values are restored. Retiring the previous key stays a step in Stripe's dashboard. The value is encrypted to the agent you run, so Keysquid’s servers never see it.

Keysquid checks a pasted key by reading your account balance (`GET /v1/balance`), so give a restricted key at least *Balance: Read* or the check will fail. Use Stripe’s own expiry option on the old key when you create the new one: Keysquid can’t expire Stripe keys for you.

## If a Stripe key leaked

- **Rotate with expiration “Now”.** A live secret key can create charges, refunds and payouts. Downtime is the lesser risk.
- **Review request logs** for the old key in Workbench, and recent payouts, refunds and changes to payout destinations.
- **Read Stripe’s guide** to [protecting against compromised API keys](https://support.stripe.com/questions/protecting-against-compromised-api-keys).

## Frequently asked questions

### How long does the old Stripe key keep working after I rotate it?

As long as the expiration you choose when rotating, up to 7 days. If you choose Now, the old key is deleted immediately and anything still using it fails.

### Does rotating a restricted key keep its permissions?

Yes. Rotating revokes the key and generates a replacement that keeps the restricted key's name; you don't have to set its permissions again.

### Do I need to rotate my publishable key?

Usually not. Publishable keys (pk_live_) are designed to be exposed in browser and mobile code and can't perform sensitive operations. Rotate secret and restricted keys instead.

### Does rotating an API key change my webhook signing secret?

No. Webhook signing secrets (whsec_) belong to each webhook endpoint and are rolled separately, with their own option to keep the old secret valid for up to 7 days.

### Can Stripe keys be rotated automatically?

Stripe can schedule a key to rotate itself, but someone still has to deliver the new value to every service. Keysquid handles that part: you create the key in the Dashboard and Keysquid verifies it and writes it everywhere it's used.

Rotate keys without ever handing them over

Keysquid rotates and revokes API keys on a schedule and encrypts every value to an agent you run, so we never see a readable key. Flat pricing from $9.99 a month, unlimited team members, 7-day free trial.

[Start 7-day free trial](https://keysquid.com/signup)

[Security model](https://keysquid.com/security)[Docs](https://keysquid.com/docs)

## Related

- [Rotate AWS IAM access keys](https://keysquid.com/rotate/aws-iam)
- [OpenAI API key formats and revoking](https://keysquid.com/rotate/openai)
- [Rotation support for every provider](https://keysquid.com/rotate)
- [Leaked an API key? The first 10 minutes](https://keysquid.com/blog/leaked-api-key-first-10-minutes)
- [Anthropic key rotation](https://keysquid.com/rotate/anthropic)
- [Cloudflare key rotation](https://keysquid.com/rotate/cloudflare)

## Sources

1. [Stripe docs: API keys (rotate, expire, access policies)](https://docs.stripe.com/keys)
2. [Stripe docs: restricted API keys](https://docs.stripe.com/keys/restricted-api-keys)
3. [Stripe docs: best practices for managing secret API keys](https://docs.stripe.com/keys-best-practices)
4. [Stripe docs: webhooks (roll endpoint signing secrets)](https://docs.stripe.com/webhooks)
5. [Stripe support: protecting against compromised API keys](https://support.stripe.com/questions/protecting-against-compromised-api-keys)
