Token format reference
This page describes the structure of Ory Talos API keys, imported keys, and derived tokens, and how Ory Talos routes a submitted credential to the correct verification path.
API key format
Generated API keys use a versioned format:
<prefix>_v1_<identifier>_<checksum>
Example:
prod_v1_QixobFgVufjZNuoYXKtn78NAqFVroyN518nRaK3WD3nxTNufzwJq9sjdrDMrcyP2_3wyBJBd2KxqXK117oqGWZzJU85Nv7C9vKWj9nVSqbEby
Components
| Component | Length | Description |
|---|---|---|
prefix | 1-16 chars | User-defined label (for example, prod, dev, test). Set via credentials.api_keys.prefix.current in config. |
v1 | 2 chars | Format version identifier |
identifier | ~64 chars | Base58-encoded timestamp:uuid payload |
checksum | ~44 chars | Full 32-byte HMAC-SHA256 over prefix_v1_identifier_, Base58-encoded |
Identifier encoding
The identifier is the Base58 encoding of timestamp:uuid:
- Timestamp: Unix epoch seconds (int64), set at key creation time.
- UUID: UUID v4 (36 chars with hyphens). Used as the
key_idfor database lookup.
Base58 uses the Bitcoin alphabet (123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz), which omits the visually
ambiguous characters 0, O, I, and l.
Checksum verification
The checksum is computed over the payload prefix_v1_identifier_:
- Compute HMAC-SHA256 with the current HMAC secret (
secrets.hmac.current). - Base58-encode the full 32-byte digest (no truncation).
During verification, Ory Talos tries all configured secrets in order, current (secrets.hmac.current) first, then retired
(secrets.hmac.retired). This supports secret rotation without invalidating existing keys.
Credential routing
When a credential is submitted for verification, Ory Talos checks its format in this order and stops at the first match:
| Order | Format match | Credential type | Lookup method |
|---|---|---|---|
| 1 | JWT format (eyJ...) | Derived JWT | Claims extracted during verification |
| 2 | Token starts with a configured macaroon prefix followed by _v1_ (credentials.derived_tokens.macaroon.prefix.current or retired) | Derived macaroon | Identifier extracted during verification |
| 3 | <prefix>_v1_<id>_<checksum> matches the API key shape | Generated API key | UUID extracted from identifier |
| 4 | None of the above | Imported key | SHA-512/256 hash with tenant scope |
Macaroons share the <prefix>_v1_... shape with generated API keys; routing distinguishes them by checking the configured
macaroon-prefix list before falling through to the API key regex.
Imported key format
Imported keys have no format requirements: any string credential can be imported. Ory Talos stores a tenant-scoped hash instead of the raw key:
SHA-512/256(network_id + 0x00 + raw_key)
The null-byte separator prevents ambiguity between the network ID and the key content. Including the network ID in the hash input makes the same raw key resolve to a different hash in each tenant.
Derived token formats
JWT
Derived tokens produced as JWTs follow the standard JWT format:
eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.signature
The sub claim holds the parent key's ID. Other claims include act (actor ID), scp (scopes), and exp (expiration). When the
parent key has a rate limit policy, rl carries it as {"q": <quota>, "w": <window in seconds>}; a token whose rl lacks either
field, or sets a quota below 1 or a window below 1 second, fails verification. The signing algorithm follows the JWK key type:
Ed25519 keys produce EdDSA signatures, RSA keys produce RS256. The alg header on the issued JWT reflects this choice.
Signing key selection (kid hint)
Ory Talos resolves the active signing key on every derive request. The kid header in the issued JWT identifies which JWK from
the configured JWKS produced the signature.
Resolution order:
- If
credentials.derived_tokens.jwt.signing_key_idis set, Ory Talos selects the JWK whosekidmatches. If no JWK has thatkid, signing fails withInternalError, and the error details include the requestedsigning_key_id. - Otherwise, Ory Talos selects the first key with
"use": "sig". - Otherwise, Ory Talos selects the first key in the JWKS.
Set signing_key_id explicitly in production so that rotating signing material is a config change rather than a side effect of
JWKS ordering. In multi-tenant deployments, the JWKS resolves per tenant through the contextualizer, so the kid hint is also
per-tenant.
Macaroon
Macaroon tokens use a configurable prefix:
<prefix>_v1_<base64url_data>
Set the prefix with credentials.derived_tokens.macaroon.prefix.current (default: mc, 1-8 alphanumeric characters or
underscores). The data section is the base64url-encoded binary macaroon: its identifier, location, one or more JSON caveats, and
the signature.
Caveats
The first caveat holds the claims Ory Talos Secure API Keys sealed in at derive time. The holder can append further first-party
caveats offline with a compatible macaroon library. POST /v2alpha1/admin/apiKeys:verify applies every caveat in order, and a
caveat can only narrow authority. Each caveat is a JSON object that must repeat the token's iss value. The supported fields are:
| Field | Effect of a caveat |
|---|---|
scp (or scope) | Intersected with the current scopes; on a scoped token the result must not be empty. |
aud | Intersected with the current audience; rejected on a token that names none. |
exp | Applied only if it is earlier than the current expiry. |
nbf | Applied only if it is later than the current "not before" time. |
acl | Intersected with the current CIDR allowlist. |
meta | Asserted against the current metadata, which is never changed. |
| Custom claims | Asserted against the token's custom claims, which are never changed. |
Where an acl caveat's block and the token's block overlap, the more specific block wins, so a caveat can never hand back an
address the token had given up. An acl caveat on a token that carries no allowlist makes the caveat's CIDRs the effective
allowlist. An acl caveat that lists no CIDRs, or whose CIDRs don't overlap the token's allowlist, is rejected — an empty
allowlist means "any address", so narrowing to nothing would widen the token instead of denying it.
Blocks are matched by the network they cover, not by their spelling: an IPv4-mapped IPv6 block is the IPv4 network it denotes, so
::ffff:10.0.0.0/104 and 10.0.0.0/8 are one block and admit the same addresses. A mapped block shorter than /96 covers IPv6
addresses instead. IPv4 and IPv6 blocks never overlap, so a caveat that lists only one family is rejected on a token whose
allowlist carries only the other.
An aud caveat narrows the recipients the token is accepted for. It is rejected if it lists no recipients, contains an empty
value, or has no recipient in common with the token. A caveat also cannot bind a token that names no audience: adding or removing
all recipients would make the token valid in a verification context its issuer did not authorize.
An scp caveat drops scopes the token holds. On a token that carries scopes, a caveat that lists none, or whose scopes do not
overlap the token's, is rejected. A token derived from a key that has no scopes carries none, and an scp caveat leaves it that
way.
Metadata and custom claims are immutable once the token is signed. A caveat may restate an entry to assert it, but entries the caveat omits stay in place, and a caveat that adds, changes, or nulls out either map is rejected. Removal is not a narrowing here: verification resolves a collision between metadata and a custom claim of the same name in favor of the metadata, so dropping the metadata entry would promote the value it masked. Nested objects and arrays must match completely — a caveat cannot drop one property of a nested object.
exp and nbf must be real times. A token with no expiry never expires, so a caveat that encodes the zero time (Unix second
-62135596800) is rejected rather than read as an expiry earlier than the token's own.
The claims sub, nid, jti, akid, pid, act, iat, tty, and vis identify the token and cannot be changed. The rate
limit rl cannot be changed either, not even lowered: the token draws from its parent key's counter, which one policy governs. A
caveat that sets any of them to a different value is rejected, as is a caveat that omits iss or carries a different issuer. A
caveat that spells scopes both ways in one object is also rejected, because only one of the two lists could take effect.
Third-party caveats require a separate proof token, called a discharge macaroon, from another service to confirm that a condition
has been met. Ory Talos Secure API Keys does not support this flow: POST /v2alpha1/admin/apiKeys:verify rejects third-party
caveats and does not accept discharge macaroons.
ID formats
| Context | Format | Length | Example |
|---|---|---|---|
| Database storage | UUID v4 string | 36 chars | 550e8400-e29b-41d4-a716-446655440000 |
| API key identifier | Base58-encoded | ~64 chars | QixobFgVufjZNuoYXKtn78NAqFVroyN518nRaK3WD3nxTNufzwJq9sjdrDMrcyP2 |
| Imported key hash | Hex-encoded SHA-512/256 | 64 chars | a1b2c3d4... |
