how to add headers_to_attributes
# ask-ai
b
how to add headers_to_attributes
t
Thanks for reaching out, Sandeep. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To add
headers_to_attributes
in LiveKit, you can easily set it up within either an inbound or outbound SIP trunk configuration. This feature helps you map custom SIP headers (like
X-*
headers) directly to LiveKit participant attributes, making your setup more personalized and efficient. For Inbound SIP Trunks: When you're setting up or updating an inbound SIP trunk, simply use the
headers_to_attributes
field to connect headers from the SIP
INVITE
request to participant attributes. Here’s an example to guide you:
Copy code
{
  "trunk": {
    "name": "Demo inbound trunk",
    "numbers": [
      "+15105550100"
    ],
    "headers_to_attributes": {
      "X-Custom-Id": "user_id",
      "X-Custom-Role": "role"
    }
  }
}
For Outbound SIP Calls: When making an outbound call using
CreateSIPParticipant
, you can include
headers_to_attributes
within the
SIPOutboundConfig
to map headers from the SIP
200 OK
response to participant attributes. Here’s a helpful example:
Copy code
{
  "sip_trunk_id": "trunk_123",
  "sip_call_to": "+1234567890",
  "room_name": "my_room",
  "trunk": {
    "hostname": "sip.provider.com",
    "transport": "UDP",
    "headers_to_attributes": {
      "X-User-ID": "user_id"
    }
  }
}
If you have any questions or need a hand with this setup, please don’t hesitate to reach out. I’m here to help! Sources: SIP participant | LiveKit Docs | protobufs/rpc/sip.proto | livekit-protocol/livekit/protocol/sip.pyi | livekit-protocol/src/livekit.rs
b
headers_to_attributes is not getting update in update request
t
It looks like the
headers_to_attributes
field might not be updating in your request because of the update method being used. To update this field, you’ll want to use the
replace
action in your update request, since the usual update methods don’t support changing this field directly. Here’s a simple way to update it: 1. Use the
replace
action in your update request. For example:
Copy code
{
  "req": {
    "sip_trunk_id": "your-trunk-id",
    "replace": {
      "name": "Updated Trunk Name",
      "numbers": [
        "+15105550100"
      ],
      "address": "sip.provider.com",
      "headers_to_attributes": {
        "X-Custom-ID": "caller_id",
        "X-Dept": "department"
      },
      "media_encryption": 0
    }
  }
}
1. Make sure to include all required fields, since the
replace
action will overwrite the entire trunk configuration. 2. Double-check that you’re using the correct API endpoint and authentication token, and that it matches your trunk type (inbound or outbound). 3. After sending the request, you can confirm the update by using
GetSIPInboundTrunk
or
GetSIPOutboundTrunk
. If you run into any issues or have questions along the way, please don’t hesitate to reach out—I’m here to help! Sources: livekit/livekit_sip.pb.go | SIP APIs | LiveKit Docs
b
curl --location 'https://stagingpulse-t7293wti.livekit.cloud/twirp/livekit.SIP/UpdateSIPInboundTrunk' \ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoibmFtZSIsInZpZGVvIjp7InJvb21Kb2luIjp0cnVlLCJyb29tIjoibXktcm9vbSIsImNhblB1Ymxpc2giOnRydWUsImNhblN1YnNjcmliZSI6dHJ1ZSwiY2FuUHVibGlzaERhdGEiOnRydWV9LCJzaXAiOnsiYWRtaW4iOnRydWUsImNhbGwiOnRydWV9LCJzdWIiOiJpZGVudGl0eSIsImlzcyI6IkFQSXV3akVncXBaeEo5ZyIsIm5iZiI6MTc0ODExMjMyNiwiZXhwIjoxMjI3MDgxMTIzMjZ9.E0xWxHOEQEsBoRruVJCHGtNDEaqywg4-yuNY7fTlf2k' \ --header 'Content-Type: application/json' \ --data-raw ' { "sip_trunk_id": "ST_rk2a4tiMhaEt", "update": { "name": "staging_livekit_inbound_trunk", "metadata": "{\"trunkPhoneNumber\":\"+918035731212\"}", "numbers":{ "set": [ "+918035731212" ] }, "allowed_addresses": { "set": [ "54.172.60.0/23", "54.172.254.0/24", "52.55.63.0/24", "52.45.127.0/24", "18.136.1.128/26", "13.238.202.192/26", "52.9.254.123/32", "52.9.254.127/32", "216.120.187.64/32", "216.120.187.65/32", "216.120.187.66/32", "216.120.187.67/32", "216.120.187.68/32", "204.89.148.64/32", "204.89.148.65/32", "204.89.148.66/32", "204.89.148.67/32", "204.89.148.68/32", "13.52.9.4/32", "13.52.9.5/32", "18.214.109.132/32", "18.214.109.133/32", "216.120.187.64/25", "216.120.187.192/27", "204.89.148.64/25", "204.89.148.192/27", "3.120.121.128/26", "54.233.191.0/27", "18.228.70.64/26", "13.238.202.192/26", "52.220.63.176/28", "204.89.149.64/27", "204.89.149.128/27", "204.89.151.64/26", "204.89.151.128/25", "13.56.175.187/32", "13.57.139.231/32", "18.211.55.148/32", "18.211.27.222/32", "204.89.148.70/32", "3.120.80.110/32", "35.157.59.132/32", "18.228.96.85/32", "18.228.143.199/32", "13.238.88.135/32", "52.62.46.143/32", "52.220.250.27/32", "18.136.128.252/32", "3.7.4.233/32", "3.7.220.174/32" ]}, "auth_username": "saww", "auth_password": "@" }, "replace": { "headers_to_attributes": { "X-Plivo-CallUUID": "_call_id" } } }'
t
It looks like you're using both the
update
and
replace
actions in your request. To help you get the
headers_to_attributes
field updated correctly, here are a few friendly steps to follow: 1. Try using only the
replace
action when modifying the
headers_to_attributes
field, since the
update
action doesn’t support changes to this field. 2. Make sure the header names in
headers_to_attributes
are formatted properly. For example, they should match the pattern
^[a-zA-Z][a-zA-Z0-9\-_]*$
and avoid spaces or special characters. 3. Double-check that the SIP headers in the incoming INVITE request exactly match the names you’ve specified in
headers_to_attributes
, keeping in mind that this mapping is case-sensitive. 4. After sending your request, you can use the
GetSIPInboundTrunk
API to confirm that the
headers_to_attributes
field updated as expected. If you’re still running into issues, it might help to look at the SIP INVITE request logs to see if the SIP provider is sending the headers you expect. Please don’t hesitate to reach out if you’d like me to walk through this with you further—I’m here to help! Sources: protobufs/rpc/io.proto | SIP inbound trunk | LiveKit Docs | SIP APIs | LiveKit Docs