Skip to content

API key levels, lifetime and rotation ​

This page is the API reference for the rules described in the Help Center article on API keys. All routes need an organization administrator (or, for application settings, someone who can configure the application).

Key levels ​

LevelCreateListRotate or revoke
OrganizationPOST /api/v1/console/api-keysGET /api/v1/console/api-keys?level=OrganizationPOST /api/v1/console/api-keys/{keyId}/rotate, .../revoke
ApplicationPOST /api/v1/console/applications/{applicationId}/api-keysGET /api/v1/console/applications/{applicationId}/api-keysPOST /api/v1/console/applications/{applicationId}/api-keys/{keyId}/rotate, .../revoke

Rules, each returned as 400 with a code:

  • application_level_key_requires_application_route: an organization-route request that names an applicationId.
  • application_mismatch: an application-route request whose body names a different application or organization.
  • allowlist_not_allowed_at_app_level: an application key cannot carry allowedApplicationIdsCsv.
  • scope_not_allowed_at_app_level: an application key cannot hold an organization-wide scope (for example applications.create).
  • invalid_key_level: the level filter is neither Organization nor Application.

A request for scopes beyond the caller's own permissions (the creator ceiling) returns 403. Denied creates are written to the audit log as apikey.create.denied; repeats are throttled.

Environment kinds ​

Both create routes take an optional allowedEnvironmentKinds: an array of Development, Staging and/or Production (case-insensitive names only, no numbers, no comma-joined strings).

RequestApplication routeOrganization route
field omitted or nullRecorded as ["Development"], written explicitly. The apikey.create audit row carries environmentKinds=Development;environmentKindsDefaulted=true.A key that can write (#1461) is recorded as ["Development"] too, with environmentKindsDefaulted=true. A read-only organization key keeps no kinds (every environment, harmless for reads); the audit row carries environmentKinds=unrestricted;environmentKindsDefaulted=false. "Every environment" for a writing key is an explicit choice: list all three kinds. Existing keys with no kinds keep working and show as "No environment restriction" in the Console, where Restrict (below) narrows them.
a valid listRecorded as exactly those kinds (stored sorted); environmentKindsDefaulted=false.Same.
any wrong shape: empty list, an unknown name, a duplicate (also differing only in case), a blank element, a non-string element (number, boolean, object, null, nested list), or a value that is not a list (a bare string, object, number or boolean)400 invalid_environment, nothing created, audited as apikey.create.denied with reason=invalid_environmentsame
a kind the creator may not grant403 environment_exceeds_ceiling, nothing created, audited as deniedsame

Narrowing an existing key (#1368) ​

PATCH /api/v1/console/api-keys/{keyId}/environments?organizationId=... and PATCH /api/v1/console/applications/{applicationId}/api-keys/{keyId}/environments take { "allowedEnvironmentKinds": [...] } and change the kinds of a live key in place (same key value, no rotation). The Console offers it as Restrict on the Environments column.

  • Narrow only. A key with no kinds may be set to any non-empty set (that is narrowing). A confined key may keep a subset of its current kinds; adding one is refused with 403 environment_exceeds_ceiling and nothing changes. The same set again succeeds and writes nothing.
  • Same validation as create (400 invalid_environment for a missing, empty, unknown, duplicate or wrongly shaped list, never read as "all") and the same creator ceiling. Permission is whatever may rotate the key (applications.write for the organization or the application); another application's key through the application route is 404, another organization is 403.
  • A revoked key is refused (400). A live rotation neighbour (a predecessor still in its grace window, or the live successor) is narrowed in the same transaction, so the older key can not keep the wider set; a later rotation copies the narrowed set.
  • Audit: apikey.environments.narrowed with before=/after= kinds (and alsoNarrowed= for neighbours) and the actor; refusals are apikey.update.denied.

The apikey.create audit detail always carries the same five fields in this order: environmentKinds, environmentKindsDefaulted, keyId, level, name. The key name in the audit field is percent-encoded (the key's display name is unchanged), so a name cannot add, repeat or override a field.

Where environment kinds are enforced (#1371). A key whose kinds are not empty can only address those environments on the routes below; any other environment is refused with 403 environment_not_allowed (and a value that is not a single environment name, such as a number, a comma list or a repeated parameter, with 400 invalid_environment). A key with no kinds is never checked, so every existing unrestricted key behaves as before. Every 403 environment_not_allowed denial is written to the audit log, best effort (a failure to write the audit row does not change the response) (permission.denied, reason=environment_not_allowed, with the route, the key id, the environment asked for and where it came from) and to the application log, and never contains the key.

Where the environment comes fromRuntime routesRule
?environment= (required)secrets (.../secrets, .../secrets/{key}), application configuration values (list, get, put, delete), the paywall tokenThe named environment must be in the key's kinds.
?environment= (optional, Production when omitted)offeringsSame; omitting it means Production.
The request body (environment, Production when omitted)POST .../applications/{id}/tenantsThe tenant is created in that environment; a key limited to Development must name it.
The tenant addressedGET .../tenants/{slug}, GET /runtime/tenants/{id}, imports, inbox, branding, onboarding progress, automation, SCIM, setup links, tenant webhook endpointsThe tenant's own environment must be in the key's kinds.
The tenant and ?environment=usage meters (read, consume, release, reconcile, batch) and the usage-widget tokenBoth must be in the key's kinds.
The body (environmentKind and tenantId, Production when environmentKind is omitted)POST .../custom-domains/The environment and the tenant named in the body must both be in the key's kinds.
A tenant named in the body (tenantId or tenantSlug)storage: create grant, upload URL, download URLThe named tenant's own environment must be in the key's kinds. A request that names no tenant (application-owned files) is not judged.
Every environmentapplication webhook endpoints: list, create, update, delete, deliveries, redeliver, rotate secretThese endpoints are application-wide and receive the events of every environment, so only a key that allows every environment may manage them. A key limited to some environments gets 403 environment_not_allowed.
Resolved inside the handlerevents pull, the local webhook relay, analytics ingestion (tenants named in the body)Same rule, answered with events_environment_not_allowed / relay_environment_not_allowed where those routes already did.

A tenant address that points at a tenant the key's organization does not own is not judged here; the route's own scoping answers it exactly as before, so this check reveals nothing about other organizations. A workload credential's bound environment is a separate check that still applies; when a key has both, both must allow the environment.

Environment kinds are not enforced on these runtime routes yet, so a key limited to Development can still reach them. Tenant create and offerings default to Production when environment is omitted, so a key limited to Development (every application key created since #1370 is, unless you chose otherwise) must pass environment=Development or is refused. Some belong to the whole application and have no environment to resolve: sms/send, ai/extract, AI credits (balance and grant), the MCP gateway, and the cache and caching connection details. They spend quota or hand out application-wide connection details, they are not environment data, and a Development-only key can use them. The rest are: application cache management (status, usage, opt-in, flush), the caching mode and configuration, reading, verifying and deleting an existing custom domain, storage requests that name no tenant (and the objects they reach), application search, token introspection, the environments and readiness listings, and application metadata reads (applications/{slug}, context, widget config). Each is listed with its reason in runtime-environment-kind-routes.txt next to the route tests, and a test fails when a new runtime route is added without declaring whether it enforces kinds. Tracked in #1371. Until that list is empty, kinds are not full isolation: also grant only the scopes the integration needs.

Naming kinds needs no extra permission: whoever may create the key at that level may name any kind. The environment ceiling only limits a creator that is itself confined to environments (it never widens). The returned key view lists allowedEnvironmentKinds (an empty array means the key is not confined). Rotation copies the kinds to the successor; it never widens them. Existing keys with no kinds are unchanged.

Expiry ​

Create requests take expiresAtUtc and noExpiryConfirmed.

RequestResult
expiresAtUtc in the past400 expiry_in_past
expiresAtUtc beyond the organization maximumCreated with the maximum; the response says the expiry was reduced
No expiresAtUtc, noExpiryConfirmed not true400 no_expiry_not_confirmed
allowedEnvironmentKinds includes Production, productionConfirmed not true (application and organization routes)400 production_not_confirmed
No expiry confirmed, organization does not allow it400 no_expiry_not_allowed
No expiry confirmed, organization has a maximum lifetime400 no_expiry_conflicts_max_lifetime

When no-expiry is accepted, the acknowledging user is recorded on the key. A rotated key never outlives the organization's current policy.

Organization policy ​

GET and PATCH /api/v1/console/security-policy (optional organizationId). GET needs access to the organization. PATCH needs a signed-in person (never an API key or an assistant approved through a client metadata document) who is either platform staff holding platform:organizations:write (any organization) or holds platform:organizations:security-policy:write in the target organization. Only the organization_admin role carries that permission, and it is judged against the person's role in that one organization, so administering organization A grants nothing on organization B. Everyone else gets 403 and nothing is changed; both outcomes for the organization-scoped permission are audited (organization.security_policy.write_authorized and organization.security_policy.write_denied). The same rule applies to PUT /api/v1/console/session-policy and PATCH /api/v1/console/organization-mfa-policy. The permission exists only on the organization role and cannot be added to a custom platform role. A PATCH whose allowedIpRanges does not contain the caller's own address (when the caller belongs to the organization) is refused with 400 ip_allowlist_excludes_caller, and with caller_ip_unknown when the address cannot be determined; send confirmIpAllowlistExcludesCaller: true to override the first, which is audited as organization.security_policy.ip_allowlist_lockout_confirmed. Turning requireMfa on while the caller (a member who is not platform staff) has not enabled MFA on their own account is refused with 400 mfa_lockout_risk (also on the legacy organization-mfa-policy route); confirmMfaLockout: true overrides it and is audited as organization.security_policy.mfa_lockout_confirmed. The allow-side audit rows (write_authorized and the confirmations) are written only after the change is saved; the legacy MFA route writes organization.mfa_policy.update. Writes are refused during a support-impersonation session and audited against the real actor. API key fields:

FieldDefaultRange
apiKeyMaxLifetimeDaysnone1 to 3650. Send clearApiKeyMaxLifetime: true to remove it (not together with a value).
allowNonExpiringApiKeystrue
allowApiKeySelfRotationfalse
apiKeySelfRotationGraceMinutes151 to 1440
apiKeyMaxChainLifetimeDays90up to 365

Changes are audited with the acting user.

Application self-rotation setting ​

GET and PUT /api/v1/admin/applications/{applicationId}/api-key-policy with { "selfRotation": "Inherit" | "Allow" | "Deny" }. An application can only narrow the organization policy: Allow is refused (and audited as denied) while the organization setting is off, and the organization's Deny always wins. Where a key could act on several applications (its lock, its allowlist, its environment), any Deny wins.

Self-rotation decision order ​

A key rotates itself only if all of these hold, checked in this order; the first failure is the reason returned:

  1. scope_missing: the key holds apikeys.rotate.self.
  2. policy_org: the organization allows self-rotation.
  3. policy_app: no application involved has Deny.
  4. chain_limit: the chain, counted from the first key's creation, is still inside apiKeyMaxChainLifetimeDays.

The replacement has the same scopes, binding, allowlists and expiry rule, and the old key keeps working for the grace period. Approvals and rotations of one key are serialized, so a key cannot be rotated twice at once.

Reading a key's own details ​

GET /api/v1/runtime/api-key/self, authenticated with the key itself, returns its prefix and name, organization, level, bound application, allowed applications, exact and legacy scopes, and expiry. It never returns the secret.

Two fields let a client discover what the key may do without guessing from its scopes (both are about the calling key only, never another key):

  • allowedEnvironmentKinds: array of canonical environment kind names (Development, Staging, Production), sorted. An empty array means the key is not restricted (every kind is allowed).

  • selfRotation: the self-rotation policy decision for this key right now, from the same service the rotate route uses.

    • allowed (boolean): true when POST /api/v1/runtime/api-key/self/rotate would pass the policy.
    • reasonCode (string): ok, scope_missing, policy_org, policy_app, chain_limit or workload_credential.
    • policySource (string or null): org or app when a policy switch caused the denial.
    • graceMinutes (integer or null): the longest overlap window the replaced key keeps working; null for a workload credential.
    • chainEndsAtUtc (timestamp or null): when the key's rotation chain stops being renewable by the key itself; null for a workload credential.

    allowed: true is a policy answer, not a guarantee: the rotate route can still refuse with 409 already_rotated, 403 creator_inactive or 429 rotation_too_soon (a key issued by a rotation less than 60 seconds ago). A client that does not recognise a reasonCode should treat rotation as unavailable. This GET is not audited; it only tells a key its own policy, which is accepted as low risk.

Key review fields ​

Key list entries include reviewRequiredAtUtc and reviewReason. They are set when the key's creator loses access: the key is suspended (creator removed, deleted or disabled) or narrowed to the scopes the creator can still grant (creator demoted). Restoring the creator never widens a key or reactivates a suspended one. The audit event is apikey.creator_access_lost. Machine-issued keys are exempt.

Leaked keys: GitHub secret scanning (#1002) ​

POST /api/v1/security/secret-scanning receives GitHub secret scanning partner alerts. It is off by default (GitHubSecretScanning:Enabled=false answers 404) and is switched on per lane after the owner has joined the program (email [email protected] with the details below).

Registration detailValue
Secret type nametenancyengine_api_key
Pattern\bte_[0-9a-f]{37}\b (a te_ prefix and 37 lowercase hex characters, 40 in all)
Endpointhttps://<lane api host>/api/v1/security/secret-scanning

What it does, in order: rate limit per client address (429 + Retry-After), body cap (413), then the ECDSA P-256 / SHA-256 signature over the raw body is checked against the keys GitHub publishes at GitHubSecretScanning:PublicKeysUrl (a missing, malformed, wrong or unknown-key signature is 401 and nothing else happens). Each token that is a live key is revoked, audited as apikey.secret_scanning.revoked (key id, level, GitHub's type and source, and the source URL without its query or fragment) and the key's creator and the organization admins get one message per request listing the keys. A key that is already revoked, an unknown token and a token that does not look like a key are ignored without an audit row or an email, so repeats are harmless. The response is { "processed", "revoked" }; a token is never logged, echoed, audited or emailed.

Not done: a checksum in the key format (the 40-character hex format is unchanged, so the pattern has no checksum to cut false positives; a mismatch is harmless because only a hash match revokes).

TenancyEngine platform documentation