---
title: "Handler for POST /livekit/token endpoint"
method: POST
path: "/livekit/token"
tags: ["livekit"]
---

# Handler for POST /livekit/token endpoint

`POST /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:
1. Creates the room if it doesn't exist
2. Sets `room.metadata.auth_id` to the authenticated tenant's ID
3. 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

- TokenRequest — Request body for generating a LiveKit token # Example ```json { "room_name": "conversation-room-123", "participant_name": "Alice Smith", "participant_identity": "user-alice-456" } ```
  - `participant_identity` string, required — Unique identifier for the participant (e.g., "user-123")
  - `participant_name` string, required — Display name for the participant (e.g., "John Doe")
  - `room_name` string, required — The LiveKit room name to generate a token for

## Response `200`

Token generated successfully. Room is created if it doesn't exist and metadata.auth_id is set.

- TokenResponse — Response containing the generated LiveKit token # Example ```json { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "room_name": "conversation-room-123", "participant_identity": "user-alice-456", "livekit_url": "ws://localhost:7880" } ```
  - `livekit_url` string, required — The LiveKit server URL to connect to
  - `participant_identity` string, required — Echo back the participant identity for client confirmation
  - `room_name` string, required — Echo back the room name for client confirmation
  - `token` string, required — The generated JWT token for LiveKit

## Other responses

- `400` — Invalid request (missing or empty fields)
- `403` — Access denied: room exists with a different tenant's auth_id
- `500` — LiveKit service not configured, room creation failed, or token generation failed

## Changes

- **2026-02-08** `0df166d28191` — 2 info
  - the endpoint scheme security `auth` was added to the API
  - the endpoint scheme security `bearer_auth` was removed from the API
- **2026-01-07** `3a996c4eb1fc` — 1 info
  - added the non-success response with the status `403`
- **2025-11-12** `d85b83f25aea` — 3 info
  - the endpoint scheme security `bearer_auth` was added to the API
  - the endpoint scheme security `auth` was removed from the API
  - removed the non-success response with the status `403`

[Change history](https://skmtc.dev/saynaai/apis/sayna-api/changes/livekit/token/post.md)

---

[API](https://skmtc.dev/saynaai/apis/sayna-api.md) · [All operations](https://skmtc.dev/saynaai/apis/sayna-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/saynaai/sayna-api/revisions/395ce7e35139/schema)
