CLI reference
Tokens CLI command reference
Create, inspect and manage tokens
npx sanity tokens --help
pnpm dlx sanity tokens --help
yarn dlx sanity tokens --help
bunx sanity tokens --help
Commands
create
USAGE
$ sanity tokens create [LABEL] [-p <id>] [--yes] [--expires-at 2027-01-01] [--json] [--role viewer]
ARGUMENTS
[LABEL] Label for the new token
FLAGS
-y, --yes Skip prompts and use defaults (unattended mode)
--expires-at=2027-01-01 Date or timestamp the token expires (ISO 8601; tokens never expire by default)
--json Output as JSON
--role=viewer Role to assign to the token (defaults to viewer in unattended mode)
OVERRIDE FLAGS
-p, --project-id=<id> Project ID to create token in (overrides CLI configuration)
DESCRIPTION
Create a new API token for the project
EXAMPLES
Create a token with a label
$ sanity tokens create "My API Token"
Create a token with editor role
$ sanity tokens create "My API Token" --role=editor
Create a token in unattended mode
$ sanity tokens create "CI Token" --role=editor --yes
Create a token that expires on a given date
$ sanity tokens create "Build Token" --expires-at 2027-01-01
Output token information as JSON
$ sanity tokens create "API Token" --json
Create a token for a specific project
$ sanity tokens create "My Token" --project-id abc123 --role=editordelete
USAGE
$ sanity tokens delete [TOKENID] [-p <id>] [--yes]
ARGUMENTS
[TOKENID] Token ID to delete (will prompt if not provided)
FLAGS
-y, --yes Skip confirmation prompt (unattended mode)
OVERRIDE FLAGS
-p, --project-id=<id> Project ID to delete token from (overrides CLI configuration)
DESCRIPTION
Delete an API token from the project
EXAMPLES
Interactively select and delete a token
$ sanity tokens delete
Delete a specific token by ID
$ sanity tokens delete silJ2lFmK6dONB
Delete a specific token without confirmation prompt
$ sanity tokens delete silJ2lFmK6dONB --yes
Delete a token from a specific project
$ sanity tokens delete --project-id abc123list
USAGE
$ sanity tokens list [-p <id>] [--json]
FLAGS
--json Output tokens in JSON format
OVERRIDE FLAGS
-p, --project-id=<id> Project ID to list tokens for (overrides CLI configuration)
DESCRIPTION
List API tokens for the project
EXAMPLES
List tokens for the project
$ sanity tokens list
List tokens in JSON format
$ sanity tokens list --json
List tokens for a specific project
$ sanity tokens list --project-id abc123rotate
USAGE
$ sanity tokens rotate [-t <token>] [--json]
FLAGS
-t, --token=<token> Token to rotate (prefer standard input to keep it out of shell history)
--json Output as JSON
DESCRIPTION
Rotate an API token, replacing its secret with a new one
EXAMPLES
Rotate the token piped on standard input
$ echo "$SANITY_TOKEN" | sanity tokens rotate
Rotate a token read from a file
$ sanity tokens rotate < token.txt
Output the rotated token as JSON
$ echo "$SANITY_TOKEN" | sanity tokens rotate --json