how to set headerToAttributes for outbound trunk i...
# ask-ai
o
how to set headerToAttributes for outbound trunk in json? for inbound trunk it works, but not for outbound
t
Thanks for reaching out, Jaivarsan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're using the right feature—outbound trunks use
headers_to_attributes
in the JSON. Here’s how to set it and what to check since inbound worked but outbound doesn't: 1) Example outbound trunk JSON
Copy code
{
  "name": "My outbound trunk",
  "address": "sip.telnyx.com",
  "numbers": [
    "+15105550100"
  ],
  "authUsername": "your-username",
  "authPassword": "your-password",
  "headers_to_attributes": {
    "X-Custom-Header": "customAttribute"
  }
}
2) Important checks • Field name and casing must be exactly
headers_to_attributes
. • The remote SIP endpoint must include the
X-*
header (e.g.,
X-Custom-Header
) in the INVITE for the value to be available. • Confirm you’re creating/updating the trunk using the CreateSIPOutboundTrunk API or dashboard JSON editor where
headers_to_attributes
is accepted. • After connection, the mapped attribute appears on the SIP participant as
customAttribute
. If you share the outbound JSON you tried and an example SIP INVITE (headers portion), I can spot any mismatch. Would you like me to review your config? Sources: SIP APIs | LiveKit docs
o
• dashboard JSON editor where
headers_to_attributes
is accepted. for outbound it is not showing
t
Thanks — I’m looking into why
headers_to_attributes
isn’t visible for your outbound trunk in the dashboard JSON editor. A few quick questions so I can pinpoint the issue: 1. Are you editing the trunk in the LiveKit Cloud dashboard UI or creating/updating it via the API/CLI? 2. Can you paste the exact outbound trunk JSON you currently see (or a screenshot of the dashboard JSON editor)? Mask any secrets. 3. Do you control the remote SIP endpoint that sends the INVITE? If so, can you paste the INVITE headers (or the relevant
X-*
header line) that should be mapped? 4. Which LiveKit dashboard version or release are you using, if known? If you prefer, paste just the
headers_to_attributes
snippet you tried. I’ll review it and suggest the exact JSON or a workaround if the UI is missing the field.
o
in the UI
t
Thanks — I’m responding about the
headers_to_attributes
field not appearing in the dashboard JSON editor for outbound trunks. A few quick troubleshooting steps and questions so I can pinpoint the cause: 1. In the dashboard JSON editor try adding the field manually under the outbound trunk object:
Copy code
"headers_to_attributes": {
  "X-Custom-Header": "customAttribute"
}
1. Confirm you saved the trunk after editing the JSON and re-opened it to verify the field persisted. 2. If the editor rejects the field or it disappears after save, paste the exact outbound trunk JSON you currently see (mask auth secrets). That will show whether the UI is hiding it or stripping it on save. 3. Tell me whether you created/edited the trunk from the Trunks page in LiveKit Cloud UI or through an embedded editor in another screen. 4. If you prefer not to paste JSON, tell me the exact error or behavior when you attempt to save (e.g., validation message, silent drop, or no save button). If you share the JSON or the save behavior, I’ll review it and give the exact JSON structure or a workaround. Would you like me to check your current config?
o
for on outbound call made through livekit outobund trunk, if we pass these as sip headers
Copy code
# Additional SIP headers if needed
            sip_headers = {}
            sip_headers["X-CallType"] = "OUTBOUND"
            if virtual_number:
                # Set caller ID via P-Asserted-Identity or From header
                sip_headers["X-Virtual-Number"] = virtual_number

            # Create the SIP participant request
            request = CreateSIPParticipantRequest(
                sip_trunk_id=sip_trunk_id,
                sip_call_to=sip_call_to,
                room_name=room_name,
                participant_identity=participant_identity,
                participant_metadata=participant_metadata,
                play_dialtone=False,  # Don't play dialtone, agent will handle audio
            )

            if sip_headers:
                # Protobuf map fields must be mutated, not reassigned
                for key, value in sip_headers.items():
                    request.headers[key] = value

            logger.debug(f"LiveKit CreateSIPParticipant request for call {call_uuid}: room={room_name}, trunk={sip_trunk_id}, to={sip_call_to}")
where will these sip headers sit again when joining or part of the particpant in the room with webrtc transport.
t
You're asking where the SIP headers you attach to an outbound call (via
request.headers[...]
) will appear for the WebRTC participant when they join the room. • If you configure
headers_to_attributes
on the outbound trunk (JSON field
headers_to_attributes
), any mapped
X-*
header present in the INVITE will be extracted and stored as a participant attribute on the SIP participant. Use the header name as the key in the map and the desired participant attribute name as the value. • Those mapped values become participant attributes accessible from the participant in the room (the SIP participant’s attributes map). For example, if you map
"X-CallType": "callType"
, the room participant will have an attribute
callType
with the header value. • If you do not set
headers_to_attributes
, headers sent on the outbound INVITE are not automatically persisted as participant attributes. Suggests: 1. Add
headers_to_attributes
to the outbound trunk JSON, for example:
Copy code
"headers_to_attributes": {
  "X-CallType": "callType",
  "X-Virtual-Number": "virtualNumber"
}
1. Place your headers into
request.headers
as you already do. After the SIP call connects, read the attribute from the participant’s attributes map (e.g.,
participant.info.attributes["callType"]
). If you want, paste the trunk JSON you’re using and I’ll verify the exact mapping you need.