Guide
Supabase's new API keys: moving from anon/service_role to publishable/secret keys before the deprecation
Short answer: replace the legacy anon key with a publishable key (sb_publishable_...) everywhere you ship code, and the legacy service_role key with a secret key (sb_secret_...) everywhere you run server code, then deactivate the legacy keys once nothing uses them. Supabase's docs say the anon and service_role keys are being deprecated in early 2027, and both key types work side by side until then, so you can switch one piece at a time.¹ ²
Most of the work is a find-and-replace. The parts that break apps are Edge Functions, Database Webhooks and anything that sends the key as a Bearer token, so this guide spends most of its time there.
When do the legacy keys go away?
As of 27 November 2026, Supabase's API keys and migration docs say it is "deprecating the anon and service_role keys in early 2027".¹ ² We haven't found an exact day in any official Supabase source, so don't plan around one.
Earlier wording was later: the original GitHub announcement's timetable listed "Late 2026, TBC" for deleting the legacy keys, and said apps that hadn't moved to the new keys by then would break.³ Supabase changed its docs to "early 2027" so they match the notice in the dashboard.⁴ The same announcement said paused projects restored from 1 November 2025 come back without the legacy keys, which is a good reason not to wait.³
How to tell which keys you're using
- Legacy keys are long JWTs that start with
eyJ. Supabase's docs point out that if a tool, tutorial or AI assistant tells you to copy a long key beginningeyJ, it was written for the legacy keys.¹ - New keys are short strings that start with
sb_publishable_orsb_secret_. They are not JWTs.¹
The roles don't change. The publishable key gets the same low privileges as anon, so your Row Level Security (RLS) policies behave the same, and a secret key runs as the service_role Postgres role and bypasses RLS, just like the old service_role key.¹ ²
| Legacy key | Replace with | Where it belongs |
|---|---|---|
anon (eyJ...) |
Publishable key (sb_publishable_...) |
Web pages, mobile and desktop apps, CLIs, public source code |
service_role (eyJ...) |
Secret key (sb_secret_...) |
Servers, Edge Functions, cron jobs, workers |
The migration, step by step
1. Find every place that holds a key (10 minutes)
Before you change anything, make a list. Search your repo, your host's environment variables (Vercel, Netlify, Cloudflare Pages and so on), your Edge Function code and secrets, and your CI settings for SUPABASE, anon, service_role and eyJ. Add the places Supabase says are easy to miss: app versions already on users' phones, deployment scripts, third-party integrations, cron jobs, and Database Webhooks or pg_net calls.²
Supabase has no automatic usage indicator for the legacy keys, so this list is what you'll check against at the end.²
2. Create the new keys (2 minutes)
Open Settings > API Keys in the Supabase dashboard and choose the Publishable and secret API keys tab. If you see a Create new API keys button, your project is still on legacy keys only. Creating the new keys is safe: it adds a publishable key and a secret key, both named default, alongside your existing keys, and the legacy keys keep working.²
3. Swap the publishable key in your front end
Anywhere your shipped code uses the anon key, use the publishable key instead. With supabase-js that's the second argument to createClient:²
const supabase = createClient(
'https://your-project.supabase.co',
'sb_publishable_...' // was the anon key
)
Sign-in doesn't change. Users still sign in through Supabase Auth and get their own JWT.²
If the key comes from an environment variable such as VITE_... or NEXT_PUBLIC_..., the value is copied into your JavaScript at build time, so changing it on your host does nothing until you redeploy. Our env vars guide covers this. The publishable key is designed to be public, as long as RLS and grants are right (what it can and can't do).
4. Swap the secret key in your server code
Anywhere a server you control uses the service_role key, use a secret key instead.² Keep it in a server-only variable. Never put it in a VITE_ or NEXT_PUBLIC_ variable, or anywhere else that ends up in the browser.
Secret keys add two safety nets the old key didn't have. Supabase rejects them with HTTP 401 when a request comes from a browser (it matches on the User-Agent header), and you can create a separate secret key for each backend component so one leak only forces one rotation.¹ ² The browser block is a guard against mistakes, not a lock: it doesn't make a leaked key harmless, because an attacker can still use it from other tools.¹ If one has already shipped, follow our service_role key exposed guide to rotate it.
5. Update your Edge Functions
This is the step most likely to break something.
Read the new environment variables. Supabase adds SUPABASE_PUBLISHABLE_KEYS and SUPABASE_SECRET_KEYS to your functions' environment. They hold a JSON object of keys by name, not a plain string, so parse them and pick the key by name:²
// before
const secretKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
// after
const secretKey = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']
SUPABASE_PUBLISHABLE_KEYS has the same shape, so read the publishable key the same way.² ⁶
SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY still exist, but they hold the legacy keys, so a function that reads them is still on the deprecated path.¹
Send keys on the apikey header. Keep Authorization: Bearer for a signed-in user's JWT, and send publishable and secret keys on the apikey header.¹ ⁵
Don't treat verify_jwt as authentication for API keys. If a function is called with only a publishable or secret key, check that key in your own code rather than relying on the platform check. Supabase's pages don't describe the platform check the same way. The Authorization headers page says it accepts the new keys on either header for migration compatibility.⁵ The migration guide and the Edge Function 401 troubleshooting page say it only understands legacy-format keys, and tell you to turn it off for functions called with the new keys.² ⁷ They agree on what matters: passing the check with only an API key doesn't authenticate the caller, so the function has to check the key, or the user's JWT, in its own code.¹ ²
The recommended way is the @supabase/server SDK's withSupabase wrapper:² ⁶
auth: 'user'for functions your signed-in users call. It validates the user's JWT and gives you a client scoped to their RLS policies.auth: 'secret'for functions called by your own backend, cron jobs orpg_net. It accepts only the secret key nameddefaultunless you name another, for exampleauth: 'secret:billing'.auth: 'none'only for functions that verify callers some other way, such as Stripe webhooks, where you check Stripe's signature yourself (see our Stripe webhooks guide).
For functions that check callers this way, Supabase's migration guide says to set verify_jwt = false so the SDK does the checking.² Supabase also says to leave verify_jwt on for functions only ever called with a user JWT, and not to turn it off just to clear a 401 in development.⁵ ⁶
6. Fix Database Webhooks and pg_net calls
Calls from Postgres usually send the service_role key as Authorization: Bearer .... The new secret keys aren't JWTs, so they're rejected there. Send the secret key on an apikey header instead. For webhooks made in the dashboard, edit each one's HTTP headers: remove the Authorization header that holds the key and add apikey.² Don't paste the secret key into SQL or webhook settings in plain text. Supabase recommends keeping it in Vault and reading it when the call is made.²
7. Check nothing still uses the legacy keys
Go back to your list from step 1 and confirm every entry now uses sb_publishable_ or sb_secret_.² A quick test that a publishable key works: call a table route such as /rest/v1/your_table or /auth/v1/health, not the root /rest/v1/, which only accepts secret keys and gives a publishable key a 401.¹
8. Deactivate the legacy keys
In Settings > API Keys, deactivate the legacy keys. If you find a client you missed, you can reactivate them, so this step can be undone.² One exception: if the legacy service_role key ever leaked, move the missed client to a new key instead, because reactivating would bring the leaked key back.⁸
Optional next step: the new keys don't use your project's JWT secret, but the access tokens Supabase Auth gives your users are still signed with it. Moving to JWT signing keys is a separate migration that takes your whole project off the shared secret.²
What usually goes wrong
- The new key isn't live. You changed the variable on your host but didn't redeploy, so the old key is still built into the JavaScript.
- A secret key in a public variable.
VITE_SUPABASE_SECRET_KEY"works" in local tests and publishes the key. Browser calls get a 401, but the key is still exposed and needs rotating.¹ - Edge Functions still reading
SUPABASE_SERVICE_ROLE_KEY. They keep working until you deactivate the legacy keys, then fail.¹ - Keys sent as
Bearertokens. Secret keys sent asAuthorization: Bearerfrompg_netor Database Webhooks are rejected, and nothing can verify a new key as a JWT.² ⁵ Use theapikeyheader. verify_jwtturned off with nothing in its place. Then anyone who finds the function's URL can call it. AddwithSupabase, or a signature check for webhooks.⁶- Old mobile app versions. Builds already on users' phones still carry the
anonkey. Ship the update and give it time before you deactivate.² - A false alarm from
/rest/v1/. A 401 from the root path with a publishable key is expected. Test a table route instead.¹ - Realtime disconnects. Public Realtime connections last at most 24 hours unless they're upgraded with a signed-in user.¹
FAQ
When will the Supabase anon and service_role keys stop working? Supabase's docs say the keys are being deprecated in early 2027.¹ As of 27 Nov 2026 we haven't found an exact date in Supabase's docs or announcements, so migrate now rather than waiting for one.
Is the Supabase publishable key safe to put in my frontend?
Yes. It replaces the anon key, has the same low privileges, and is designed to be public. What it can reach depends on your RLS policies and grants.¹ ²
Do I need to change my RLS policies?
No. Requests with the publishable key run as anon when nobody is signed in and as authenticated when a user's JWT is sent too, exactly as with the anon key. A secret key runs as service_role. Existing policies behave the same.¹ ²
Does switching keys change how my users sign in? No. Supabase says user authentication is unchanged: users still sign in through Supabase Auth and get their own JWT.²
Can I undo deactivating the legacy keys?
Yes, you can reactivate them in Settings > API Keys.² Don't do that if the service_role key ever leaked, because reactivating restores it.⁸
Want a second pair of eyes before you flip the switch? Run a free Quick Check on your live URL to look for sb_secret_ and service_role keys in the JavaScript it loads, or book the $49 Launch Check for a fuller pre-launch review. We never need your passwords or keys.
Sources
- Supabase docs, API keys (deprecation notice "early 2027"; key types and prefixes; keys aren't JWTs;
eyJmeans legacy; role mapping; secret keys blocked in browsers byUser-Agent; Edge Function environment variables; known limitations:apikeyheader,verify_jwt,GET /rest/v1/, Realtime 24 hours): https://supabase.com/docs/guides/getting-started/api-keys - Supabase docs, Migrating to publishable and secret API keys (steps,
defaultkey names,SUPABASE_SECRET_KEYSJSON,pg_netand Database Webhooks, Vault, no usage indicator, reversible deactivation, JWT signing keys next step): https://supabase.com/docs/guides/getting-started/migrating-to-new-api-keys - Supabase GitHub discussion #29260, Upcoming changes to Supabase API keys (original timetable, including "Late 2026, TBC" and restored projects from 1 November 2025): https://github.com/orgs/supabase/discussions/29260
- supabase/supabase pull request #54052, Change deprecation notice in docs to mention early 2027: https://github.com/supabase/supabase/pull/54052
- Supabase docs, Authorization headers (
apikeyvsAuthorization, howverify_jwttreats the new keys): https://supabase.com/docs/guides/functions/auth-headers - Supabase docs, Securing Edge Functions (
withSupabaseauth modes, named keys,verify_jwtdefault, webhooks withauth: 'none'): https://supabase.com/docs/guides/functions/auth - Supabase troubleshooting, Edge Function 401 error response (the platform check and incompatible key formats): https://supabase.com/kb/troubleshooting/edge-function-401-error-response
- Supabase docs, Rotate a leaked or compromised API key (don't re-enable legacy keys after a leak): https://supabase.com/docs/guides/security/rotate-leaked-api-keys