Invalid API Key provided
Last verified:
The fix
Invalid API Key provided. Stripe could not accept the key string on this request. It is truncated, revoked, or not a key. A pk_ key on a secret call is a different error.
- 1
See the prefix, not the whole key
Log the first seven characters and the length.
sk_test_andsk_live_are secret keys.rk_test_andrk_live_are restricted keys.pk_is publishable. If the prefix ispk_, stop and use the publishable-key page. If the length is the placeholder from a README, the real key was never set. - 2
Strip quotes and whitespace, then use the current key
The env value is the key only, with no quotes and no newline. In the Dashboard, in the same mode as this deploy, reveal the current secret or create a new restricted key. Put it in
STRIPE_SECRET_KEYwith noNEXT_PUBLIC_orVITE_prefix. Restart the local server. On Vercel, add it for that environment and redeploy. The old deployment keeps the old value. - 3
Replace an expired restricted key
Expired API Key providedis therk_key's expiry, not a clock on your laptop. Create a new restricted key with the permissions this route uses, update the env var, and redeploy. Do not switch the route to an unrestrictedsk_live_to get past an expiry you can replace. - 4
Do not ship the secret to prove the key works
The browser gets
pk_only. A 401 from a curl you ran with the secret, from a machine that has the env, is enough to see that the key is accepted. Do not commit.env. A price in the other mode fails later withNo such price, after this error is gone.
Why it happens
Stripe rejects the request when the Authorization bearer value is not a live key for an account. The message starts Invalid API Key provided: and then a masked copy of what they received. A restricted key past its expiry says Expired API Key provided: instead. Both mean the server is not sending a current secret or restricted key.
A wrapping quote, a trailing newline, or a space becomes part of the value. A tutorial placeholder such as sk_test_... with the dots still in it is not a key. A key you rolled or deleted keeps failing until the process loads the new one. This API call cannot be made with a publishable API key is a different code, secret_key_required: the string parsed as a pk_ key and the call needs a secret. OpenAI's Incorrect API key provided is a different product. Do not paste the full Stripe key into a chat to compare it.
The next error you'll probably hit
Once this is fixed, the usual follow-up is This API call cannot be made with a publishable API key. The server called Stripe with a pk_ key. Checkout sessions, customers, and PaymentIntents need a secret or restricted key. The error code is secret_key_required.
Prompt to paste back into your AI tool
Paste this above the error.
Stripe returns: Invalid API Key provided. If the message is Expired API Key provided, or This API call cannot be made with a publishable API key, quote that instead. The env var name is <name>. The prefix we can see is <pk_, sk_, rk_, or unknown>. Do not paste the full key. Do not put the secret in a NEXT_PUBLIC_ or VITE_ variable. Do not commit .env. Do not replace a pk_ misuse with a secret in the browser. Do not log the full key. 1. If the prefix is pk_, stop. That is the publishable-key page. 2. If the value has quotes, spaces, or a newline, remove them. If it is a placeholder, say the real key is missing. 3. Tell me to set STRIPE_SECRET_KEY from the current secret or a new restricted key in the same mode, then restart or redeploy. 4. For Expired API Key, create a new restricted key. Do not switch the app to a live secret for a test route. Change no payment code.
Common questions
+Invalid API Key provided, and the Dashboard shows a key. Why does the API disagree?
The running process has a different string: an old deploy, quotes around the value, or a placeholder. Compare the prefix and the length, then redeploy with the current key. Do not compare by pasting the secret into a chat.
+The message is This API call cannot be made with a publishable API key. Is the key invalid?
No. Stripe accepted it as a pk_ key and refused the call. Secret calls need sk_ or rk_. That is the other page.
Related errors
- This API call cannot be made with a publishable API keyThe server called Stripe with a pk_ key. Checkout sessions, customers, and PaymentIntents need a secret or restricted key. The error code is secret_key_required.CursorLovableBoltStripeNext.jsOct 27, 2026
- No such price: wrong Stripe modeNo such price: that price_ id is from the other Stripe mode, or the code sent a product id. Copy a price from the same mode as the secret key.CursorLovableBoltStripeNext.jsOct 14, 2026
- NEXT_PUBLIC_ secret in the bundleA NEXT_PUBLIC_ or VITE_ secret is in the browser bundle. Rotate the key, move the call to a server route, and keep real public keys in the client.CursorLovableBoltNext.jsViteNov 11, 2026
- Changed a Vercel env var but the live app still uses the old valueSaving an environment variable does not change the deployment that is already live. Redeploy. NEXT_PUBLIC_ and VITE_ values are copied into the bundle at build time.CursorLovableBoltVercelNext.jsOct 22, 2026
- Lovable payment gateway production errorsLovable payment gateway production errors: preview takes the test card, the published app does not. Finish go-live, or use the live key and live price id.LovableCursorStripeViteNov 2, 2026