import asyncio import logging import os from live...
# ask-ai
h
import asyncio import logging import os from livekit import api from livekit.protocol.sip import TransferSIPParticipantRequest logger = logging.getLogger("transfer-logger") logger.setLevel(logging.INFO) async def transfer_call(participant_identity: str, room_name: str) -> None: async with api.LiveKitAPI() as livekit_api: transfer_to = 'tel:+14155550100' try: # Create transfer request transfer_request = TransferSIPParticipantRequest( participant_identity=participant_identity, room_name=room_name, transfer_to=transfer_to, play_dialtone=False ) logger.debug(f"Transfer request: {transfer_request}") # Transfer caller await livekit_api.sip.transfer_sip_participant(transfer_request) print("SIP participant transferred successfully") except Exception as error: # Check if it's a Twirp error with metadata if hasattr(error, 'metadata') and error.metadata: print(f"SIP error code: {error.metadata.get('sip_status_code')}") print(f"SIP error message: {error.metadata.get('sip_status')}") else: print(f"Error transferring SIP participant:") print(f"{error.status} - {error.code} - {error.message}") how to ge the participant id ?
t
Thanks for reaching out, Sahil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking how to get the participant identity to use in your
TransferSIPParticipantRequest
. The participant identity is the participant's
identity
field (not a separate numeric ID). You can retrieve it from the room's list of participants and then use that value in your transfer call. Below are concise options and example code to get the
participant_identity
. 1) Get the identity by listing participants in a room • Use
room.list_participants
and read
participant.identity
. • Optionally filter by
participant.kind
to find SIP participants. Example (async):
Copy code
from livekit import api

async def get_participant_identity(room_name: str) -> str:
    async with api.LiveKitAPI() as livekit_api:
        resp = await livekit_api.room.list_participants(
            api.ListParticipantsRequest(room=room_name)
        )

        # Find first SIP participant
        for p in resp.participants:
            if p.kind == api.ParticipantInfo.ParticipantKind.PARTICIPANT_KIND_SIP:
                return p.identity

        # Fallback: return first participant identity if any
        if resp.participants:
            return resp.participants[0].identity

        raise Exception("No participants found in room")
2) Track identity at creation time (recommended when you control SIP creation) • When you create a SIP participant, set and store the
participant_identity
you pass in. • Reuse that stored identity later for transfer. Example snippet when creating a SIP participant:
Copy code
await livekit_api.sip.create_sip_participant(
    api.CreateSIPParticipantRequest(
        room_name="my-room",
        participant_identity="caller-123",  # choose and store this
        sip_call_to="+15555555555",
        sip_trunk_id="ST_..."
    )
)
3) Use the identity in your transfer function • Once you have the identity, plug it into
TransferSIPParticipantRequest
exactly as in your original transfer code. If you want, tell me which room name you’re working with or whether you prefer to find the SIP participant by some property (caller number, metadata, or the first SIP participant). I can then show a tailored example that filters participants the way you need. Sources: Preserve caller ID during SIP transfers with Twilio | LiveKit | How to do call transfers with Five9 | LiveKit | SIP Lifecycle Management Agent | LiveKit Documentation | Outbound Calling Script | LiveKit Documentation