flaky-beard-91685
09/12/2025, 10:47 AMtall-airline-16756
09/12/2025, 10:47 AMtall-airline-16756
09/12/2025, 10:47 AMAccessToken
and VideoGrant
from the livekit-server-sdk
package.
import { AccessToken, VideoGrant } from 'livekit-server-sdk';
2. Initialize the Access Token: Next, create an AccessToken
using your LiveKit API key and secret.
const at = new AccessToken('api-key', 'secret-key', { identity: 'participant-identity' });
3. Define the Video Grant: Here, you specify the permissions and room details in a VideoGrant
object.
const videoGrant = { room: 'my-room', roomJoin: true, canPublish: true, canSubscribe: true };
4. Add the Video Grant: Then, attach the VideoGrant
to your access token using the addGrant()
method.
at.addGrant(videoGrant);
5. Generate the JWT Token: Finally, generate the signed JWT token by calling toJwt()
.
const token = await at.toJwt(); console.log('access token', token);
To bring it all together, here’s a complete example for you to try out:
import { AccessToken, VideoGrant } from 'livekit-server-sdk';
const roomName = 'name-of-room';
const participantName = 'user-name';
const at = new AccessToken('api-key', 'secret-key', { identity: participantName });
const videoGrant = { room: roomName, roomJoin: true, canPublish: true, canPublishData: true, canSubscribe: true };
at.addGrant(videoGrant);
const token = await at.toJwt();
console.log('access token', token);
If you have any questions or need a hand with any part of this, please don’t hesitate to ask. I’m here to help!
Sources: Docs::Home | Authentication | LiveKit Docs | packages/livekit-server-sdk/src/grants.test.ts