dazzling-truck-32153
08/31/2025, 7:02 PM# Generate LiveKit token
livekit_token = api.AccessToken(
api_key=os.getenv("LIVEKIT_API_KEY"),
api_secret=os.getenv("LIVEKIT_API_SECRET")
).with_identity(participant.identity).with_name(ctx.room.name).to_jwt()tall-airline-16756
08/31/2025, 7:02 PMtall-airline-16756
08/31/2025, 7:02 PMAccessToken using your LiveKit API key and secret, plus the participant’s identity.
2. Set up a VideoGrant that defines the room and what the participant can do (like joining, publishing, or subscribing).
3. Add that grant to your token with addGrant().
4. Generate the JWT by calling toJwt().
5. Send the token back to your client safely.
Here’s a quick example in Node.js to help you get started:
import { AccessToken, VideoGrant } from "livekit-server-sdk";
const API_KEY = process.env.LIVEKIT_API_KEY;
const API_SECRET = process.env.LIVEKIT_API_SECRET;
function createParticipantToken(identity, roomName) {
const at = new AccessToken(API_KEY, API_SECRET, {
identity: identity,
ttl: "15m", // Token expiry time
});
const grant = {
room: roomName,
roomJoin: true,
canPublish: true,
canPublishData: true,
canSubscribe: true,
};
at.addGrant(grant);
return at.toJwt();
}
Here are some key permissions you can tweak in the grant:
• `room`: The room the participant can enter.
• `roomJoin`: Set to true to allow joining.
• `canPublish`: Lets them share audio/video tracks.
• `canPublishData`: Lets them send data messages.
• `canSubscribe`: Lets them listen to others' tracks.
• `canUpdateOwnMetadata`: Lets them update their own metadata.
Remember, it’s best to generate tokens on your server to keep your API secret safe. If you’d like an example in another programming language or tailored to your specific needs, just let me know—I’m here to help!
Sources: app/api/token/route.ts | Authentication Examples | livekit/livekit_composite | DeepWiki | frontend/src/pages/api/token.tsdazzling-truck-32153
08/31/2025, 7:03 PMtall-airline-16756
08/31/2025, 7:03 PMlivekit-api package. Here’s a simple way to do it:
1. First, install the package:
pip install livekit-api
1. Make sure to set your environment variables for LIVEKIT_API_KEY and LIVEKIT_API_SECRET.
2. Then, generate the token like this:
from livekit import api
import os
# This will automatically use LIVEKIT_API_KEY and LIVEKIT_API_SECRET from your environment variables
token = (
api.AccessToken()
.with_identity("python-bot") # Set the participant’s identity
.with_name("Python Bot") # Set a friendly display name
.with_grants(
api.VideoGrants(
room_join=True, # Allow joining the room
room="my-room" # Specify which room
)
)
.to_jwt() # Generate the JWT token
)
print(token)
You can totally customize permissions using the VideoGrants class. For instance, if you want to disable publishing audio/video, you’d do this:
api.VideoGrants(
room_join=True,
room="my-room",
can_publish=False,
can_subscribe=True
)
If you have any questions or want examples tailored to your specific needs, just let me know—I’m here to help!
Sources: livekit-api/README.mddazzling-truck-32153
08/31/2025, 7:05 PMlivekit_token = api.AccessToken(
api_key=os.getenv("LIVEKIT_API_KEY"),
api_secret=os.getenv("LIVEKIT_API_SECRET")
).with_identity(participant.identity).with_name(ctx.room.name).with_grants(api.VideoGrants(room_join=True, room=ctx.room.name, can_publish=True)).to_jwt()tall-airline-16756
08/31/2025, 7:05 PMroom_join and can_publish.
Once you generate the token with to_jwt(), you can send it to the client for authentication. If you run into any hiccups or want to chat more about it, just let me know—I’m here to help!dazzling-truck-32153
08/31/2025, 7:09 PMtall-airline-16756
08/31/2025, 7:10 PMroom_join and the specific room name inside the VideoGrants.
• Double-check that the token is signed with the correct API secret.
• Also, verify the token hasn’t expired—expired tokens just won’t let you connect.
Take another look at your token generation code on the server to ensure all the needed permissions are included. If you want, I’m here to help you go through your token generation logic—just let me know!
Sources: CHANGELOG.md | Authentication | LiveKit Docs | Authentication | LiveKit Docs | Android quickstart | LiveKit Docsdazzling-truck-32153
08/31/2025, 7:11 PMtall-airline-16756
08/31/2025, 7:11 PMctx.room.name exactly matches the name of the room you want to join.
• Confirm that the room_join permission is set to True and that the room field is correctly set to ctx.room.name.
• Double-check that the API key and secret you’re using are valid and belong to the LiveKit project where your room lives.
• Also, make sure the token hasn’t expired when you’re trying to use it.
If you’ve gone through these and it’s still not working, just give me a shout and we’ll dig in together!