Handler for POST /livekit/token endpoint
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_id to the authenticated tenant's ID
- Issues the token only after metadata is verified/set
Arguments
- state - Shared application state containing LiveKit configuration
- request - 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
Request body
Example request
{
"participant_identity": "user-alice-456",
"participant_name": "Alice Smith",
"room_name": "conversation-room-123"
}Response
Token generated successfully. Room is created if it doesn't exist and metadata.auth_id is set.
Example response
{
"livekit_url": "ws://localhost:7880",
"participant_identity": "user-alice-456",
"room_name": "conversation-room-123",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Changes
Changed in 3 of the 13 revisions of this API.6
- ○
the endpoint scheme security
authwas added to the APIapi-security-added
- ○
the endpoint scheme security
bearer_authwas removed from the APIapi-security-removed
This revision also has 2 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ○
- ○
added the non-success response with the status
response-non-success-status-added
- ○
- ○
the endpoint scheme security
bearer_authwas added to the APIapi-security-added
- ○
the endpoint scheme security
authwas removed from the APIapi-security-removed
- ○
removed the non-success response with the status
response-non-success-status-removed
This revision also has 29 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ○