TenancyEngine/ docs

Authentication

TenancyEngine's HTTP API accepts exactly two credential types. Every protected route uses one of them, never both, never something else.

MechanismHeaderBound toTypical caller
Organization API key X-TenancyEngine-Api-Key: te_... A single organization Servers, CI/CD, background jobs, MCP tools, your SDK
OIDC bearer token Authorization: Bearer <access_token> A signed-in user and their org/tenant context TE Console, browser SPAs, mobile apps

Missing or invalid credentials return 401 Unauthorized. Valid credentials without sufficient scope return 403 Forbidden.

Never put an API key in browser code that ships to end users. The one exception is TE Console's own signed-in API playground, where you paste your own key into your own browser session to test your own integration. The key never leaves your machine except to call the real API directly.

Organization API key

HeaderX-TenancyEngine-Api-Key (or Authorization: Bearer te_...; both work)
Route prefix/api/v1/runtime/*
Created inTE Console → your account → API keys

Common scopes (set at key creation, comma-separated):

ScopeGrants
applications.readApplication lookup, runtime context
applications.writeProvision tenants under an application
tenants.readTenant lookup
tenants.writeCreate tenants, adjust usage
entitlements.readAdd-on / entitlement status
analytics.writeSend analytics events
sms.sendSend SMS via the platform gateway (never bundled into any composite scope, a deliberate money-spending guard)
mcp.fullComposite scope minted by the MCP device-code flow

A key only ever authorizes calls about your own organization's applications and tenants: OrganizationApiKeyMiddleware binds the request to your organization before any route logic runs, and each endpoint separately checks the specific scope it needs.

OIDC bearer token

HeaderAuthorization: Bearer <access_token>
Issuerhttps://auth.saasruntime.com (discovery: /.well-known/openid-configuration)
Route prefix/api/v1/console/*, /api/v1/admin/*

Use a bearer token when a human is signed in and authorization should reflect that person's roles and organization/tenant membership: console UIs, staff tooling, or your own product's backend acting on behalf of a logged-in user.

Quick decision matrix

ScenarioUse
Nightly job provisions tenants from your CRMOrganization API key (tenants.write)
Your backend gates a request on a tenant's plan featuresOrganization API key (applications.read)
Your own console page saves a setting for the signed-in userOIDC bearer (their session)
MCP tool call over HTTPOrganization API key (usually mcp.full, via device flow)

Example: get your application

curl -sS "https://auth.saasruntime.com/api/v1/runtime/applications/your-app-slug" \
  -H "X-TenancyEngine-Api-Key: te_your_key_here"

Error handling

StatusMeaningTypical fix
401Missing, invalid, expired, or revoked credentialRotate the key; check expiresAtUtc; refresh the OIDC token
403Valid credential, insufficient scopeAdd the scope at key creation, or use a bearer token with the right role
404Resource doesn't exist or belongs to a different organizationBoth cases 404, deliberately: TenancyEngine never confirms another org's data exists
429Rate limitedBack off and respect Retry-After

Security checklist

See also: Getting started, API reference, SDKs.