The two kinds of key
How a request is authenticated
Every call carries a key in theapikey header. Calls made on behalf of a signed-in person also carry their access token:
- The gateway reads the key. A missing key is
missing_api_keyand a bad oneinvalid_api_key(both401). - It checks the key’s limits: expiry, allowed browser origins, allowed addresses, allowed routes, rate limit, and your plan’s quotas.
- It checks the key’s scopes (below).
- If there is a bearer token, it identifies the person: their id, roles, organization and assurance level.
- The access rule for what’s being asked is evaluated with all of that.
Scopes
A scope names something a key may do. A scope has the formfamily:read, family:write or family:*:
readallows looking:GET,HEADandOPTIONSrequests.writeallows changing: every other method.*allows both.- A lone
*is everything.
The scope families
A publishable key can only hold the application families (
data, storage, auth, flows, ai, realtime). Management scopes need a secret key because the management API is out of a browser’s reach.
Presets
When you create a key, Start from a preset and adjust:
The two AI presets are what AI tools use.
Other limits on a key
Besides scopes: an expiry, allowed IP ranges and allowed routes (GET /rest/v1/*). The environment also has a list of websites allowed to use publishable keys. All refuse the call at the gateway. See API keys.
Rules of thumb
- Put the publishable key in client code. It is meant to be seen.
- Keep the secret key in an environment variable on a server. The browser build of the client refuses to start with one.
- Never trust the browser for permissions. Your access rules run on the server for every request, whatever the client sends.
- Do not store anything sensitive in
user_metadata, since the user can edit it. Store permissions inrolesorapp_metadata, set from a server. - Give each app and job its own key with the fewest scopes it needs.
Choosing a key on a server
See Node.js for both patterns.
Rotating and revoking
If a secret key may have leaked, rotate it: create the replacement, deploy it, and let the old one expire after a grace period. If you are sure it leaked, revoke it now. See API keys.Redirect addresses
Links in emails (confirmation, reset, invite) and social sign-in can only return to addresses you have listed under Users & auth → Domains. List exactly your app’s addresses, includinghttp://localhost:… for development, and no wildcards you do not need. See Redirect URLs.
Go-live security checklist
- Secret keys only on servers, in your host’s secret store, never in a repository or a mobile app.
- A different key per environment, and per app or job, each scoped.
- Websites allowed to call it lists only your real sites (Environment settings).
- Servers allowed to use secret keys is set if your servers have fixed addresses.
- Every table has an access rule. No table is left open by accident. Test each rule as a signed-in person, as a different person, and as nobody.
- Password policy, two-step verification and attack protection are set the way you want.
- Models are Servers only unless a browser must call them, and agents have a cost limit (Approvals and limits).
- Webhook receivers verify signatures (Verify signatures), and inbound hooks aren’t set to None.
- Alarms and a backup schedule are on.
- You know where the audit log is.