Invalid API key
Last verified:
The fix
Invalid API key. Supabase received a key this project does not accept. Copy the publishable key, or the legacy anon key, from the same project as the URL. No API key found in request means the header was missing.
- 1
Pass the publishable key from the same project
Open Connect in the Supabase dashboard, or Settings, API Keys. There is no separate Settings, API page. Copy the project URL and the publishable key into the names your client already reads. Legacy apps can keep
NEXT_PUBLIC_SUPABASE_ANON_KEYwhile that anon key is still enabled. Vite uses theVITE_prefix. Do not wrap the value in quotes if the env file keeps them.import { createClient } from "@supabase/supabase-js"; export const supabase = createClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!, ); - 2
Restart or redeploy after the env change
Next.js inlines
NEXT_PUBLIC_when the client bundle is built. Vite inlinesVITE_the same way. A dev server that was already running, and a Vercel deployment that was already built, still have the old value. Restart, or redeploy. - 3
Look at the apikey header on the failing request
In the network panel the request to
/rest/v1or/auth/v1should sendapikey. No header isNo API key found in request, which is an undefined env var or a hand-writtenfetch. A header that is present and still returnsInvalid API keyis the wrong project, a deleted key, or extra characters. Keys fromsupabase startbelong to the local stack. They do not open the hosted project. - 4
Leave the secret key on the server
A browser variable that starts with
sb_secret_or holds the service_role JWT is not the fix forInvalid API key. Move that call to a server route that readsSUPABASE_SECRET_KEYwith no public prefix. If the browser already shipped the secret, that isForbidden use of secret API key in browseronce the gateway recognizes it, and the key has to be rotated after the bundle is clean.
Why it happens
The API gateway checks the apikey header before Postgres runs. Invalid API key means a key arrived and this project does not accept it: the wrong project, a rotated key, quotes or a space copied into the value, or a truncated string. No API key found in request means the header was absent. Opening the project URL in a browser tab sends no header, so that tab shows the missing-key sentence even when the app's key is fine.
The browser client wants the publishable key, sb_publishable_..., or the legacy anon key, which is a long JWT starting with eyJ. Supabase is deprecating the anon and service_role keys by the end of 2026. Both forms work until you disable the legacy keys under Settings, API Keys. Publishable and secret keys are not JWTs. Send them on the apikey header. createClient does that. Putting sb_publishable_... on Authorization: Bearer and asking a server to verify it as a JWT fails, because the key has one part. The secret key, sb_secret_..., and the legacy service_role key do not belong in the browser. A secret key that the browser actually sent is the next page. An RLS denial is new row violates row-level security policy. supabaseUrl is required is thrown before any request, when the env var was empty.
The next error you'll probably hit
Once this is fixed, the usual follow-up is Forbidden use of secret API key in browser. Forbidden use of secret API key in browser. The request sent an sb_secret_ key with a browser User-Agent. Put the publishable key in the client, and keep the secret in a server variable with no public prefix.
Prompt to paste back into your AI tool
Paste this above the error.
Supabase returns Invalid API key. If the body instead says No API key found in request, say that and treat the header as missing. The request host is <host, no query string>. Do not switch the browser client to the service_role key or an sb_secret_ key. Do not disable RLS. Do not put the key on Authorization: Bearer and delete the apikey header. Publishable and secret keys are not JWTs. 1. Read the URL and the key from env. If either is undefined, fix the name (NEXT_PUBLIC_ or VITE_) and tell me to restart or redeploy. 2. If both are set, tell me to recopy the URL and the publishable key (or the legacy anon key) from Connect or Settings, API Keys, in the same project. Check for quotes and spaces. 3. Show the createClient call. Do not rewrite queries. 4. If the value starts with sb_secret_ or is the service_role JWT, move it to a server-only variable and tell me to rotate it after the client bundle no longer contains it.
Common questions
+How is Invalid API key different from No API key found in request?
Invalid API key means the apikey header was sent and this project rejected it. No API key found in request means the header was not sent. A browser tab pointed at the project URL has no header. The app's env var can still be right.
+I pasted the new sb_publishable_ key and a tutorial still wants the eyJ anon key. Which one?
The publishable key replaces the anon key for browser code. The anon key still works until you disable legacy keys. Both have to come from the same project as the URL. The publishable key is not a JWT. createClient sends it as apikey.
+The SQL editor works. The app says Invalid API key. Why?
The SQL editor is signed in as you. The app sends the apikey header. Recopy the URL and the publishable key from that same project, then restart the dev server or redeploy so the new NEXT_PUBLIC_ or VITE_ value is in the bundle.
+Is this the same as new row violates row-level security policy?
No. Invalid API key fails at the gateway, before a policy runs. An RLS denial names the policy. Fix the key first. If a real query then returns the row-level security sentence, that is the next page.
Related errors
- Forbidden use of secret API key in browserForbidden use of secret API key in browser. The request sent an sb_secret_ key with a browser User-Agent. Put the publishable key in the client, and keep the secret in a server variable with no public prefix.CursorLovableBoltSupabaseNext.jsNov 6, 2026
- supabaseUrl is requiredsupabaseUrl is required: createClient got an empty URL or key, missing when the bundle was built. Set the Supabase URL and anon key, then rebuild.CursorLovableBoltSupabaseNext.jsOct 19, 2026
- process.env.NEXT_PUBLIC_ is undefinedprocess.env.NEXT_PUBLIC_ is undefined. The name is missing from .env.local, it has no NEXT_PUBLIC_ prefix, or Next.js has not been restarted since you added it. Do not put a secret on that prefix.CursorLovableBoltNext.jsVercelNov 3, 2026
- new row violates row-level security policynew row violates row-level security policy: RLS is on and no INSERT policy allows this role. Add a policy for the signed-in user. A missing GRANT differs.CursorLovableBoltSupabasePostgresOct 15, 2026