firebase deploy fails because the Stripe client has no API key
Neither apiKey nor config.authenticator providedShort answer
The Stripe client is built from a key that is empty at that moment. Firebase loads your code during deploy, when secrets and parameters are not available, so a new Stripe(key) at the top of the file receives undefined. Create the client inside the function, bind the secret to the function with the secrets option, and set the secret before you deploy.
Fix it fast
1Find out which cause you have
Find where the Stripe client is created and what key it reads. A client created at module level, outside any function, is the first suspect.
grep -rn "new Stripe\|Stripe(" functions/src functions/index.js 2>/dev/null2Match what you see, then jump to its fix
- 1
The failure happens during firebase deploy, before any request is served.The client is created in global scope, before the key existsFix - 2
Deploy succeeds, then calling the function throws the same error, or stripeKey.value() is an empty string.The secret is not bound to the functionFix - 3
Secret binding is in place, the value is still empty.The secret was never set, or was set after the last deployFix
- 1
What does the error look like?
Neither apiKey nor config.authenticator provided
Cause 1 of 3
The client is created in global scope, before the key exists
1Check
Firebase documents that secret values are hidden until the function executes, and that reading parameter values in global scope causes a deployment failure. stripe-node also fails when the file that creates the client is imported while the key is not there, for instance during a build step.
sed -n 1,20p functions/src/index.ts2Fix
Create the client lazily, on first use inside the function. For initialisation that depends on a parameter, Firebase recommends onInit().
import Stripe from 'stripe';
import { defineSecret } from 'firebase-functions/params';
import { onRequest } from 'firebase-functions/v2/https';
const stripeKey = defineSecret('STRIPE_SECRET_KEY');
let stripe: Stripe | undefined;
const getStripe = () => (stripe ??= new Stripe(stripeKey.value()));
export const createCheckout = onRequest({ secrets: [stripeKey] }, async (req, res) => {
const session = await getStripe().checkout.sessions.create({ /* ... */ });
res.json({ id: session.id });
});3Verify
Deploy again; the load step passes.
firebase deploy --only functionsConfirmed by firebase.google.com
Cause 2 of 3
The secret is not bound to the function
1Check
A function reads a secret only when it is listed in that function's secrets option. A function that is missing from the list sees nothing, so each Stripe function needs its own binding.
grep -n "secrets:" functions/src/*.ts2Fix
Add the secret to the options of every function that uses Stripe.
export const stripeWebhook = onRequest({ secrets: [stripeKey] }, handler);3Verify
Redeploy, call the function and read its log in the Firebase console; no missing-key error appears.
firebase deploy --only functionsConfirmed by firebase.google.com
Cause 3 of 3
The secret was never set, or was set after the last deploy
1Check
Create the secret with the CLI. Firebase notes that after you set a value you must deploy the functions that use it.
grep -rn "STRIPE_SECRET_KEY" functions/src2Fix
Set the secret, then deploy the functions that use it.
firebase functions:secrets:set STRIPE_SECRET_KEY
firebase deploy --only functions3Verify
Call the function again.
firebase deploy --only functionsConfirmed by firebase.google.com
How do I stop it coming back?
- Keep the Stripe key in Secret Manager through defineSecret, not in .env files (they are not a secure place for secrets) or in code.
- Do not use functions.config(): it is deprecated and Firebase says deploys that use it will fail after March 2027. Export it with firebase functions:config:export.
- Create third-party clients lazily so a build or deploy step can import the file without the key.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Payments
Stripe webhook: no signatures found matching the expected signature
No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
Stripe signs the exact bytes it sends, using that endpoint's own secret.
5 causes, each with a fixPayments
Metadata you set on a Stripe Checkout Session is empty when you read it
event.data.object.metadata.order_id is None in the webhook handler
Stripe does not copy metadata between objects on its own.
3 causes, each with a fixPayments
Stripe Elements shows console warnings or errors in a Next.js checkout
Could not find Elements context; You need to wrap the part of your app that calls useElements() in an <Elements> provider.
Most React Stripe.js warnings come from four mistakes: calling loadStripe inside a component, using useStripe or useElements outside the Elements provider, using the objects before they have loaded, and a Content Security Policy that blocks js.stripe.com.
4 causes, each with a fixPayments
Stripe says No such checkout.session when you retrieve a session
resource_missing
A resource_missing error means the ID is not visible to the key you used.
3 causes, each with a fixPayments
Stripe says there is no such token when your server uses it
livemode_mismatch
Stripe answers with a missing-resource error when the ID you send does not exist for the key you use.
3 causes, each with a fixPayments
A payment method is missing from the Stripe Payment Element, or the call to exclude it fails
Excluding apple_pay, google_pay or link with excluded_payment_method_types returns an error
With automatic payment methods, Stripe decides which methods the Payment Element shows.
5 causes, each with a fix