a
hi
t
Thanks for reaching out, Shashin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi — thanks for reaching out! How can I help you today? If you’re reporting an issue, please include: • a brief description of the problem, • any error messages or screenshots, • the SDK or platform you’re using (web, iOS, Android, server), • relevant room or session IDs (if applicable).
a
How to generate room token and use that token to participate in the room in oython
t
Thanks — I’ll show how to (1) generate a room token server-side with the LiveKit Python server SDK and (2) use that token client-side with the LiveKit Python client to join a room. Step 1 — Install SDKs 1. Install both packages:
Copy code
pip install livekit-api livekit
Step 2 — Generate a room token (server-side) 1. Use
livekit-api.AccessToken
to create a JWT. Keep
api_secret
only on the server.
Copy code
from livekit.api import AccessToken, VideoGrants

api_key = "your-api-key"
api_secret = "your-api-secret"
room_name = "my-room"
identity = "user-123"  # unique participant id

token = (
    AccessToken(api_key, api_secret)
    .with_identity(identity)
    .with_grants(
        VideoGrants(
            room_join=True,
            room=room_name,
            can_publish=True,
            can_subscribe=True,
            can_publish_data=True,
        )
    )
)

jwt_token = token.to_jwt()
print("Generated token:", jwt_token)
Send
jwt_token
securely to the client (e.g., via HTTPS endpoint). Step 3 — Join the room (client-side, Python) 1. Use the
livekit
client to connect with the token.
Copy code
from livekit import Room
import asyncio

async def main():
    room = Room()
    websocket_url = "<wss://your-livekit-instance.com>"  # replace with your LiveKit URL
    await room.connect(websocket_url, jwt_token)
    print("Connected to room:", room.name)

    # Optionally create and publish local tracks (camera/mic)
    # from livekit.room import RoomUtils
    # local_tracks = await RoomUtils.create_local_tracks(video=True, audio=True)
    # await room.local_participant.publish_track(local_tracks[0])  # video
    # await room.local_participant.publish_track(local_tracks[1])  # audio

    await asyncio.Event().wait()  # keep running

asyncio.run(main())
Notes and tips • Never expose
api_secret
to clients. Generate tokens server-side and return only the JWT. • Use unique
identity
per participant. • Adjust grant flags (
can_publish
,
can_subscribe
,
room
) to control permissions. • Replace
<wss://your-livekit-instance.com>
with your LiveKit server URL (cloud or self-hosted). If you want, tell me: • whether you’re using LiveKit Cloud or a self-hosted instance, and • whether the client is a desktop Python client or embedding this in a web app and I’ll give the exact connection URL and any small changes you’ll need. Sources: Python SDKs | livekit/livekit_composite | DeepWiki | An open source stack for real-time multimodal AI
a
cant i get link of the room created?
t
Good question — regarding a "link" to a room: LiveKit does not provide a built-in single sharable room URL that automatically includes permissions. Instead you create a shareable link yourself by embedding a generated token (JWT) or by directing users to a page that requests a token from your server. Two common approaches: • Share a client URL that fetches a token on load (recommended) ◦ Create a web page (e.g., https://example.com/room/my-room) that, when opened, calls your backend to get a server-generated token for that user and then connects to LiveKit using the token. This keeps your API secret safe and lets you control identities/permissions. • Share a direct link with a token (less secure) ◦ Generate a token server-side and append it to a client URL, e.g.: https://example.com/room/join?token=eyJhbGci... • The page reads
token
and calls LiveKit client connect with it. Only use for short-lived tokens and trusted recipients. If you want, tell me: • which platform you’re targeting (web, Python desktop, iOS, Android), and • whether you prefer the page-to-request-token model or an embedded-token link, and I’ll give a concrete example (server endpoint and client code) you can copy.
a
Does connecting through LiveKit Cloud’s WebSocket endpoint count against the 1,000 free minutes, and would the same usage be metered if LiveKit is self-hosted instead?
t
Thanks — good question. Here’s how usage is metered: • Connecting to LiveKit Cloud via the WebSocket endpoint does not consume the 1,000 free agent session minutes. • WebSocket/WebRTC participant connections are billed under WebRTC minutes (the Build plan includes 5,000 free WebRTC minutes), not the agent session minutes. • If you self‑host LiveKit there is no LiveKit metering or billing — you only pay your own infrastructure costs. If you want, tell me whether you're using LiveKit Cloud or planning to self‑host and I can help estimate which minute buckets your usage will fall into. Sources: LiveKit Pricing | Announcing LiveKit Cloud
a
The agent will be self hosted but if we use livekit wss url will it still deduct 1000 min or is that specifically only for agent cloud hosting
t
Thanks — good clarification. The 1,000 free agent minutes apply only when the agent is run on LiveKit Cloud (Agent Cloud). If you self‑host the agent but connect it to LiveKit Cloud via the LiveKit WSS endpoint: • Those connections will be counted as WebRTC minutes (or the appropriate Cloud usage bucket), not the 1,000 free agent session minutes. If you fully self‑host LiveKit (agent and server): • LiveKit does not meter or bill usage — you only pay your own infrastructure costs. If you’d like, tell me whether the agent will authenticate with Cloud using API keys/tokens or connect to a self‑hosted room, and I’ll confirm which Cloud usage bucket it will hit.
a
i will only use livekit credentials (url, secret, api) in .env file but wont be hosting in livekit cloud. Instead python and react will be hosted in self hosted server
t
Thanks — great clarification. To confirm: • If you self‑host your Python and React apps but use LiveKit Cloud’s URL/API key/secret (i.e., your apps connect to LiveKit Cloud WSS), that usage is metered by LiveKit Cloud as WebRTC (participant) minutes or whatever Cloud usage bucket applies — it will NOT consume the 1,000 free agent‑session minutes (those apply only when agents run on LiveKit Cloud). • If you fully self‑host LiveKit (agent + server + signaling), LiveKit does not meter or bill usage — you only pay your own infrastructure costs. So using credentials from .env on your self‑hosted apps and connecting to LiveKit Cloud counts as Cloud WebRTC usage, not the 1,000 free agent minutes. Do you want me to estimate expected WebRTC minutes for your workload or confirm which Cloud usage bucket your agent connections will hit?
a
yes
t
Thanks — I can estimate WebRTC minutes for you. To give an accurate estimate, please provide: • Expected number of participants per room (average). • Average session length per participant (minutes). • Expected rooms/sessions per day or per week. • Whether participants publish video, audio, or both (video uses more minutes). • Any simulcast/forwarding or recording usage (e.g., SFU forwarding, server-side recording). With those I’ll calculate estimated monthly WebRTC minutes and suggest how to optimize usage.