Secure realtime authentication for browser and mobile apps
Use client tokens for browser and mobile realtime connections.Client tokens are short-lived keys you create on your backend, then pass to your frontend for client.realtime.connect().
Never expose your permanent API key (sk-...) in client-side code. Use client tokens (ek_...) for all browser and mobile realtime sessions.
All options are optional. Without options, tokens use a 60-second TTL and are unrestricted.
Parameter
Type
Description
expiresIn
number
TTL in seconds (1–3600, default 60)
allowedModels
string[]
Restrict which models the key can access (max 20)
constraints
object
Operational limits (see below)
metadata
object
Custom key-value pairs to attach to the token
Constraints object:
{ "realtime": { "maxSessionDuration": 120 // max seconds per WebSocket session (min 10) }}
expiresIn vs maxSessionDuration — these control different things.
expiresIn sets how long the token can be used to start new connections. Once a realtime session is established, the token’s expiration does not terminate it.
maxSessionDuration caps how long an individual realtime session can remain active, regardless of token expiration.
Use both together for full control: e.g. a 5-minute token window with a 2-minute max per session.
Pass allowedModels to restrict which models a token can be used with. The bouncer verifies model permissions when the client connects — if the model isn’t in the allowed list, the connection is rejected.Tokens created without allowedModels are unrestricted and work with any model.