08 / 10ConceptStripeSupabaseOpenAIFirebase
Publishable vs. secret API keys
Not every credential is a secret in the same way. Some providers hand you a key that is designed to sit in browser JavaScript, protected by other mechanisms entirely. Confusing the two categories causes real incidents in both directions.
A field guide, provider by provider
| Provider | Designed to be public | Must stay server-only |
|---|---|---|
| Stripe | Publishable key (pk_) Client-side Stripe.js, Payment Element | Secret key (sk_) Creating charges, refunds, reading customer data |
| Supabase | anon key (eyJ… (JWT)) Client SDK calls, subject to Row Level Security | service_role key (eyJ… (JWT)) Server-side admin access, bypasses RLS entirely |
| OpenAI / Anthropic | — no public variant — These providers do not offer a browser-safe key | API key (sk-…) Always called from your server; billed per request |
| Firebase (Web) | Web app config (apiKey, etc.) Identifies your project; safety comes from Firebase Security Rules, not secrecy | Service account JSON Admin SDK on a server; full read/write, no rule enforcement |
| Google Maps | Browser key Must be restricted by HTTP referrer in Google Cloud Console | Server key Restricted by IP address, used from backend services |
ℹPublic doesn't mean unprotected
A Stripe publishable key, a Supabase anon key, and a Firebase web config are all meant to travel to the browser. Their safety comes from a differentlayer: Stripe publishable keys can only create tokens, never move money; Supabase's anon key is constrained by Row Level Security policies you write; Firebase relies on its Security Rules. Exposing the key isn't the mistake — skipping the layer that constrains it is.
✕The common AI-app mistake
A very common pattern in vibe-coded AI apps: calling
OPENAI_API_KEYdirectly from client-side code "just to get it working," often by prefixing it NEXT_PUBLIC_OPENAI_API_KEYto make the error go away. OpenAI and Anthropic don't offer a restricted, browser-safe key at all — there is no publishable-key equivalent. Every request to those APIs has to originate from your own server (a Route Handler or Server Action), which can enforce your own rate limits, auth, and usage caps before spending your quota.Self-check0/3 answered
A key being safe to expose in the browser always means the provider considers it non-sensitive.
OpenAI and Anthropic offer a publishable-style key meant for direct browser use.
A Supabase service_role key is safe to use in a Client Component as long as it’s not prefixed with NEXT_PUBLIC_.