Skip to content
>_VibeUnstuck

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. 1

    See the prefix, not the whole key

    Log the first seven characters and the length. sk_test_ and sk_live_ are secret keys. rk_test_ and rk_live_ are restricted keys. pk_ is publishable. If the prefix is pk_, stop and use the publishable-key page. If the length is the placeholder from a README, the real key was never set.

  2. 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_KEY with no NEXT_PUBLIC_ or VITE_ prefix. Restart the local server. On Vercel, add it for that environment and redeploy. The old deployment keeps the old value.

  3. 3

    Replace an expired restricted key

    Expired API Key provided is the rk_ 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 unrestricted sk_live_ to get past an expiry you can replace.

  4. 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 with No 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