how to end the call properly?
# ask-ai
n
how to end the call properly?
t
Thanks for reaching out, Tareq. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To properly end a call in LiveKit, you can follow these approaches depending on your use case: 1. End Call for All Participants: Use the
delete_room
API to terminate the entire session. This will disconnect all participants and remove the room from the server:
Copy code
await ctx.api.room.delete_room(
    api.DeleteRoomRequest(
        room=ctx.room.name,
    )
)
2. End Call for Specific Participants: If you want to remove only specific participants, use the
remove_participant
API:
Copy code
await self.api.room.remove_participant(api.RoomParticipantIdentity(
    room=self.room.name,
    identity=self.participant.identity,
))
3. Agent-Specific Disconnection: For agent-specific disconnection while allowing other participants to continue, use the job context shutdown method:
Copy code
ctx.shutdown(reason="Session ended")
Important Considerations: • Let the agent finish speaking before terminating the connection. • The
delete_room
API sends a
Disconnected
room event to all participants. • Handle errors gracefully, as users may have already hung up. Let me know if you need further clarification or assistance with implementing these methods. Sources: Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docs | Job lifecycle | LiveKit Docs | telephony/sip_lifecycle.py