flaky-hospital-13625
11/13/2025, 10:07 AMtall-airline-16756
11/13/2025, 10:07 AMtall-airline-16756
11/13/2025, 10:08 AMheaders field in the CreateSIPParticipantRequest object. This lets you include your custom SIP X-* headers right in the INVITE request.
Here’s a friendly example to guide you:
from livekit import api
# Initialize the Livekit API client
livekit_api = api.ApiClient(
api_key="your-api-key",
api_secret="your-api-secret",
base_url="your-livekit-server-url"
)
# Define custom SIP headers
custom_headers = {
"X-Custom-Header": "value1",
"X-Another-Header": "value2"
}
# Create SIP participant with custom headers
response = livekit_api.sip.create_sip_participant(
livekit_api.sip.CreateSIPParticipantRequest(
sip_trunk_id="your-sip-trunk-id",
sip_call_to="+1234567890", # The phone number to call
room_name="outbound-call-room",
participant_identity="caller-identity",
headers=custom_headers, # Pass the custom headers here
wait_until_answered=True
)
)
print("SIP Call ID:", response.sip_call_id)
Just make sure to replace placeholders like "your-api-key", "your-api-secret", and "your-livekit-server-url" with your actual LiveKit credentials and server URL. Also, update "your-sip-trunk-id" with the ID of your configured SIP trunk.
The headers dictionary holds the custom X-* headers you want to send with the SIP INVITE request. These will be passed exactly as you set them to the SIP endpoint, which can be really helpful for routing, logging, or any other needs your SIP setup supports.
Sources: livekit/livekit_sip.pb.go | livekit-protocol/livekit/protocol/sip.pyi | test/integration/sip_test.goflaky-hospital-13625
11/13/2025, 10:11 AMFrom and P-Asserted-Identity headers?tall-airline-16756
11/13/2025, 10:12 AMFrom and P-Asserted-Identity headers using the headers field in the CreateSIPParticipantRequest object. Here’s a friendly example to guide you:
from livekit.protocol.sip import CreateSIPParticipantRequest
create_request = CreateSIPParticipantRequest(
sip_trunk_id="your-trunk-id",
sip_call_to="+1234567890",
room_name="my-room",
participant_identity="sip-participant",
headers={
"From": "sip:caller@example.com",
"P-Asserted-Identity": "sip:asserted@example.com"
}
)
Just a couple of important things to keep in mind:
• Your SIP provider needs to allow modification of these headers. Sometimes providers might restrict or overwrite them for security reasons.
• For setting the actual calling number (caller ID), it’s best to use the sip_number field in CreateSIPParticipantRequest to make sure everything routes correctly.
• Headers set at the SIP trunk level will combine with or be overridden by the headers you specify in the request.
It’s a good idea to double-check with your SIP provider to ensure they support this, so you can avoid any call rejections or unexpected header changes. If you have any more questions, I’m here to help!
Sources: protobufs/livekit_sip.proto | SIP APIs | LiveKit docs | Preserving Caller ID During SIP Transfers in LiveKit Agents