Payments and finance

Stripe API keys: find, store, rotate, and use them safely with AI agents

Stripe API keys are created and managed on the Dashboard API keys page. Stripe recommends restricted keys (rk_) over unrestricted secret keys (sk_) for server code, and each mode (sandbox or live) has its own set of keys.

Stripe key types

TypePrefixSecret?ScopeExpiry
Publishable keypk_live_ / pk_test_NoClient-side use with Stripe.js, Elements and mobile SDKs; cannot perform sensitive operationsCannot be expired
Restricted key (RAK)
Can be tagged as an agent key, which subjects it to Stripe approval rules for sensitive actions.
rk_live_ / rk_test_YesOnly the permissions you grant when creating itDoes not expire unless you expire or rotate it, or schedule a rotation
Secret key
Stripe does not recommend secret keys for new use cases.
sk_live_ / sk_test_YesUnrestricted access to all Stripe APIsDoes not expire unless you expire or rotate it, or schedule a rotation
Organization keysk_org_YesOrganization-level access across multiple Stripe accounts—

How to create a Stripe key

  1. Sign in to the Stripe Dashboard and switch to the sandbox or live mode you need.
  2. Open the API keys page.
  3. Click Create secret key (or create a restricted key from the Restricted keys list).
  4. Enter the verification code Stripe sends by email or text, name the key and click Create.
  5. Copy the key and store it in a secrets vault. In live mode you cannot reveal a key you created yourself again.

Open Stripe's key settings

Limiting what the key can do

Use restricted API keys (rk_) and grant only the resources the integration needs. You can also attach an access policy (IP address ranges, or ASN, country and threat-source rules) to a key under Manage access policy.

How to rotate a Stripe key

  1. On the API keys page, open the overflow menu (⋯) for the key.
  2. Select Rotate key and choose an Expiration for the old key (now, or a later time).
  3. Click Rotate API key, then copy and store the new key.
  4. Deploy the new key, check the old key's request logs, then let the old key expire.

When you rotate in the Dashboard, the old and new keys both work for up to 7 days. Choosing Now deletes the old key immediately.

How to revoke a Stripe key

  1. On the API keys page, open the overflow menu (⋯) for the key.
  2. Select Expire key and confirm. Code using that key stops working immediately.

If your Stripe key leaked

  1. Rotate the key from the API keys page and choose Now as the expiration so the exposed key stops working.
  2. Check the key's request logs (overflow menu, View request logs) for activity you do not recognise.
  3. Update your secrets vault and redeploy with the new key.
  4. Attach an access policy to the replacement key so requests from unknown sources are blocked.

Environment variables and CLI

Stripe CLI (stripe): Install with npm install -g @stripe/cli; run stripe agent setup to configure agent harnesses. See the CLI docs for login.

Things that catch people out

  • Webhook signing secrets are not API keys. Find them under each endpoint in the Dashboard Webhooks section.
  • In live mode a secret or restricted key you created yourself is shown once and cannot be revealed later.
  • From November 30, 2026, Stripe MCP stops accepting full-access secret keys and restricted keys without the Agent tag; use OAuth or an agent API key.
  • A key unused for payouts or transfers for over 180 days can have limited access until you click Restore access.

Recent incidents that put Stripe keys at risk

If you were affected by one of these, rotate your Stripe keys using the rotation steps above.

Using your Stripe key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Stripe key, these intents fit:

IntentWhat BotPassword does
run_withRuns a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
http_requestMakes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
rotatePartly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
store_secretSaves a value the agent already holds as a new vault item.

Stripe also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

Where do I find my Stripe API key?

In the Dashboard on the API keys page, with the sandbox or live mode toggled to the one you need.

What is the difference between sk_ and rk_ Stripe keys?

sk_ keys have unrestricted permissions on all Stripe APIs; rk_ restricted keys only have the permissions you choose. Stripe recommends restricted keys.

Can I view my Stripe live secret key again?

Only keys Stripe created for you can be revealed in live mode. If you created the key yourself and lost it, rotate or delete it and create another.

How do I rotate a Stripe API key without downtime?

Use Rotate key in the Dashboard and pick a later expiration; both keys work for up to 7 days.

Can an AI agent use my Stripe key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.

Stop pasting Stripe keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.