All guidesSupabase RLS and keys
On this page

Supabase question

Where do I find the Supabase service role key?

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

Find your service role key in Supabase Dashboard > Settings > API Keys, store it only in a server-only Vercel environment variable, then run npx -y viberaven check in your repo to flag privileged keys in client code or public-prefixed variables. VibeRaven does not rotate keys or verify your live Vercel configuration. Where to find the Supabase service role key: in the Supabase Dashboard under Settings > API Keys, where the legacy service_role key starts with eyJ and its replacement, the secret key, starts with sb_secret_. Neither belongs in client code: both bypass row level security. The secret key is on the Publishable and secret API keys tab of that page. Copy either one only into a server environment variable such as SUPABASE_SERVICE_ROLE_KEY, never into one with a NEXT_PUBLIC_ or VITE_ prefix.

Use this from your agent
  • Claude Code: 7 read-only tools; public repos only.
    claude mcp add --transport http viberaven https://viberaven.dev/mcp
  • Codex: same server, from the Codex CLI.
    codex mcp add viberaven --url https://viberaven.dev/mcp
  • In your repo: writes Vercel + Supabase check rules for your agent (what it writes).
    npx -y viberaven init
Paste this to your agent
Run `npx -y viberaven@1.8.0 check` in this repo and fix service_role or sb_secret_ keys in client code, NEXT_PUBLIC_ or VITE_ variables. Help me find my own key in Settings > API Keys without printing it. Report live checks you could not run.

Open your app's repo in your coding agent, then paste this request.

Terminal output of npx viberaven check on a Next.js fixture repo, flagging NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY in .env.example as a Supabase service role key in a client-prefixed env variable.
Terminal output of npx viberaven check on a Next.js fixture repo, flagging NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY in .env.example as a Supabase service role key in a client-prefixed env variable.

Quick answer

Legacy service_role key: Supabase Dashboard, Settings > API Keys, the key labelled service_role. It is a JWT that starts with eyJ, like the anon key next to it.

Secret key, its replacement: the same Settings > API Keys section, on the Publishable and secret API keys tab. It starts with sb_secret_. If you see a Create new API keys button, the project has only legacy keys so far, and creating them leaves service_role working.

Local stack: supabase status prints a secret key, which takes the place of the local service_role key. Edge Functions: SUPABASE_SERVICE_ROLE_KEY is already set at runtime.

The dashboard path, tab name and key prefixes were checked against Supabase's API keys and migration guides on 2026-10-27.

Why the service role key 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 env 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". Supabase answers a secret key sent from a browser with 401 Unauthorized, but notes that "an attacker can still use the key from other tools".

If the key already reached client code, a public repo or a log, treat it as leaked and follow the rotation steps.

Not sure whether yours is out? Check a public .env, your domain, your bundle and GitHub alerts.

SUPABASE_SERVICE_ROLE_KEY: where does it come from?

In your own server code, SUPABASE_SERVICE_ROLE_KEY is just an env 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 set for you. 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 do not copy the key into a function by hand.

Where the service role key is, and where it goes

  1. 1
    In the Supabase Dashboard, open your project, then Settings > API Keys. Supabase says "Every key lives there, legacy or not, and there is no separate Settings > API page", so a tutorial that sends you to Settings > API and "Project API keys" is out of date.
  2. 2
    Pick the key. The legacy service_role key starts with eyJ, like the anon key next to it, so read the label before you copy. A secret key starts with sb_secret_, on the Publishable and secret API keys tab. If the project has none yet, create one on the same page: Supabase says it is added "alongside your existing anon and service_role keys without affecting them".
  3. 3
    From a terminal, the Supabase CLI lists the same keys:
    Terminal
    supabase projects api-keys --project-ref <your-project-ref>
  4. 4
    On a local stack started with supabase start, run supabase status. Supabase says the publishable and secret keys are in its output, under Authentication Keys.
  5. 5
    Store 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=

Official docs behind this answer, checked 2026-10-27

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 by the end of 2026. 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.