Skip to main content
Tokens

Create Token

Issue a scoped token. Use this to mint short-lived tokens that grant a client access to a single actor instead of sharing your namespace token.

Each grant names a resource type, a target ("any" or a specific { "id": ... }), and the operations it allows. A token carries 1 to 32 grants with 1 to 5 operations each. The RivetKit client wraps this as handle.issueToken().

POST https://rivet.example.com/auth/tokens

Examples

Authentication

Requires the admin token, sent as a bearer token in the Authorization header. Namespace tokens are rejected. See Authentication.

Request Body

Content type: application/json.

FieldTypeRequiredDescription
namespacestringYesNamespace the token is valid in. It must exist.
durationinteger | nullNoLifetime in seconds, from 1 to the deployment’s maximum. Omit for the default lifetime.
subjectstring | nullNoFree-form subject to attach to the token, such as a user ID. At most 256 UTF-8 bytes.
grantsobject[]YesPermissions the token carries.
grants[].resource"namespace" | "actor" | "node" | "pool" | "datacenter" | "actor_gateway" | "actor_kv"YesResource type the grant applies to.
grants[].target"any" | objectYes"any" for every resource of this type, or { "id": "..." } for one resource.
grants[].operations("read" | "update" | "list" | "create" | "delete")[]YesOperations the token may perform on the target.

Responses

200

The issued token. The response carries Cache-Control: no-store.

FieldTypeDescription
tokenstringThe issued token. Treat it as a secret.
issued_tsintegerWhen the token was issued, in Unix milliseconds.
expires_tsintegerWhen the token expires, in Unix milliseconds.
{
  "token": "eyJ...",
  "issued_ts": 1700000000000,
  "expires_ts": 1700000000000
}

400

validation.invalid_input: the subject exceeds 256 UTF-8 bytes, the duration is outside the allowed range, or the grant set is invalid (empty, more than 32 grants, a grant without operations or with more than 5, or a token, acl or jwt resource). envoy.invalid_namespace_name: the namespace value is not a DNS label of 1 to 63 lowercase letters, digits and hyphens.

FieldTypeDescription
groupstringError group, for example actor.
codestringError code within the group, for example not_found.
messagestringHuman-readable error message.
metadataanyExtra details. Only present on some errors raised while authenticating or authorizing the request.
{
  "group": "validation",
  "code": "invalid_input",
  "message": "subject exceeds 256 UTF-8 bytes"
}

401

auth.invalid_token: the request does not carry the admin token.

FieldTypeDescription
groupstringError group, for example actor.
codestringError code within the group, for example not_found.
messagestringHuman-readable error message.
metadataanyExtra details. Only present on some errors raised while authenticating or authorizing the request.
{
  "group": "auth",
  "code": "invalid_token",
  "message": "Authentication token is invalid."
}

403

auth.issuance_disabled: JWT issuance is not enabled for this deployment.

FieldTypeDescription
groupstringError group, for example actor.
codestringError code within the group, for example not_found.
messagestringHuman-readable error message.
metadataanyExtra details. Only present on some errors raised while authenticating or authorizing the request.
{
  "group": "auth",
  "code": "issuance_disabled",
  "message": "JWT issuance is not enabled for this deployment."
}

404

namespace.not_found: the namespace does not exist.

FieldTypeDescription
groupstringError group, for example actor.
codestringError code within the group, for example not_found.
messagestringHuman-readable error message.
metadataanyExtra details. Only present on some errors raised while authenticating or authorizing the request.
{
  "group": "namespace",
  "code": "not_found",
  "message": "The namespace does not exist."
}

415

The request is missing the Content-Type: application/json header. Returned as plain text.

Content type: text/plain.

422

The JSON body does not match the request schema, for example a missing required field, a wrong type or an unknown field where unknown fields are rejected. Returned as plain text.

Content type: text/plain.

500

core.internal_error: an unexpected failure, including a deployment without authentication configured.

FieldTypeDescription
groupstringError group, for example actor.
codestringError code within the group, for example not_found.
messagestringHuman-readable error message.
metadataanyExtra details. Only present on some errors raised while authenticating or authorizing the request.
{
  "group": "core",
  "code": "internal_error",
  "message": "An internal error occurred"
}

503

auth.issuance_unavailable: the signing service is temporarily unavailable. Retry the request.

FieldTypeDescription
groupstringError group, for example actor.
codestringError code within the group, for example not_found.
messagestringHuman-readable error message.
metadataanyExtra details. Only present on some errors raised while authenticating or authorizing the request.
{
  "group": "auth",
  "code": "issuance_unavailable",
  "message": "The server could not issue an authentication token because the signing service is temporarily unavailable. Retry the request."
}