new row violates row-level security policy (Supabase)
Your insert or update is blocked by RLS. Add a policy for that exact write, without turning RLS off.
Wrong key, wrong header, or a secret key in the browser. Pick the key by where the code runs, without turning RLS off.

Use the right key for where the code runs, send it the way Supabase expects, and keep secrets off the client.
https://YOUR_PROJECT.supabase.co) and the key must be from the same project (Supabase: API keys).sb_publishable_...) or legacy anon.sb_secret_...) or legacy service_role.apikey header, not as Authorization: Bearer. Publishable and secret keys "aren't JWTs"; anything that tries to verify one as a JWT fails (Supabase: API keys)..env. Restart the dev server after changing env vars.# Browser-safe (prefix per your framework)
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...
# Server-only. Never prefix these, or your bundler will ship the key.
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SECRET_KEY=sb_secret_...
An API key tells Supabase which application is calling. It is not the signed-in user. Common misconfigurations:
User-Agent and returns HTTP 401 Unauthorized for a secret key in a browser (Supabase: API keys).apikey, not Authorization: Bearer (Supabase: API keys).eyJ... JWT are describing legacy anon / service_role keys. New keys are short sb_publishable_... / sb_secret_... strings (Supabase: API keys).service_role key in frontend code, VITE_ / NEXT_PUBLIC_ variables, or the repo (Supabase: API keys).My Supabase client returns Invalid API key or HTTP 401 on startup.
Check: project URL matches the key's project; browser code uses only the publishable (or legacy anon) key; new-style keys are sent on the apikey header; no sb_secret_ or service_role value is in client env vars or the bundle.
Do not disable RLS. Do not move a secret key into the client.
Show changes first and wait for my OK. If a secret was exposed, remind me to rotate it.
sb_secret_ and for JWTs whose role is service_role (secret key in frontend bundle).Is the publishable key safe? · Secret key in frontend bundle · JWT expired
Was it a new sb_ key, a legacy JWT key, or a secret key that had slipped into the browser? Tell us which. We'll lead with that case.
This guide is educational and based on the vendor's public docs as of the review date. Platforms change: check the linked sources. Not a security audit. Disclaimer.
From BuiltSafely · builtsafely.com · https://builtsafely.com/fixes/invalid-api-key/
The BuiltSafely weekly
Platform changes that affect the security of AI-built apps, checked against official docs. Free. Unsubscribe any time.