Supabase API keys are under Settings → API Keys in the dashboard. The newer publishable (sb_publishable_) and secret (sb_secret_) keys replace the legacy anon and service_role JWT keys, which are being deprecated by the end of 2026. Publishable keys are safe in client code; secret and service_role keys bypass Row Level Security and must stay on the server.
Supabase key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Publishable key Safe to ship in browsers, mobile apps and CLIs. It does not protect against XSS, CSRF or phishing, so enable RLS on every table. | sb_publishable_ | No | Low privilege; maps to the Postgres `anon` or `authenticated` role, limited by Row Level Security | — |
| Secret key Server-side only. Requests with a browser User-Agent return HTTP 401. Never prefix the variable with NEXT_PUBLIC_. | sb_secret_ | Yes | Elevated; maps to the `service_role` Postgres role, which bypasses RLS | — |
| anon key (legacy) Legacy keys start with eyJ. Deprecated by the end of 2026. | — | No | Long-lived JWT equivalent to the publishable key | Long-lived JWT |
| service_role key (legacy) Legacy keys start with eyJ. Deprecated by the end of 2026; deactivate rather than delete. | — | Yes | Long-lived JWT equivalent to the secret key; bypasses RLS | Long-lived JWT |
How to create a Supabase key
- Open your project in the Supabase dashboard.
- Go to Settings → API Keys, or use the Connect dialog for a ready-to-paste URL and publishable key.
- Create a secret key there if you need one for a backend component.
- Or from the CLI run
supabase projects api-keys --project-ref <ref>.
Limiting what the key can do
Use the publishable key in clients and rely on Row Level Security for access. Use a separate secret key for each backend component to limit the damage of a leak. Management API and MCP access use a separate personal access token, which should be scoped to a project with only the needed permissions.
How to rotate a Supabase key
- Create a new secret key in Settings → API Keys.
- Replace the old key in every component that uses it.
- Confirm all components work with the new key.
- Delete the old secret key (permanent) or deactivate a legacy key (reversible).
Creating new keys does not revoke legacy keys; both work until you deactivate the legacy ones. Fix the root cause of the leak before rotating.
How to revoke a Supabase key
- Delete the secret key in Settings → API Keys once nothing depends on it. Deleting is permanent.
- Deactivate legacy
anonandservice_rolekeys there; this can be reversed.
If your Supabase key leaked
- Fix the root cause of the leak first.
- Create a replacement secret key and roll it out everywhere.
- Delete the exposed secret key, or deactivate the legacy key.
- Review database activity for access you did not make.
Environment variables and CLI
Supabase's SDKs and docs read the key from SUPABASE_URL, SUPABASE_PUBLISHABLE_KEYS, SUPABASE_SECRET_KEYS, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY or SUPABASE_ACCESS_TOKEN.
Supabase CLI (supabase): supabase login uses a personal access token and stores it in the system credential store; in CI set SUPABASE_ACCESS_TOKEN
Things that catch people out
- The env var names above are the defaults Supabase injects into Edge Functions;
SUPABASE_PUBLISHABLE_KEYSandSUPABASE_SECRET_KEYShold JSON dictionaries of keys. - Publishable and secret keys are not JWTs; send them in the
apikeyheader, notAuthorization: Bearer. - Edge Functions must check API keys in code;
verify_jwtdoes not authenticate the caller. - The hosted MCP server uses OAuth by default; scope it with
?project_ref=and?read_only=truewhen it touches production data.
Recent incidents that put Supabase keys at risk
If you were affected by one of these, rotate your Supabase keys using the rotation steps above.
- VS Code and Open VSX extensions leaked 550+ secrets, including tokens that could publish updates 2025-10-15
Using your Supabase key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Supabase key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
cli_login | Lets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned. |
rotate | Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet. |
store_secret | Saves a value the agent already holds as a new vault item. |
Supabase also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I find my Supabase service role key?
In the dashboard under Settings → API Keys. New projects use a secret key (sb_secret_) instead of the legacy service_role JWT.
Is the Supabase anon key safe to expose?
Yes, if Row Level Security is enabled on every table. The anon key and the newer publishable key are meant for client code.
What is the difference between the Supabase anon key and publishable key?
They map to the same low-privilege role. The publishable key is the replacement for the legacy anon JWT.
How do I rotate a Supabase secret key?
Create a new secret key, deploy it everywhere, confirm it works, then delete the old key.
Can an AI agent use my Supabase key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.