Trade a CLI sign-in code for a token
Markdown versionPOST/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
| Status | Description | Body |
|---|---|---|
| 200 | A token for the `/me/*` endpoints. | CliToken |
| 400 | Malformed 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 |
| 404 | Not found. Also returned on a bot's handle subdomain: the API is only served on the main site. | Error |
| 429 | Rate limited (policy `publicApi`, per IP). | Error |
| 500 | Unexpected error. | Error |
Example
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"code":"…","code_verifier":"…","redirect_uri":"…"}' \
https://bluesky.bot/api/v1/cli/tokenSchemas
Error
| Field | Type | Description |
|---|---|---|
| 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.reason | string | With `invalid_handle`, `invalid_listing`, `conflict` and `forbidden`: e.g. `reserved`, `taken`, `too_long`, `no_handle`, `suspended`. |
| error.url | string, uri | With consent_required: open this dashboard page to grant profile editing. |
| error.field | string | With `invalid_listing`: the refused field. |
| error.scope | string | With `insufficient_scope`: the scope the token lacks. |
| error.parameter | string | The invalid query parameter. |
| error.retryAfterSeconds | integer (1–) | With `rate_limited`. |
CliTokenRequest
| Field | Type | Description |
|---|---|---|
| code (required) | string | |
| code_verifier (required) | string | The PKCE verifier (RFC 7636). |
| redirect_uri (required) | string | The same `http://127.0.0.1:<port>/callback` as on /cli/authorize. |
CliToken
| Field | Type | Description |
|---|---|---|
| token (required) | string | Keep it secret: it acts as you on `/me/*`. |
| tokenType (required) | string = "Bearer" | |
| expiresAt (required) | string, date-time | |
| creator (required) | Account |
Account
| Field | Type | Description |
|---|---|---|
| did (required) | string | |
| handle (required) | string | Your Bluesky handle. |
| displayName | string | null |