Skip to content
Latchkey

pscale "not authenticated" (PLANETSCALE_SERVICE_TOKEN) in CI

pscale defaults to a browser OAuth login that CI cannot complete. For automation it authenticates with a service token: an id and a secret, plus the org name. Missing any of the three makes it report that you are not authenticated.

What this error means

A pscale command fails with "not authenticated" or "Error: no access token" in the workflow, even though the same command works after pscale auth login locally.

pscale
Error: not authenticated. Please run `pscale auth login` or set a service token
with --service-token and --service-token-id.

Common causes

No service token in CI

The CLI cannot run the interactive login in a headless job and no PLANETSCALE_SERVICE_TOKEN was provided, so it has no credentials.

Token id, secret, or org is missing

Service-token auth needs the token id, the token secret, and the organization. Omitting any one causes the CLI to reject the request.

How to fix it

Pass the service token and org

  1. Create a service token in the PlanetScale org settings with the needed database access.
  2. Store the id and secret as CI secrets.
  3. Pass all three (id, token, org) to each pscale command.
Terminal
pscale database list \
  --org "$PLANETSCALE_ORG" \
  --service-token-id "$PLANETSCALE_SERVICE_TOKEN_ID" \
  --service-token "$PLANETSCALE_SERVICE_TOKEN"

Set them as environment variables

pscale reads the token id, token, and org from env vars, so set them at job level to avoid repeating flags.

.github/workflows/ci.yml
env:
  PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }}
  PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}
  PLANETSCALE_ORG: my-org

How to prevent it

  • Use a scoped service token for CI, never a personal browser login.
  • Set token id, token secret, and org together at the job level.
  • Grant the token only the databases and actions the workflow needs.

Frequently asked questions

What causes "pscale "not authenticated""?
The CLI cannot run the interactive login in a headless job and no PLANETSCALE_SERVICE_TOKEN was provided, so it has no credentials.
How do I fix pscale "not authenticated"?
Pass the service token and org

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card