dry-rainbow-66344
08/31/2025, 11:47 AMtall-airline-16756
08/31/2025, 11:47 AMtall-airline-16756
08/31/2025, 11:48 AMentrypoint function that connects your agent to the room. Here’s a quick example in Python:
async def entrypoint(ctx: agents.JobContext):
await ctx.connect()
# Add your custom agent logic here
1. Configure the Worker: Next, register your agent with the LiveKit server using WorkerOptions. Here’s how you can do it in Python:
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
1. Authentication and Tokens: You’ll need to generate a JWT token with these grants to keep things secure:
• agent: true or kind: "agent"
• roomJoin: true
• Room name
• API key and secret from your environment variables
token = (
api.AccessToken()
.with_identity("agent_identity")
.with_kind("agent")
.with_grants(api.VideoGrants(room_join=True, room=room_name, agent=True))
.to_jwt()
)
1. Dispatch the Agent: Finally, you can either let the worker join every new room automatically or explicitly dispatch it using AgentDispatchClient. Here’s an example in Python:
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(agent_name="test-agent", room=room_name)
)
Just a quick reminder to double-check that your environment variables (LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET) are set up correctly. If you hit any bumps or have questions, feel free to reach out—I’m here to help!
Sources: agent/main.py | OpenAI and LiveKit partner to turn Advanced Voice into an API | livekit-agents/livekit/agents/jupyter.py | examples/agent-dispatch/index.ts | examples/agent_dispatch.pydry-rainbow-66344
08/31/2025, 11:48 AMtall-airline-16756
08/31/2025, 11:49 AMconst room = new Room();
await room.connect(wsUrl, token);
const roomSid = await room.getSid();
console.log('Room SID:', roomSid);
• Python:
room = Room()
await room.connect(url, token)
room_sid = await room.sid
print(f"Room SID: {room_sid}")
• Server API: You can also check out active rooms and their SIDs using the LiveKit Server API. Here’s an example in Python:
from livekit import api
lkapi = api.LiveKitAPI()
rooms = await lkapi.room.list_rooms()
for room in rooms.rooms:
print(f"Name: {room.name}, SID: {room.sid}")
If you want a hand with retrieving the room ID or getting your setup just right, feel free to ask—I’m here to help!
Sources: Connecting to LiveKit | LiveKit Docs | Connecting to LiveKit | LiveKit Docs | src/room/Room.ts | livekit-rtc/livekit/rtc/room.py | Sources/LiveKit/Core/Room.swiftdry-rainbow-66344
08/31/2025, 11:54 AMtall-airline-16756
08/31/2025, 11:54 AMlkapi isn’t actually something you import directly from the livekit module. Instead, lkapi is usually just a variable name for an instance of the LiveKitAPI class. No worries though — here’s a simple way to fix it:
1. First, make sure you have the right package installed:
pip install livekit-api
1. Then, use the correct import and set it up like this:
from livekit import api
lkapi = api.LiveKitAPI(
url="https://your-project.livekit.cloud",
api_key="your-api-key",
api_secret="your-api-secret"
)
# For example, to create a room:
room_info = await lkapi.room.create_room(api.CreateRoomRequest(name="my-room"))
print(room_info)
await lkapi.aclose()
1. Optional tip: Use environment variables to keep things neat:
export LIVEKIT_API_KEY="your-api-key"
export LIVEKIT_API_SECRET="your-secret"
export LIVEKIT_URL="https://your-project.livekit.cloud"
lkapi = api.LiveKitAPI() # This will automatically pick up those environment variables
Just a heads-up: don’t try importing lkapi directly since it’s not part of the module itself. If you get stuck or want me to walk you through anything else, just give me a shout — I’m happy to help!
Sources: examples/agent_dispatch.py | Still Have Questions