Give every backend job a key that can do one thing
One powerful key in an environment variable is the easiest setup and the worst failure. When a key leaks, the scopes it carries are the limit of the damage.
5 min read · Last checked
In short
Key points
- Every runtime call checks for the scope it needs and answers 403 if the key lacks it.
- Read the scope catalog from the public endpoint instead of guessing names; a wrong name returns 400.
- Scopes that spend money or return credentials are never part of a composite scope. A key needs that exact scope.
- Create separate keys for separate jobs so that you can revoke one without stopping the others.
How scopes are checked
An organization API key carries a list of scopes, sent in the X-TenancyEngine-Api-Key header; the SDKs add the header for you. A call made without the scope it needs returns 403 with a message that names the missing scope. Creating a key with a scope that does not exist returns 400 and lists the invalid names.
Scopes are exact. A scope satisfies only its own check, apart from two legacy scopes described below.
Read the catalog
The response is generated from the platform’s own authorization check, so the grantedBy field is accurate. A documentation test fails if the published tables drift from the catalog.
curl https://api.saasruntime.com/api/v1/public/api-key-scopes
# Each entry has: scope, label, description, group, sensitive,
# restriction, grantedBy, deprecatedTwo legacy scopes to avoid
- admin satisfies every pre-existing scope, including the spend and credential scopes, and only org-wide keys can hold it. Existing keys keep working; new keys cannot be created with it.
- mcp.full is a composite for the CLI and MCP server. It covers application, tenant, entitlement, billing and analytics scopes, and nothing that spends money or reads credentials. New keys cannot be created with it either.
Match scopes to jobs
Check the scope names against the catalog before you copy this list; the catalog is the source of truth and changes over time.
- The signup handler that creates customer workspaces: tenants.write (and applications.read if it looks the application up).
- The request path that reads the runtime context to gate features: applications.read, which that call requires.
- The worker that reports usage: tenants.write, which covers consuming and releasing usage.
- The job that mints customer setup links: setup-links.write only.
- Anything that sends SMS: sms.send only, and treat it as spend. It is deliberately excluded from composite scopes.
Rotate and revoke
Keep one key per job and per environment, store it in your secret manager, and rotate it on a schedule you can name. A key can also be allowed to rotate itself, and only itself, when the organization and application policy permit it. Never ship an organization API key to a browser or a mobile app.
Honest limits
What to know before you rely on this
- Scope names and descriptions come from the live catalog; this article lists examples, not the full set.
- Some scopes are restricted to org-wide keys or to TenancyEngine’s own services.
Questions people ask
Why was my call refused with 403?
The key lacks the scope that call needs. The message names it. Add that exact scope to a new key and revoke the old one.
Can one key cover several jobs?
It can, but one leaked key then exposes every job. Separate keys cost almost nothing and shrink the damage.
Sources
Keep reading
Try it on the free plan
One app and five customers, no credit card required.