When genereting access token with livekit.api.Acce...
# ask-ai
f
When genereting access token with livekit.api.AccessToken, what kind of input parameters does with_ttl accepts?
t
Thanks for reaching out, muse. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
with_ttl
method in
livekit.api.AccessToken
accepts a single input parameter: • ttl (type:
datetime.timedelta
) - The time-to-live duration for the access token. Here is an example of how to use it:
Copy code
from livekit import api
import datetime

token = api.AccessToken() \
    .with_ttl(datetime.timedelta(hours=2)) \
    .with_identity("user-123") \
    .to_jwt()
The method returns the
AccessToken
instance, allowing for method chaining. If you don’t call
with_ttl
, the token will use the default TTL of 6 hours. Sources: README.md
f
Does it mean that if i join a room after 6 hours i am kicked out? Or does it mean that i can access the room at most in 6 hours and then stay how long i desire?
t
Hey there! Let me break this down in a friendly way. When it comes to LiveKit access tokens, think of them like a temporary pass that gets you into a room. The token's "time to live" (TTL) only matters when you're first trying to join - it's basically your initial entry ticket. Once you're in the room, no worries! You can totally stay as long as you want. Even if your original token expires, LiveKit's got your back - the server will automatically issue new tokens to keep you connected. So if you get disconnected, you'll seamlessly reconnect without any hassle. Just remember: the token is your entry pass, but once you're in, you're good to go! 😊 Sources: Authentication | LiveKit Docs | packages/livekit-server-sdk/README.md | livekit-api/livekit/api/access_token.py | livekit-api/src/access_token.rs