Skip to main content

Getting Started

Make sure to first set up your PlanetScale developer environment. Once you’ve installed the pscale CLI, you can interact with PlanetScale and manage your databases straight from the command line.

The service-token command

This command allows you to create, list, and manage access for service tokens. Usage:

Available sub-commands

Service token automation: service-token

Legend: 🚫 unavailable with a service token (all sub-commands). All service-token sub-commands are unavailable when authenticated with a service token. Exact error: pscale service-token <sub-command> is unavailable when authenticated with a service token. Do not retry the CLI. Use the alternatives below. Read operations (list, show-access): use pscale api with the same service token. Create and manage operations: run under pscale auth login; there is no service-token CLI path for those sub-commands. Setup and commands to avoid: CLI overview · Service tokens
* Flag is required

Sub-command flag descriptions

Some of the sub-commands have additional flags unique to the sub-command. This section covers what each of those does. See the above table for which context.

Available flags

Global flags

Examples

Adding service token access for a database

Command:
This will add the following permissions to the specified access token: read_branch, delete_branch, create_branch. The output will show the updated permissions on all databases. You can find a list of all permissions in the PlanetScale API documentation. Output:

Adding service token access for an organization

Command:
This will grant the service token the read_organization access on the organization. Output:

Show a service token

Create a service token with IP restrictions

--cidrs accepts IPv4 addresses and CIDR ranges, up to 10. A bare address is stored as a /32. Omit --cidrs to leave the token unrestricted. See IP restrictions.

Duplicate a service token

This creates a copy of the service token with a new name and prints the new token ID and value, the same as create. The copy keeps the original token’s permissions and IP restrictions. --ttl sets the copy’s time to live in seconds. The copy doesn’t take the original token’s expiration.

Update a service token’s name, expiry, or IP restrictions

Pass at least one of --name, --ttl, or --cidrs. A flag you leave out keeps its current value. --ttl sets a new time to live in seconds, and --ttl never removes the expiry. --cidrs replaces the allowed addresses, and --cidrs "" removes all restrictions. The token’s ID, value, and permissions don’t change.

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.