Skip to content

Which keys are safe to show, and which must stay secret?

Publishable keys are safe to show, because they’re made for code that runs in a browser or app. Secret keys must stay on a server, in .env and in your host’s settings. You can usually tell them apart by their first letters, and if you can’t, treat the key as secret.

Find your situation

If it’s a Stripe key
Keys starting pk_test_ or pk_live_ are publishable and safe in a web page. Secret keys (sk_) and restricted keys (rk_) must stay secret, and so does each webhook’s signing secret.
If it’s a Supabase key
Supabase’s sb_publishable_ and older anon keys may be used in app code. Table permissions and Row Level Security protect private data. sb_secret_ and older service_role keys skip Row Level Security and stay on the server. The older anon and service_role keys both start with eyJ, so check which one you have.
If it’s a Clerk key
pk_test_ and pk_live_ are publishable. sk_test_ and sk_live_ are secret, and Clerk says never to put them in a public environment variable. Webhook signing secrets, which start whsec_, are secret too.
If it’s a Firebase key
Firebase’s apiKey may be used in app code. Security Rules and App Check protect the resources. Keep service account credentials on a server with limited permissions. Use a separate server-side key for Gemini instead of enabling it on a public Firebase key.
If it’s a key for an AI service, like OpenAI or Claude
Always secret. OpenAI warns that a key in a browser or phone app lets others make requests on your account, which can mean unexpected charges. Your app’s server calls the AI and keeps the key.
If a key’s name starts with NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_
That prefix copies the value into the code every visitor downloads. Use it only for publishable keys. If a secret key has one of these names, remove the prefix. If your site already went online with it, replace the key. The answer “I shared a secret key by mistake. What do I do now?” has the steps.

Who does what

You

  • Check each key’s first letters before you decide where it goes.
  • Turn on Row Level Security in Supabase, or publish Security Rules in Firebase, before you put your product online.

Your AI tool

  • Sort your product’s keys into publishable and secret, by name only.
  • Use publishable keys in browser and app code, and secret keys only in server code.
  • Search your built site for secret key prefixes like sk_live_ or sb_secret_, without printing any values.
  • Write Row Level Security policies or Security Rules for you to review.
Hand this to your AI tool
Check how this product uses its keys. Don’t print any key values. Show names, and at most a prefix like sk_test_.
1. List every environment variable the product uses. Using each service’s current docs, say whether it’s publishable (safe in a browser or app) or secret.
2. Flag any secret key whose name starts with NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_ or another prefix my framework sends to the browser.
3. Flag any secret key used in code that runs in a browser or on a phone.
4. If I use Supabase or Firebase, check that Row Level Security or Security Rules protect my data, and tell me what’s missing.
Explain each problem in plain words and wait for my yes before you change anything.

This comes from https://buildladder.com/answers/public-or-secret-key. If you can open web pages, read https://buildladder.com/answers/public-or-secret-key.md for the current version. BuildLadder guide, tool, concept, answer and setup pages all work this way: add .md to the address.

Ask me before you install anything, sign in to anything or spend money. Never ask me to paste a password or secret key into this chat.

Where to go next

Updated Sources: Stripe API keys, Supabase API keys, Clerk environment variables, Clerk: rotate your API keys, Firebase API keys, Firebase Admin SDK setup, OpenAI: API key safety, Next.js environment variables.