Databases, search and data

Supabase API keys: find, store, rotate, and use them safely with AI agents

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

TypePrefixSecret?ScopeExpiry
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_NoLow 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_YesElevated; maps to the `service_role` Postgres role, which bypasses RLS—
anon key (legacy)
Legacy keys start with eyJ. Deprecated by the end of 2026.
—NoLong-lived JWT equivalent to the publishable keyLong-lived JWT
service_role key (legacy)
Legacy keys start with eyJ. Deprecated by the end of 2026; deactivate rather than delete.
—YesLong-lived JWT equivalent to the secret key; bypasses RLSLong-lived JWT

How to create a Supabase key

  1. Open your project in the Supabase dashboard.
  2. Go to Settings → API Keys, or use the Connect dialog for a ready-to-paste URL and publishable key.
  3. Create a secret key there if you need one for a backend component.
  4. 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

  1. Create a new secret key in Settings → API Keys.
  2. Replace the old key in every component that uses it.
  3. Confirm all components work with the new key.
  4. 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

  1. Delete the secret key in Settings → API Keys once nothing depends on it. Deleting is permanent.
  2. Deactivate legacy anon and service_role keys there; this can be reversed.

If your Supabase key leaked

  1. Fix the root cause of the leak first.
  2. Create a replacement secret key and roll it out everywhere.
  3. Delete the exposed secret key, or deactivate the legacy key.
  4. 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_KEYS and SUPABASE_SECRET_KEYS hold JSON dictionaries of keys.
  • Publishable and secret keys are not JWTs; send them in the apikey header, not Authorization: Bearer.
  • Edge Functions must check API keys in code; verify_jwt does not authenticate the caller.
  • The hosted MCP server uses OAuth by default; scope it with ?project_ref= and ?read_only=true when 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.

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:

IntentWhat BotPassword does
run_withRuns 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_requestMakes 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_loginLets 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.
rotatePartly 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_secretSaves 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.

Stop pasting Supabase keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.