hello, can i change the room name?
# ask-ai
h
hello, can i change the room name?
t
Thanks for reaching out, Ju. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Just a heads-up: once a room name is set in LiveKit, it can’t be changed later on. The name you choose during creation sticks with the room for its entire lifetime. If you have any other questions or need a hand with something else, don’t hesitate to reach out—I’m here to help! Sources: packages/livekit-server-sdk/src/RoomServiceClient.ts | livekit-ffi/protocol/room.proto
h
where do i choose the room name? from dotenv import load_dotenv from livekit import agents from livekit.agents import AgentSession, Agent, RoomInputOptions from livekit.plugins import ( openai, noise_cancellation, ) load_dotenv() class Assistant(Agent): def __init__(self) -> None: super().__init__(instructions="You are a helpful voice AI assistant. Always respond in English only, regardless of the language the user speaks in.") async def entrypoint(ctx: agents.JobContext): session = AgentSession( llm=openai.realtime.RealtimeModel( voice="ash" ) ) await session.start( room=ctx.room, agent=Assistant(), room_input_options=RoomInputOptions( # LiveKit Cloud enhanced noise cancellation noise_cancellation=noise_cancellation.BVC(), ), ) # JSON transcript with per-message timestamps import os, json, tempfile from livekit.agents import ConversationItemAddedEvent from datetime import datetime, timezone session_start_ts = datetime.now(timezone.utc) file_stamp = session_start_ts.strftime("%Y%m%d_%H%M%S") os.makedirs("transcripts", exist_ok=True) transcript_file = f"transcripts/conversation_{file_stamp}_{ctx.room.name}.json" # In-memory list of message dicts conversation = [] def write_json_atomic(data): """Write JSON atomically to avoid partial writes on crash.""" # Write to a temp file in same directory then replace dir_name = os.path.dirname(transcript_file) fd, tmp_path = tempfile.mkstemp(dir=dir_name, prefix="._partial_", suffix=".json") try: with os.fdopen(fd, "w", encoding="utf-8") as tmp_f: json.dump(data, tmp_f, ensure_ascii=False, indent=2) os.replace(tmp_path, transcript_file) except Exception: # Best-effort cleanup if something goes wrong try: os.unlink(tmp_path) except OSError: pass @session.on("conversation_item_added") def on_conversation_item_added(event: ConversationItemAddedEvent): # Capture message with timestamp (UTC ISO 8601) now = datetime.now(timezone.utc) conversation.append({ "timestamp": now.isoformat().replace("+00:00", "Z"), "relative_seconds": (now - session_start_ts).total_seconds(), "role": event.item.role, "text": event.item.text_content, "interrupted": event.item.interrupted, "id": getattr(event.item, "id", None), }) write_json_atomic({ "room": ctx.room.name, "session_started": session_start_ts.isoformat().replace("+00:00", "Z"), "messages": conversation, }) async def finalize_transcript(): # Ensure final flush (already written incrementally, but keeps structure consistent) write_json_atomic({ "room": ctx.room.name, "session_started": session_start_ts.isoformat().replace("+00:00", "Z"), "messages": conversation, }) ctx.add_shutdown_callback(finalize_transcript) await session.generate_reply( instructions="Greet the user and offer your assistance in English." ) if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
t
Hey there! To set a room name in LiveKit, all you need to do is specify the
name
parameter when you create the room. You do this with the
CreateRoom
API call. Here’s a quick example in Python:
Copy code
room_client.CreateRoom(
    livekit.CreateRoomRequest(
        name="myroom",  # This is where you set your room name
        empty_timeout=600,
        max_participants=20
    )
)
Just a heads up—the room name has to be unique within your LiveKit deployment. If a room with that name already exists, the request will simply return the existing room. If you have any questions or want me to walk you through anything else, just let me know—I’m here to help! Sources: Managing rooms | LiveKit Docs | packages/livekit-server-sdk/src/RoomServiceClient.ts | examples/api/src/main.rs | livekit-protocol/livekit/protocol/room.pyi | src/main/kotlin/io/livekit/server/RoomServiceClient.kt
h
where do i create the room? is it in the sterater code already done?
t
Creating rooms in LiveKit is pretty straightforward, and you’ve got two options: • Automatic Creation: The room gets created automatically as soon as the first participant joins with a valid access token. This is the easiest way and happens by default—no extra code needed. • Explicit Creation: If you want more control—like setting timeouts, max participants, or adding metadata—you can create rooms yourself using the
CreateRoom
API. Here’s a quick example in Python:
Copy code
room_client.CreateRoom(\n    livekit.CreateRoomRequest(\n        name=\"myroom\",\n        empty_timeout=600,\n        max_participants=20\n    )\n)
And don’t worry if your starter code doesn’t explicitly create rooms—the automatic creation will still kick in when someone joins. If you want, I’m happy to help you find where that happens in your code! Sources: packages/livekit-server-sdk/src/RoomServiceClient.ts | examples/api.py | Managing rooms | LiveKit Docs | examples/api/src/main.rs | protobufs/livekit_room.proto
h
how do i add the room creation in my code above?
t
Hey there! To explicitly create a room in your code, you can use the
CreateRoom
API before kicking off the session. Here’s a friendly little tweak to your code to help you add room creation:
Copy code
from livekit import RoomServiceClient, CreateRoomRequest

# Initialize the RoomServiceClient (just make sure you have your credentials handy)
room_client = RoomServiceClient(api_key="your_api_key", api_secret="your_api_secret")

# Let's create the room explicitly
room = room_client.CreateRoom(
    CreateRoomRequest(
        name="myroom",  # Pick a room name you like here
        empty_timeout=600,  # Optional: how long before the room times out (in seconds)
        max_participants=20  # Optional: max number of people allowed
    )
)

# Now, continue with your usual session setup
session = AgentSession(
    llm=openai.realtime.RealtimeModel(
        voice="ash"
    )
)

await session.start(
    room=room,  # Use the room we just created
    agent=Assistant(),
    room_input_options=RoomInputOptions(
        noise_cancellation=noise_cancellation.BVC(),
    ),
)
Just a quick reminder to swap out
your_api_key
and
your_api_secret
with your actual LiveKit credentials. If you hit any bumps or have questions, I’m here to help!