able-jackal-84140
10/02/2025, 7:06 PMtall-airline-16756
10/02/2025, 7:06 PMtall-airline-16756
10/02/2025, 7:06 PMable-jackal-84140
10/02/2025, 7:08 PMtall-airline-16756
10/02/2025, 7:09 PMcreate_sip_participant method. Just a heads-up, this requires having an outbound SIP trunk set up in LiveKit. If you'd like, I’m happy to walk you through the detailed steps for this!
• Standard Participants: For web or mobile users, the way to go is generating a join token on your server, which the client then uses to connect to the room. This is the best way to add standard participants programmatically.
Could you let me know which type of participant you’re aiming to add? Also, if you want, I’m here to help with token generation or setting up SIP configuration—just say the word!
Sources: livekit-agents/livekit/agents/job.py | Docs::Telephony | README.md | telephony/sip_lifecycle.pyable-jackal-84140
10/02/2025, 7:09 PMtall-airline-16756
10/02/2025, 7:10 PMLIVEKIT_API_KEY and LIVEKIT_API_SECRET set up in your environment or directly in your code.
2. Initialize the AccessToken: Create a token object using the api.AccessToken class.
3. Set Participant Identity: Use .with_identity(identity) to give your participant a unique identifier.
4. Define Permissions: Specify what the participant can do, like joining a room, publishing, and subscribing, using api.VideoGrants.
5. Set Token Expiration: Optionally, you can decide how long the token should last with .with_ttl().
6. Generate the Token: Finally, call .to_jwt() to create your token.
Here’s a simple example to guide you:
from livekit import api
import datetime
def generate_token(room_name, identity):
token = (
api.AccessToken("your-api-key", "your-api-secret")
.with_identity(identity)
.with_grants(
api.VideoGrants(
room_join=True,
room=room_name,
can_publish=True,
can_subscribe=True
)
)
.with_ttl(datetime.timedelta(minutes=15))
.to_jwt()
)
return token
print(generate_token("my-room", "user-123"))
If you have any questions or need a hand with any part of this, just let me know—I’m here to help!
Sources: Authentication | LiveKit Docs | Docs::Agents | Generating tokens | LiveKit Docs | auth.py | livekit-api/livekit/api/access_token.pyable-jackal-84140
10/02/2025, 7:12 PMtall-airline-16756
10/02/2025, 7:13 PMrtc.Room() to create your room object.
3. Connect to the Room: Call the connect() method with your LiveKit server’s WebSocket URL and the token you generated.
4. Handle Events: It’s helpful to set up event listeners for connection events like connected and disconnected to stay informed about the connection status.
Here’s a friendly example to illustrate:
import asyncio
from livekit import rtc
async def connect_to_room():
room = rtc.Room()
@room.on("connected")
def on_connected():
print("Connected to the room!")
@room.on("disconnected")
def on_disconnected(reason):
print(f"Disconnected: {reason}")
token = "your-generated-token"
url = "wss://your-livekit-server-url"
try:
await room.connect(url, token)
except rtc.ConnectError as e:
print(f"Failed to connect: {e}")
asyncio.run(connect_to_room())
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: examples/agent_dispatch.py | Connecting to LiveKit | LiveKit Docs | Authentication | LiveKit Docs | Generating tokens | LiveKit Docs