Skip to main content
POST
Creates a session token, a short-lived credential that a browser sends instead of an API key. This endpoint requires an API key, and each successful call costs one credit. Session tokens describes how a backend and a browser use it.

Request body

  • origins lists 1 to 10 origins allowed to use the token, each in the format of the browser’s Origin header, such as https://app.example.com.
  • subject is an optional label for the user, such as a user ID, of 1 to 128 characters without control characters.
  • ttlSeconds is the token’s lifetime, from 60 to 3,600 seconds. The default is 900.

Response

token is an opaque string of a few hundred characters that starts with metasession_. Treat it as a secret, and do not parse it. expiresAt is the expiry time in Unix milliseconds. Tokens cannot be refreshed, so create a new token before expiresAt.

Errors

Authorizations

Authorization
string
header
required

Send an API key, or a session token a key minted, as Authorization: Bearer <credential>. A browser opening /v1/stream offers its session token in Sec-WebSocket-Protocol instead.

Body

application/json

The body of POST /v1/session-tokens.

origins
string[]
required

The origins the token may be presented from, 1 to 10, each as a browser sends Origin.

Required array length: 1 - 10 elements
Example:
subject
string | null

Who the token is for, in the caller's own terms: at most 128 characters, no control characters.

Maximum string length: 128
Example:

"user-42"

ttlSeconds
integer<int32> | null

How long the token lives, 60 to 3600 seconds; 900 when absent.

Required range: 60 <= x <= 3600
Example:

900

Response

The token, and when it expires. Present it as Authorization: Bearer <token>, or on the stream handshake in Sec-WebSocket-Protocol beside metastreams.v1, from one of its origins.

A session token as the mint answers it.

expiresAt
integer<int64>
required

When it stops authenticating.

token
string
required

The token, presented as Authorization: Bearer <token>, or on the stream handshake in Sec-WebSocket-Protocol.