On this page
Which key is the tutorial asking for?
Setting up a browser client? Copy the legacy anon key or its publishable replacement instead.
Migrating a backend job? Use the API key migration guide to check what that job sends before replacing its credential.
If your backend is on Vercel, save it as a Secret variable and select the environment where that job runs.
Two keys start with eyJ: read the label
The legacy anon key and the legacy service_role key are both JWTs that start with eyJ, and they sit next to each other on the same page. The anon key is public; service_role is not. Read the label before you copy.
If you see a Create new API keys button instead of an sb_secret_ key, the project has only legacy keys so far. Creating new ones leaves service_role working. There is no separate Settings > API page any more, so a tutorial that sends you to "Project API keys" was written for the old dashboard. Dashboard paths checked against Supabase’s API keys and migration guides on November 29, 2026.
SUPABASE_SERVICE_ROLE_KEY: where does it come from?
In your own server code it is just a variable name: you paste the key from Settings > API Keys into it, in .env.local and in your host's environment variables, with no NEXT_PUBLIC_ or VITE_ prefix. Supabase's own examples name the new key SUPABASE_SECRET_KEY.
In Supabase Edge Functions it is already set. Supabase says SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY "still exist in the runtime, but they carry the legacy keys", and SUPABASE_SECRET_KEYS holds the secret keys. You never paste a key into a function.
On a local stack started with supabase start, run supabase status: the publishable and secret keys are under Authentication Keys, and the local secret key takes the place of the local service_role key.
supabase projects api-keys --remote=YOUR_PROJECT_REFWhy it stays on the server
Supabase says secret keys "provide full access to your project's data, bypassing Row Level Security", lists service_role as their legacy version, and warns: "Never put one in a browser, a shipped application, or source control." A public prefix puts it there: Next.js inlines a NEXT_PUBLIC_ value "into any JavaScript sent to the browser", and Vite says VITE_ variables "will be exposed in client-side source code". A secret key sent from a browser gets 401 Unauthorized, but Supabase notes that "an attacker can still use the key from other tools".
Not sure whether yours is out? Check a public .env, your domain, your bundle and GitHub alerts.
Copy the key and store it
- 1Open your project in the Supabase Dashboard, then Settings > API Keys.
- 2For new code, take a secret key (sb_secret_) from the Publishable and secret API keys tab. If there is none yet, create one: Supabase says it is added "alongside your existing anon and service_role keys without affecting them".
- 3Store it as a server-only variable. Supabase's rule for server keys is "Never prefix these, or your bundler will ship the key":
Environment # .env.local: read only in server code, API routes or Edge Functions SUPABASE_SERVICE_ROLE_KEY=<copied from Settings > API Keys> # Wrong: these prefixes ship the value to every visitor # NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY= # VITE_SUPABASE_SERVICE_ROLE_KEY= - 4Set the same variable in your host's environment settings, then redeploy.
Where people put the key by mistake
We read 512 public Lovable repos with a supabase/migrations folder, each at its last commit before October 3, 2026. 29 of them (5.7%) commit a Supabase service role or secret key. The key was rarely in the app itself: it sat in the files around the app. No key was tested and no project is named.
Which key is which
| Key | Starts with | Where in the dashboard | In the browser? |
|---|---|---|---|
| anon (legacy) | eyJ | Settings > API Keys | Yes, with RLS on |
| publishable | sb_publishable_ | Publishable and secret API keys tab | Yes, with RLS on |
| service_role (legacy) | eyJ | Settings > API Keys, labelled service_role | No |
| secret | sb_secret_ | Publishable and secret API keys tab | No |
Where the 29 repos had it
In our sample, 25 of the 29 repos contained only the legacy service_role key. Check one-off scripts, env templates and setup notes when moving a server credential.
| Where the key was | Repos |
|---|---|
| A one-off script: fix an admin account, seed data, import users | 12 |
| .env.example or another env template, where a placeholder should be | 7 |
| A Markdown deploy guide or setup note | 7 |
| A committed .env file | 6 |
| App code the browser loads | 3 |
Related guides
Supabase and framework documentation
Browse all launch guides · Read resources · How to make and check your next change
FAQ for builders before launch
Should I copy the service_role key or a secret key?
A secret key, for new code. Supabase lists service_role as the legacy version of secret keys, both bypass Row Level Security, and Supabase is deprecating the anon and service_role keys in early 2027. Secret keys (sb_secret_) are short strings, not JWTs, and you can make one per server component. A legacy key keeps working until you disable it in Settings > API Keys.
Why can't I find the service role key in local Supabase Studio?
A local stack started with supabase start prints a publishable key and a secret key, under Authentication Keys, and Supabase says the local secret key takes the place of the local service_role key. Run supabase status to print them again while the stack is running.
