powerful-dog-59275
08/26/2025, 2:00 PMtall-airline-16756
08/26/2025, 2:00 PMtall-airline-16756
08/26/2025, 2:01 PMdelete_room API. This will remove all participants, including the SIP participant, and completely end the session.
Here’s a simple example to help you get started:
from livekit import api
async def hangup_call():
ctx = get_job_context() # or use JobContext directly
if ctx is None:
return
await ctx.api.room.delete_room(
api.DeleteRoomRequest(room=ctx.room.name)
)
Another way is to handle session closure right in your agent logic by listening for events like participant_disconnected and calling delete_room when the room is empty:
async def entrypoint(ctx: JobContext):
@ctx.room.on("participant_disconnected")
def on_participant_left(participant):
if len(ctx.room.participants) == 0: # last participant left
ctx.delete_room() # immediately terminate room and SIP session
# wait for room events or shutdown
...
Deleting the room explicitly like this helps make sure everything cleans up right away and avoids any surprise lingering sessions. If you want, I’m here to help you get this set up—just let me know!
Sources: Agents telephony integration | LiveKit Docs | Inside a session | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | pkg/sip/inbound.go | Job lifecycle | LiveKit Docspowerful-dog-59275
08/26/2025, 2:02 PMtall-airline-16756
08/26/2025, 2:03 PMRoomServiceClient with your LiveKit server URL, API key, and secret key like this:
import { RoomServiceClient } from 'livekit-server-sdk';
const livekitHost = <LIVEKIT_SERVER_URL>;
const apiKey = <API_KEY>;
const secretKey = <SECRET_KEY>;
const roomService = new RoomServiceClient(livekitHost, apiKey, secretKey);
1. Next, just call the deleteRoom method and pass in the room name you want to delete:
await roomService.deleteRoom('myroom');
Keep in mind, deleting a room will disconnect everyone currently in it. If you have any questions or need a hand with this, feel free to ask—I'm here to help!
Sources: Managing rooms | LiveKit Docs | Managing rooms | LiveKit Docs | livekit/livekit_room.twirp.go | packages/livekit-server-sdk/README.mdpowerful-dog-59275
08/26/2025, 2:03 PMtall-airline-16756
08/26/2025, 2:04 PMRoomServiceClient by calling the deleteRoom method and passing in the room's name. Here’s a simple way to get it done:
1. First, set up the RoomServiceClient with your LiveKit API credentials:
import { RoomServiceClient } from 'livekit-server-sdk';
const roomServiceClient = new RoomServiceClient(
<LIVEKIT_SERVER_URL>,
<API_KEY>,
<SECRET_KEY>
);
1. Then, inside your agent’s logic, just call deleteRoom and pass the room name from the agent’s context like this:
await roomServiceClient.deleteRoom(ctx.room.name!);
Here’s an example you can add to your agent’s execution code:
execute: async () => {
console.log('Waiting for 20 seconds before deleting room...');
setTimeout(async () => {
console.log('Deleting room...');
await roomServiceClient.deleteRoom(ctx.room.name!);
}, 20000);
return 'Game over, thank you for playing. Goodbye!';
}
This way, the room gets properly deleted, all participants are disconnected, and the Disconnected event fires with the reason ROOM_DELETED. If anything’s unclear or you want a hand with this, just let me know—I’m here to help!
Sources: Connecting to LiveKit | LiveKit Docs | packages/sip--um-actually/src/agent.tspowerful-dog-59275
08/26/2025, 2:10 PMtall-airline-16756
08/26/2025, 2:10 PMpowerful-dog-59275
08/26/2025, 2:11 PMtall-airline-16756
08/26/2025, 2:12 PMpowerful-dog-59275
08/26/2025, 2:13 PMtall-airline-16756
08/26/2025, 2:14 PMimport { RoomServiceClient } from 'livekit-server-sdk';
const roomServiceClient = new RoomServiceClient(
<LIVEKIT_SERVER_URL>,
<API_KEY>,
<SECRET_KEY>
);
async function handleParticipantDisconnected(ctx) {
ctx.room.on('participant_disconnected', async (participant) => {
if (ctx.room.participants.size === 0) { // Check if all participants have left
console.log('All participants have left. Deleting room...');
await roomServiceClient.deleteRoom(ctx.room.name!);
}
});
}
This snippet listens for the participant_disconnected event and deletes the room once everyone’s gone. If you want a hand setting this up or have any questions, just let me know—I’m here to help!