The Supabase publishable key, the secret key and their legacy twins

By Christophe Paka · Facts checked on 23 October 2026

"What is the purpose of the publishable/anon key?" a reader asked on r/Supabase. Another asked: "Shouldn't the server side use secret key?" A third saw Lovable keep writing the old anon key back into the app.

Mix them up and the cost is real. A post on r/ClaudeCode showed an AI tool putting the service role key inside a Next.js component. That key reads every row, and now every visitor can copy it.

The Supabase publishable key is the one you may share. The figure below compares it with the other three keys, row by row.

A matrix of four Supabase API keys, publishable, secret, legacy anon and legacy service_role, compared on format, privilege, where each is allowed and which Postgres role it becomes, with the legacy pair marked deprecated.
Figure 2.2 Two current keys and their two legacy twins: the publishable kind becomes anon or authenticated , the secret kind becomes service_role .
Use this diagram on your site

Free to share in your blog post, docs, course or slides, as long as the credit link stays. Paste the code below where the figure should go.

How to read this figure

  1. Read the four column heads. The two green columns are the current keys: publishable and secret. The two gray columns are their legacy twins. The legacy anon key was the old publishable key, and the legacy service_role key was the old secret key.

  2. Read the Format row. Current keys are short strings. The publishable key starts with sb_publishable_ and the secret key with sb_secret_. Both legacy keys are long lived JWTs (signed passes) that start with eyJ. That prefix tells you at a glance which system a key belongs to.

  3. Read the Privilege row. The publishable key is low: it gets only what grants and RLS allow. A grant lets a role use a table at all; RLS, Row Level Security, then picks the rows. A role is the database identity a request runs as. The secret key is elevated: its role has BYPASSRLS, a setting that skips every RLS rule. Grants still apply to it. Each legacy key has the same power as its twin.

  4. Read the Where allowed row. The publishable key belongs in a browser, a phone app or any public code. The secret key lives in server settings only. If a browser sends it, the platform answers HTTP 401 on purpose. The legacy service_role key belongs on a server, never in a browser or a repo.

  5. Read the Postgres role row. The publishable key becomes the role anon for a stranger, or authenticated when a signed in user's JWT comes with it. The secret key becomes service_role. One surprise: if a request carries the secret key and also a signed in user's JWT, it runs as that user, under that user's policies. The access chain draws both lanes.

  6. Read the status bar at the bottom. Supabase says the legacy anon and service_role keys are deprecated (on their way out) by the end of 2026. Do not wait for the date: move to the new keys with the steps below. Both key systems work side by side until you switch the legacy pair off, and you can switch it back on. A self hosted stack issues the new sb_ keys too.

Key takeaways

  • Ship only the publishable key in browser and phone code; keep the secret key in server settings.
  • Ask your AI tool to search the project for sb_secret_; a hit in any file the browser loads is a leak.
  • If a tool hands you a long key that begins with eyJ, ask it for the publishable key instead.

Try this: move off the legacy keys

If your project still has keys that begin with eyJ, plan the move now. Your keys sit under Settings > API Keys in the Dashboard. On Lovable Cloud the project is not in your Dashboard, so send Lovable the question instead.

  1. Create the new keys: one publishable key, and one secret key per server program.
  2. Swap them into your app and your servers. The publishable key goes in the client, each secret key in its server's settings.
  3. Check that nothing still uses the old keys. Ask your AI tool: "Search this project for eyJ and sb_secret_, and list every file that holds one."
  4. Switch the legacy pair off under Settings > API Keys in the Dashboard.

Expected result: Your app runs on the current keys only. If something breaks, switch the legacy pair back on, fix it, and try again.

Questions readers ask

What is the purpose of the publishable key?

It tells the gateway two things: which project the request is for, and that a public app sent it. It never says which rows the caller may see. The database decides that. It is public by design, and a stranger who copies it gets what your page gets, and no more.

Shouldn't the server side use the secret key?

Server code may use it. But the secret key skips every policy, so your code alone must decide what each visitor sees. Never use it in code that renders one page for every visitor. You can create several secret keys, one per server program, so a leak means replacing one key.

What do I do if my secret key leaks?

Create a new secret key, replace it on your servers, then delete the old one. To catch leaks early, never log a key; log at most six characters after the prefix. And never put it in a setting your framework ships to visitors, such as one that starts with NEXT_PUBLIC_.

Why does my AI tool keep giving me a key that starts with eyJ?

It learned from older guides. The Supabase docs put it simply: if a tool, tutorial or AI assistant tells you to copy a long key that begins with eyJ, it was written for the legacy keys. Tell your tool to use the publishable key, the current one.

Sources: API keys (Supabase docs); Migrating to the new API keys (Supabase docs).

This figure is from Supabase Made Crystal Clear, chapter 2.

The chapter builds the idea step by step, with recipes you can follow, a Try it to check yourself, and every source.

Get the book

All diagrams