Trade a CLI sign-in code for a token

Markdown version

POST/cli/token

Step 4 of `bsbot login`: the one-time code that /cli/authorize handed to the CLI's loopback address, with the PKCE verifier and the same redirect URI. A code works once and for two minutes; a failed attempt burns it. The token is valid 30 days. Rate limited per IP (`cliToken`).

Request body: CliTokenRequest

Responses

StatusDescriptionBody
200A token for the `/me/*` endpoints.CliToken
400Malformed body (`bad_request`), or a code that is unknown, expired, already used, or does not match the verifier or the redirect URI (`invalid_grant`).Error
404Not found. Also returned on a bot's handle subdomain: the API is only served on the main site.Error
429Rate limited (policy `publicApi`, per IP).Error
500Unexpected error.Error

Example

bash
curl \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"code":"…","code_verifier":"…","redirect_uri":"…"}' \
  https://bluesky.bot/api/v1/cli/token

Schemas

Error

FieldTypeDescription
error (required)object
error.code (required)string: "bad_request", "invalid_handle", "not_found", "rate_limited", "internal_error", "unauthorized", "forbidden", "conflict", "invalid_grant", "upstream_error", "insufficient_scope", "invalid_listing", "consent_required"
error.message (required)string
error.reasonstringWith `invalid_handle`, `invalid_listing`, `conflict` and `forbidden`: e.g. `reserved`, `taken`, `too_long`, `no_handle`, `suspended`.
error.urlstring, uriWith consent_required: open this dashboard page to grant profile editing.
error.fieldstringWith `invalid_listing`: the refused field.
error.scopestringWith `insufficient_scope`: the scope the token lacks.
error.parameterstringThe invalid query parameter.
error.retryAfterSecondsinteger (1–)With `rate_limited`.

CliTokenRequest

FieldTypeDescription
code (required)string
code_verifier (required)stringThe PKCE verifier (RFC 7636).
redirect_uri (required)stringThe same `http://127.0.0.1:<port>/callback` as on /cli/authorize.

CliToken

FieldTypeDescription
token (required)stringKeep it secret: it acts as you on `/me/*`.
tokenType (required)string = "Bearer"
expiresAt (required)string, date-time
creator (required)Account

Account

FieldTypeDescription
did (required)string
handle (required)stringYour Bluesky handle.
displayNamestring | null