folkwaysDocs
Realtime API

POST /v1/token

Exchange a publishable key for an anonymous, read-only token, for public apps without a backend.

Trades a publishable key for an anonymous, read-only token. The app then connects with that token like any other. JSON, not frames.

Request

HTTP
POST https://realtime.folkways.net/v1/token
Authorization: Bearer <publishable key>
Content-Type: application/json

{ "cap": [{ "topic": "scores/match-7", "ops": ["subscribe"] }], "ttl_secs": 600 }

Every field is optional; an empty body asks for the defaults.

FieldDefaultMeaning
capall of the key's rightsThe rights for this token. Each must fall within the key's, or Forbidden
ttl_secs600Lifetime in seconds, at most 900 and never past the key's own expiry
kind"anonymous"Anything else is Forbidden
subMust be left out: a publishable key never names a user

Response

200 OK
JSON
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…",
  "expires_at_ms": 1792000600000,
  "identity": null,
  "kind": "anonymous",
  "capabilities": [{ "topic": "scores/match-7", "ops": ["subscribe"] }]
}

To refresh before TokenExpiring, exchange the key again and send Reauth.

Errors

StatuserrorWhen
401AuthRequiredNo Authorization: Bearer header
401AuthInvalidMalformed, unknown, revoked or expired key, or a wrong secret
403SuspendedThe key is paused, or the segment is suspended
403Forbiddensub or a non-anonymous kind given; cap wider than the key; the segment doesn't allow anonymous connections
400InvalidArgumentThe body isn't a token request
429RateLimitedToo many failed attempts from this address in the last minute. retry_after_ms and Retry-After say how long to wait
503Unavailable, DrainingTry again shortly

Errors are JSON: { "code": 204, "error": "Suspended", "message": "api key paused" }.

CORS allows any origin: publishable keys are meant for browser apps. A paused or revoked key stops new exchanges within about 30 seconds, and connections using its tokens close within about a minute.

On this page