Supabase "Invalid API key": how to fix it
Your app calls Supabase and gets {"message":"Invalid API key"} with a 401, or No API key found in request. The request reached the right service, but the key it carried was wrong, missing, or from a different project.
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €491. The key belongs to a different project
The most common cause after copying an app or remixing a template. The URL points at project A and the key is from project B. Both come from Project Settings → API (or API Keys) in the same project. Check that the first part of your URL (abcd1234.supabase.co) matches the project you copied the key from.
2. The host never got your environment variables
Works on your machine, fails live: the key is in a local .env file that is not deployed. Add the variables in Vercel, Netlify or your host's settings, then redeploy, because Vite and Next.js bake VITE_ and NEXT_PUBLIC_ variables in at build time. Open your live site's network tab: if the apikey header is the word undefined or empty, this is it. See environment variables undefined in production.
3. A stray space, quote or line break in the value
Pasting a key into a host dashboard often adds a trailing newline or quotation marks. The key then looks right but does not match. Paste it again into an empty field, with no quotes, and redeploy.
4. You are using a key that was disabled or rotated
Supabase is moving projects from the old anon and service_role JWT keys to publishable (sb_publishable_...) and secret (sb_secret_...) keys. If you disabled the legacy keys, or someone rotated the JWT secret, any app still holding the old value gets Invalid API key. Update every place the key lives: the host, preview environments and any Edge Function or script. See legacy API keys are disabled.
5. A secret key sent from the browser
The new secret keys are blocked in browsers, and a service role key in frontend code is a serious leak whatever the error says. Browser code should only ever hold the publishable (anon) key, with row level security protecting your data. Keep secret keys in server code or Edge Functions only. See API key exposed in your app.
6. A custom fetch that drops the header
If you call the REST API with fetch instead of the client library, send both headers:
fetch(`${SUPABASE_URL}/rest/v1/todos?select=*`, {
headers: {
apikey: SUPABASE_PUBLISHABLE_KEY,
Authorization: `Bearer ${SUPABASE_PUBLISHABLE_KEY}`,
},
})
Quick checklist
- URL and key come from the same Supabase project
- Variables set on the host, then redeployed
- No spaces, quotes or line breaks in the pasted value
- Key not disabled or rotated; every environment updated
- Only the publishable key in browser code
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €49Still stuck?
Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Get the €49 fix, or start with a free scan.
Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.