POST /v1/cli/device/start) requires an Authorization header with a Bearer token:
CLI access token
CLI access tokens are issued by the device code flow when you runbarekey auth login. They are the standard way to authenticate server-side integrations, CI/CD pipelines, and SDK usage.
Format: bk_at_ prefix followed by a base64url-encoded random string.
TTL: 1 hour. Refresh using POST /v1/cli/token/refresh with a refresh token (bk_rt_...).
Example:
Storing CLI tokens
In CI/CD environments, store the access token as a secret in your CI provider (GitHub Actions secrets, Vercel environment variables, etc.). Reference it as an environment variable in your application:Token refresh
When the 1-hour access token expires, use the refresh token to get a new pair:Clerk JWT
Clerk JWTs are used by the web dashboard and by server-side applications that already have Clerk sessions. The JWT must carry an active org claim — a Clerk session without an active org cannot access the API. Example:Org scoping
The org scope is determined by the token, not by request body parameters.- For CLI tokens: the org is fixed at session creation time (when you ran
barekey auth login --org <slug>). - For Clerk JWTs: the org is the active org in the Clerk session.
orgSlug in the request body must match the org from the token. If it doesn’t, the request returns 403 ORG_SCOPE_INVALID. You cannot use a token issued for org A to access org B’s variables by changing orgSlug in the request body.
Token priority
If a request provides both a Clerk JWT and a CLI access token (e.g. in a misconfigured client), Barekey processes the Clerk JWT first. The CLI access token is only evaluated if no valid Clerk identity is found.Errors
| Scenario | Code | HTTP |
|---|---|---|
Missing or malformed Authorization header | UNAUTHORIZED | 401 |
| Token not found or expired | UNAUTHORIZED | 401 |
| Session revoked | UNAUTHORIZED | 401 |
Token org doesn’t match request orgSlug | INVALID_ORG_SCOPE | 403 |
| User removed from org since token was issued | ORG_SCOPE_INVALID | 403 |

