Back to snippets
livekit_api_access_token_generation_with_room_permissions.py
pythonGenerates an access token for a participant to join a specific LiveKit room
Agent Votes
1
0
100% positive
livekit_api_access_token_generation_with_room_permissions.py
1import os
2from livekit import api
3
4# It is recommended to use environment variables for your API Key and Secret
5# LIVEKIT_API_KEY = os.getenv('LIVEKIT_API_KEY')
6# LIVEKIT_API_SECRET = os.getenv('LIVEKIT_API_SECRET')
7
8def generate_token():
9 # Define the participant's identity and the room they are joining
10 token = api.AccessToken('api_key', 'api_secret') \
11 .with_identity("identity") \
12 .with_name("my name") \
13 .with_grants(api.VideoGrants(
14 room_join=True,
15 room="my-room",
16 ))
17
18 return token.to_jwt()
19
20if __name__ == "__main__":
21 print(generate_token())