Skip to content

Stripe go-live errorStripe: “Invalid API Key provided”

Checkout worked yesterday, or in test mode, and now every payment request fails with Invalid API Key provided. Stripe didn’t recognise the key your server sent: it is the wrong kind of key, it was rolled or expired, or the live app isn’t sending the key you think it is. Here’s each cause, in Stripe’s words, or hand it over at a fixed price.

Short answer

Check the key your production server actually sends. It must be a secret key (sk_live_) or a restricted key (rk_live_) from the Stripe account you mean, copied whole, and not one that was rolled or deleted. Copy the current key from the Dashboard into your host’s production environment variables, redeploy, and never put it in front-end code.

Which key is wrong, most common first

  1. 01

    The production environment variable is missing or stale

    “If a request doesn’t include a valid key, Stripe returns an invalid request error.” Stripe, API keys

    The most common case: the key is set on your machine or a preview deploy but empty, truncated or out of date in production. Check the variable your server reads in your host’s production settings, look for a stray space or quote mark, then redeploy so the new value is used.

  2. 02

    A publishable key where the secret key belongs

    “The API key provided is a publishable key, but a secret key is required.” Stripe, Error codes

    The server needs a secret or restricted key, and the publishable key belongs only in the browser or mobile app. Stripe reports a pk_ key on the server with its own code, secret_key_required, so if your logs show that code, the server variable holds the publishable key. Check the two variables weren’t swapped.

  3. 03

    The key was rolled or deleted

    “Code that uses the expired key can no longer make API calls.” Stripe, API keys

    If someone rolled the key in the Dashboard, the old one stops working, after a grace period if one was set. Put the replacement key in every place that used the old one, including background jobs and other servers. An expired key shows a different code, api_key_expired, so if your logs show that code, this is the cause too.

  4. 04

    A test key on live data, or the other way round

    “When you’re ready to accept real payments: Switch to your live mode keys, which start with pk_live_, rk_live_, and sk_live_.” Stripe, API keys

    Going live means switching to the live keys, and live mode starts without your test customers, prices and webhook endpoints. Our page on test mode working but live failing covers the rest of that switch.

  5. 05

    The secret key is in front-end code

    “Don’t embed secret or restricted API keys in source code or client-side applications.” Stripe, Authentication

    AI builders sometimes put the secret key in the browser bundle, or in a variable with a public prefix such as VITE_ or NEXT_PUBLIC_. Move every call that needs it to the server. If the secret key was ever public, roll it in the Dashboard.

Checked against the vendor’s docs on : Stripe docs: API keys; Stripe docs: Error codes; Stripe API reference: Authentication.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Stripe works in test mode, not live · Stripe webhook signature error · Vercel environment variables undefined · Stripe PaymentIntent already succeeded

Questions

More on this error

How do I tell which key my server is sending?

Log only the first 8 characters of the key at startup, never the whole key. sk_live_ or rk_live_ is right for live payments; pk_ means the wrong variable, and sk_test_ means the test key is still set.

Do I need a new key?

Only if the key was rolled, expired or exposed. Otherwise copy the current secret or restricted key from the Dashboard’s API keys page into production. Make sure the Dashboard is in live mode when you copy it.

Can you change the keys for me?

The keys live in your Stripe and hosting accounts, so you add them there. We move every Stripe call to the server, read the keys from settings, and hand it over as a pull request with the dashboard steps in order.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.