Invalid API key (Supabase)
Supabase says "Invalid API key" on your live site? Usually the key or project URL env var is missing, mistyped, or from another project.
Reviewed October 14, 2026
What it means in plain English
Every request your app makes to Supabase carries an API key. "Invalid API key" means Supabase got a key it doesn't recognise for that project, or got no key at all.
Likely causes
- The env vars holding your Supabase URL and key were never added to your host (Vercel/Netlify), so the app sends
undefined. - You copied the key from a different Supabase project than the URL.
- Extra spaces, quotes or a cut-off key when pasting.
- You disabled the legacy
anon/service_rolekeys in Supabase but the app still uses them. (Supabase is deprecating those legacy keys by end of 2026 in favour ofsb_publishable_…andsb_secret_…keys.) - A secret key is being used in the browser: Supabase blocks secret keys from browsers and returns 401.
How to fix it, step by step
- In Supabase open Settings → API Keys (or the Connect button) and copy the Project URL and the publishable key (
sb_publishable_…, or the legacyanonkey startingeyJif your app was built with it). - Check both come from the same project (the project ref in the URL matches the dashboard).
- Put them in your host's environment variables using the exact names your code reads:
- Vite apps (Lovable, Bolt):
VITE_SUPABASE_URL,VITE_SUPABASE_PUBLISHABLE_KEY(or whatever name appears insrc/integrations/supabase/client.ts/ your client file). - Next.js (v0, Cursor):
NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY.
- Vite apps (Lovable, Bolt):
- Paste values with no quotes or spaces.
- Redeploy. Vercel applies env var changes only to new deployments.
- If you rotated or disabled legacy keys, update every place that used the old one.
- Never use the
sb_secret_/service_rolekey in front-end code; keep it for server code only.
How to check it worked
- Open the live site, open the browser DevTools Network tab and reload; Supabase requests should return 200, not 401.
- Sign in or load a page that reads data; the error should be gone.
Sources
Related fixes
Can't fix it? Get help.
If the steps didn't clear the error, send what the screen says. A person can take a look. This is a request for a paid fix, not an instant chat.