Is there a way to see custom headers set in api.Cr...
# ask-ai
p
Is there a way to see custom headers set in api.CreateSIPParticipantRequest in livekit console?
t
Thanks for reaching out, Mario. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m glad you asked about custom headers in
api.CreateSIPParticipantRequest
! While these headers don’t show up directly in the LiveKit console, there’s a neat way to make them visible by mapping them to participant attributes using the
headers_to_attributes
field. For example, in your
CreateSIPParticipantRequest
, you can set it up like this:
Copy code
{
  "headers": {
    "X-Custom-ID": "12345",
    "X-Priority": "high"
  },
  "headers_to_attributes": {
    "X-Custom-ID": "custom_id",
    "X-Priority": "call_priority"
  }
}
After you map them, these headers will show up as participant attributes with the prefix
sip.h.*
in the console. So, for example,
X-Custom-ID
mapped to
custom_id
will appear as
sip.h.custom_id
. If you’d like, I’m here to help you walk through this setup or answer any other questions you might have! Sources: SIP overview | LiveKit Docs | SIP APIs | LiveKit Docs | protobufs/livekit_sip.proto | cmd/lk/sip.go | SIP participant | LiveKit Docs
p
I'm using Python though
t
To set
headers_to_attributes
in Python for LiveKit, you can easily configure it as part of the
CreateSIPParticipantRequest
. Here’s a simple example to guide you through it:
Copy code
from livekit.protocol.sip import CreateSIPParticipantRequest

# Define headers and their mappings
headers_to_attributes = {
    "X-Custom-ID": "custom_id",
    "X-Priority": "priority_level"
}

# Create the SIP participant request
request = CreateSIPParticipantRequest(
    sip_trunk_id="trunk_123",
    sip_call_to="+1234567890",
    room_name="meeting_room",
    participant_identity="caller123",
    headers={
        "X-Custom-ID": "12345",
        "X-Priority": "high"
    },
    headers_to_attributes=headers_to_attributes
)
After this mapping, these headers will show up as participant attributes with the prefix
sip.h.*
in the console. If you have any questions or need a hand with anything else, just let me know—I’m here to help! Sources: SIP APIs | LiveKit Docs | livekit-protocol/livekit/protocol/sip.pyi | livekit/livekit_sip.pb.go | SIP participant | LiveKit Docs
p
there is no
headers_to_attributes
in the python client...
t
Hi there! I wanted to share some helpful info about the Python client for LiveKit. The
headers_to_attributes
field isn’t directly part of
CreateSIPParticipantRequest
, but don’t worry—it’s actually found inside the
trunk
field, which uses the
SIPOutboundConfig
class. Here’s a simple way you can set it up:
Copy code
from livekit.protocol.sip import CreateSIPParticipantRequest, SIPOutboundConfig

# Define headers and their mappings
headers_to_attributes = {
    "X-Custom-ID": "custom_id",
    "X-Priority": "priority_level"
}

# Create the SIPOutboundConfig
trunk_config = SIPOutboundConfig(
    hostname="sip.provider.com",
    headers_to_attributes=headers_to_attributes
)

# Create the SIP participant request
request = CreateSIPParticipantRequest(
    sip_trunk_id="trunk_123",
    sip_call_to="+1234567890",
    room_name="meeting_room",
    participant_identity="caller123",
    trunk=trunk_config
)
If anything’s unclear or you’d like me to walk you through it further, just let me know—I’m here to help! Sources: livekit/livekit_sip.pb.go | livekit-api/livekit/api/sip_service.py
p
um... I don;t want to manually specify all fields foir the trunk
t
Great news! You don’t have to manually specify all trunk fields in the Python client. Instead, you can set up
headers_to_attributes
right at the SIP trunk level. This means the mapping will automatically apply to every participant created using that trunk, making things much simpler for you. Here’s a friendly walkthrough to get you started:
Copy code
from livekit.api import CreateSIPOutboundTrunkRequest, SIPOutboundTrunkInfo

# Configure headers_to_attributes at the trunk level
trunk_info = SIPOutboundTrunkInfo(
    name="my-trunk",
    address="sip.provider.com",
    headers_to_attributes={
        "X-Custom-ID": "custom_id",
        "X-Priority": "priority_level"
    }
)

# Create the trunk
outbound_trunk = CreateSIPOutboundTrunkRequest(trunk=trunk_info)
created_trunk = await sip_service.create_outbound_trunk(outbound_trunk)
Then, when you create a SIP participant, all you need to do is reference the trunk ID like this:
Copy code
from livekit.api import CreateSIPParticipantRequest

create_request = CreateSIPParticipantRequest(
    sip_trunk_id=created_trunk.sip_trunk_id,
    sip_call_to="+1234567890",
    room_name="my-room",
    participant_identity="sip-participant"
)
This way, you avoid repeating yourself and keep everything nicely centralized. If anything feels unclear or you want to dive deeper, just let me know—I’m here to help! Sources: livekit/livekit_sip.pb.go | livekit-api/livekit/api/sip_service.py