How do I manually end a call?
# ask-ai
l
How do I manually end a call?
t
Thanks for reaching out, Computer. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To manually end a call for all participants in LiveKit, the recommended method is to delete the entire room. This will immediately disconnect everyone in the call. Here’s how you can do this programmatically:
Copy code
from livekit import api
from livekit.agents import get_job_context

async def hangup_call():
    ctx = get_job_context()
    if ctx is None:
        # Not running in a job context
        return

    await ctx.api.room.delete_room(
        api.DeleteRoomRequest(
            room=ctx.room.name,
        )
    )
If you only want to remove a specific participant from the call, you can use the
remove_participant
method instead:
Copy code
async def hangup(self):
    try:
        await self.api.room.remove_participant(api.RoomParticipantIdentity(
            room=self.room.name,
            identity=self.participant.identity,
        ))
    except Exception as e:
        # It’s possible the user has already hung up
        <http://logger.info|logger.info>(f"received error while ending call: {e}")
For a complete call termination, deleting the room is the preferred approach as it ensures all participants are disconnected. Sources: Making calls using SIP | LiveKit Docs
l
Why do I get a 'failed to publish transcription' error when I delete the room?
t
Hey there! I totally get how frustrating that 'failed to publish transcription' error can be. Basically, this happens when you delete a room while it's still in the middle of publishing transcriptions. Once the room is gone, there's nowhere for those transcription details to go, which causes the publish to fail. Think of it like trying to send a letter to a house that's been demolished - it just can't happen! This is what we call a race condition, where room deletion and transcription publishing are trying to happen at the same time. You'll see this pop up across different SDKs, usually showing up as a warning or exception. No worries, though! The fix is pretty simple: just make sure all your transcription publishing is totally wrapped up before you delete the room. It's like making sure you've packed up all your stuff before moving out. Easy peasy! Sources: Managing rooms | LiveKit Docs | livekit-ffi/src/server/requests.rs | livekit-rtc/livekit/rtc/participant.py | livekit-agents/livekit/agents/voice/room_io/_output.py