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

Source: https://botpassword.com/keys/supabase
Last checked: 2026-10-25

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Publishable key | `sb_publishable_` | No | Low privilege; maps to the Postgres `anon` or `authenticated` role, limited by Row Level Security | — |
| Secret key | `sb_secret_` | Yes | Elevated; maps to the `service_role` Postgres role, which bypasses RLS | — |
| anon key (legacy) | — | No | Long-lived JWT equivalent to the publishable key | Long-lived JWT |
| service_role key (legacy) | — | Yes | Long-lived JWT equivalent to the secret key; bypasses RLS | Long-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).

## 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 the 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

- `SUPABASE_URL`
- `SUPABASE_PUBLISHABLE_KEYS`
- `SUPABASE_SECRET_KEYS`
- `SUPABASE_ANON_KEY`
- `SUPABASE_SERVICE_ROLE_KEY`
- `SUPABASE_ACCESS_TOKEN`

## Gotchas

- 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.

## Using this key with AI agents (BotPassword)

- `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.

## FAQ

### 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.

## Sources

- https://supabase.com/docs/guides/api/api-keys
- https://supabase.com/docs/guides/functions/secrets
- https://supabase.com/docs/reference/cli/supabase-login
- https://supabase.com/docs/guides/getting-started/mcp
