Provide me an example of passing header as "X-Call...
# ask-ai
a
Provide me an example of passing header as "X-CallerId" in CreateSIPParticpant request from my python code of ai agent
t
Thanks for reaching out, Hiren. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I understand you want a concrete Python example showing how to include the custom SIP header
X-CallerId
in a
CreateSIPParticipant
request. Below is a concise, ready-to-run example using the LiveKit Python client pattern shown earlier. • This example passes
X-CallerId
in the
headers
field of
CreateSIPParticipantRequest
. • Replace the placeholders (
your_livekit_url
,
your_api_key
,
your_api_secret
,
ST_xxx
, phone numbers, and room name) with your actual values.
Copy code
import asyncio
from livekit import api

async def create_sip_participant_with_x_callerid():
    # Initialize the LiveKit API client
    lkapi = api.LiveKitAPI(
        url="<https://your_livekit_url>",        # replace with your LiveKit URL
        api_key="your_api_key",               # replace with your API key
        api_secret="your_api_secret"          # replace with your API secret
    )

    # Custom SIP headers to include in the outbound INVITE
    custom_headers = {
        "X-CallerId": "1234567890"            # replace with your desired caller ID value
    }

    request = api.CreateSIPParticipantRequest(
        room_name="my-room",                  # replace with target room
        sip_trunk_id="ST_xxx",                # replace with your SIP trunk ID
        sip_call_to="+1234567890",            # destination phone number
        participant_identity="phone_user",    # identity for the participant in LiveKit
        headers=custom_headers                # attach custom SIP headers here
    )

    try:
        resp = await lkapi.sip.create_sip_participant(request)
        print("SIP participant created:", resp)
    except Exception as e:
        print("Error creating SIP participant:", e)
    finally:
        await lkapi.aclose()

if __name__ == "__main__":
    asyncio.run(create_sip_participant_with_x_callerid())
If you'd like, I can: • Show how to include multiple custom headers. • Demonstrate validating that the SIP provider received
X-CallerId
. • Provide a short example for synchronous code (if your environment doesn't use async). Which would help most for your use case? Sources: Outbound Calling Script | LiveKit Documentation | SIP Lifecycle Management Agent | LiveKit Documentation | Pass UUI data to Genesys Cloud during SIP transfers | LiveKit