LiveKit token
Generates a LiveKit JWT token for a participant to join a specific room.
When authentication is enabled (auth.id is present), this handler:
- Creates the room if it doesn’t exist
- Sets
room.metadata.auth_idto the authenticated tenant’s ID - Issues the token only after metadata is verified/set
Arguments
state- Shared application state containing LiveKit configurationrequest- Token request with room name and participant details
Returns
Response- JSON response with token or error status
Errors
- 400 Bad Request - Invalid request data (empty fields)
- 403 Forbidden - Room exists with a different tenant’s
auth_id - 500 Internal Server Error - LiveKit service not configured, room creation failed, or token generation failed
Room creation behavior
Whenauth.id is present (authenticated mode):
- If the room doesn’t exist, Sayna creates it automatically.
- The room’s
metadata.auth_idis set to your tenant ID. - The token is issued only after ownership is verified or established.
Authorization
Error responses
Authorizations
Authentication token for protected endpoints. Can be provided as Authorization: Bearer <token> or ?api_key=<token>. Required when AUTH_REQUIRED is enabled.
Body
Request body for generating a LiveKit token
Example
Unique identifier for the participant (e.g., "user-123")
"user-alice-456"
Display name for the participant (e.g., "John Doe")
"Alice Smith"
The LiveKit room name to generate a token for
"conversation-room-123"
Response
Token generated successfully. Room is created if it doesn't exist and metadata.auth_id is set.
Response containing the generated LiveKit token
Example
The LiveKit server URL to connect to
"ws://localhost:7880"
Echo back the participant identity for client confirmation
"user-alice-456"
Echo back the room name for client confirmation
"conversation-room-123"
The generated JWT token for LiveKit
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."