# What does Stripe 'Invalid API Key provided' mean?

**Short answer:** The request sent a key Stripe doesn't recognize for that account or mode, often test vs live mixed up, a typo, or an empty env var. An expired key that was rolled or expired in the Dashboard returns `api_key_expired`. Copy the current key from the Dashboard's API keys page into a server-side env var. Only `pk_` keys belong in the browser.

*Last updated 2026-11-25 · Reviewed by ProofForge*

## The exact error

```text
{"error":{"message":"Invalid API Key provided: sk_live_****abcd","type":"invalid_request_error"}}
error code: api_key_expired  ("The API key provided has expired.")
```

## Why it happens

- Using an `sk_test_` key against live objects (or the reverse).
- The key was rolled and the old one has expired.
- Production env var not set, so the SDK gets `undefined`.
- A publishable `pk_` key used where a secret key is required.

## How to fix it

1. Get the key for the right mode from the Dashboard's API keys page.
2. Set `STRIPE_SECRET_KEY` on the server only and restart or redeploy.
3. Prefer restricted keys (`rk_`) with only the permissions your integration needs.

```ts
// server
import Stripe from 'stripe'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
// browser: only pk_live_ / pk_test_
```

## Check it's fixed

Make one test API call from the server, and confirm no `sk_live_` or `rk_live_` string appears in your built frontend JS.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## FAQ

### Is the publishable key safe to expose?
Yes, `pk_` keys are designed for the browser. Secret (`sk_`) and restricted (`rk_`) keys are not.

### I rolled my key. Why did the old one keep working?
When rolling, Stripe lets you set an expiry of up to 7 days so you can migrate. After that it returns an expired-key error.

### What if the secret key was public?
Roll it immediately and review request logs. See /leaked-keys/stripe.

## Sources

- [Stripe: API keys](https://docs.stripe.com/keys)
- [Stripe: Error codes](https://docs.stripe.com/error-codes)

## Related

- [Stripe key leaked: first 10 minutes](/leaked-keys/stripe)
- [Fix: Stripe secret key exposed](/fix/stripe-secret-key-exposed)
- [Exposed API key checker](/tools/exposed-api-key-checker)
- [All errors](/errors)
