---
title: "Layered caller verification for LiveKit SIP calls"
date: "2026-04-25"
authors: "Darryn Campbell"
tags: "guide"
---

# Layered caller verification for LiveKit SIP calls

Identity verification for inbound SIP callers in LiveKit happens at three layers: the **trunk**, the **dispatch rule**, and the **agent itself**. Each layer gives you progressively more granular control, and in practice you'd combine them.

> If you just want to know how to verify the caller from within the agent, skip to the <a href="#agent-driven-verification">Agent-driven verification</a> section.

## 1. Trunk-level filtering (before LiveKit accepts the call)

When you create an inbound SIP trunk, you can answer two separate questions before LiveKit accepts the call: *is the trunk itself trustworthy?* and *is the caller who they claim to be?*.

### Verifying the trunk

Many of the parameters you specify when creating the trunk verify the *provider*, not the caller. This prevents someone from bypassing your SIP carrier and injecting rogue INVITEs directly at your LiveKit endpoint. For example, LiveKit uses `auth_username` / `auth_password` to authenticate inbound INVITEs from your provider.

For a full list of supported parameters, see the docs for [CreateSIPInboundTrunk](https://docs.livekit.io/reference/telephony/sip-api/#createsipinboundtrunk). LiveKit offers several [provider-specific quickstarts](https://docs.livekit.io/telephony/start/providers/) that detail any considerations particular to your SIP provider.

### Verifying the caller

If you need to restrict access to a defined list of callers, you can specify **`allowed_numbers`** on your incoming SIP trunk. Calls from any other number are rejected at the trunk:

```json
{
  "trunk": {
    "name": "My inbound trunk",
    ...
    "allowed_numbers": ["+13105550100", "+17145550100"]
  }
}
```

This is a coarse filter for expected callers, not strong proof of identity since the caller ID over the PSTN is trivially spoofable.

You can leave `allowed_numbers` empty to accept calls from any number. Either way, set `auth_username` and `auth_password` or `allowed_addresses` on the trunk, since these restrict which systems can send calls to it, not just which caller IDs they claim.

## 2. Dispatch-rule-level controls (when routing into a room)

The dispatch rule decides which LiveKit room an accepted call joins, and it has its own configurable parameters.

### PIN-protected rooms

If you need to restrict access to users based on a shared secret, you can prompt them to enter a PIN using their keypad (DTMF) before being allowed to join the room. Define a `pin` on the [dispatch rule](https://docs.livekit.io/telephony/accepting-calls/dispatch-rule/#pin-protected-room) as follows:

```json
{
  "dispatch_rule": {
    "name": "protected room rule",
    "trunk_ids": [],
    "rule": {
      "dispatch_rule_direct": {
        "room_name": "protected-room",
        "pin": "12345"
      }
    }
  }
}
```

### Inbound numbers (`inbound_numbers`)

Similar to `allowed_numbers` at the trunk level, `inbound_numbers` matches against a defined list of caller numbers, allowing you to apply different policies per caller, such as routing them to a specific room, or dispatching a separate agent.

This is a useful feature if you expect calls from a defined set of numbers, but this parameter can be left blank to accept calls from any number. As stated previously, rules based on the caller's number should be treated as a routing hint rather than secure authentication.

```json
{
  "dispatch_rule": {
    "name": "VIP dispatch rule",
    "inbound_numbers": ["+13105550100", "+17145550100"],
    "rule": {
      "dispatch_rule_individual": {
        "room_prefix": "vip-"
      }
    },
    "room_config": {
      "agents": [{ "agent_name": "vip-agent" }]
    }
  }
}
```

## 3. Participant-level identification (inside the agent)

Once the call is accepted, it becomes a SIP participant in the room with `kind == SIP` and a bundle of auto-populated `sip.*` attributes the agent can read.

### SIP phone number (`sip.phoneNumber`)

The caller's phone number (ANI) is the most common form of caller identification you can use to look up account info.  As mentioned previously, the caller's number it should not be used on its own to securely identify the user. Also note that this attribute isn't available if `hide_phone_number` is set on the dispatch rule.

```python
from livekit import rtc

participant = await ctx.wait_for_participant()
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
    caller_number = participant.attributes.get("sip.phoneNumber")
```

### Other SIP attributes

The full list of `sip.*` attributes is available from the [SIP participant docs](https://docs.livekit.io/reference/telephony/sip-participant/#sip-attributes).

Some of the relevant attributes for caller identification are as follows:

| Attribute              | Purpose                                                                                             |
| ---------------------- | --------------------------------------------------------------------------------------------------- |
| `sip.phoneNumber`      | Caller's number, as detailed above                                                                  |
| `sip.trunkPhoneNumber` | Number the caller dialed, which can be useful for multi-tenant routing                              |
| `sip.trunkID`          | Trunk ID. Use this to distinguish an "authenticated-customer trunk" from the "public support trunk" |
| `sip.ruleID`           | Dispatch rule ID that matched                                                                       |

### Custom SIP headers

Any `X-*` headers on the INVITE can be mapped to participant attributes via `headers_to_attributes` on the trunk. This is how you propagate things like an already-authenticated customer ID from an upstream PBX or IVR:

```json
{
  "trunk": {
    "name": "Authenticated IVR trunk",
    "numbers": ["+15105550100"],
    "headers_to_attributes": {
      "X-Customer-Id": "customer.id",
      "X-Auth-Token":  "customer.auth_token"
    }
  }
}
```

Attributes from `headers_to_attributes` arrive asynchronously, see [Custom attributes](https://docs.livekit.io/reference/telephony/sip-participant/#custom-attributes) for more information.

Then in the agent:

```python
customer_id    = participant.attributes.get("customer.id")
upstream_token = participant.attributes.get("customer.auth_token")

if customer_id and await verify_upstream_token(customer_id, upstream_token):
    logger.info(f"Caller pre-authenticated by upstream IVR as {customer_id}")
```

<a name="agent-driven-verification" />

### Agent-driven verification

Finally, the agent can verify identity *in the conversation itself*: ask for an account number, date of birth, shared secret, or OTP and authenticate against your backend via tool calls. This is the only layer that doesn't rely on the signalling path, and the agent should call it before discussing anything account-sensitive:

```python
from livekit.agents import RunContext, function_tool

# Verify identity based on knowledge only the user should know
@function_tool
async def verify_caller_identity(
    context: RunContext,
    account_number: str,
    passphrase: str,
    date_of_birth: str,
) -> str:
    """Verify the caller's identity against their account record.
    Call this before discussing any account-specific details."""
    phone = context.session.room_io.linked_participant.attributes.get("sip.phoneNumber")

    ok = await crm.verify(
        phone=phone,
        account_number=account_number,
        passphrase=passphrase,
        date_of_birth=date_of_birth,
    )
    if ok:
        context.session.userdata["verified"] = True
        return "Identity verified. You may now discuss account details."
    return "Verification failed. Do not share account-specific information."
```

```python
# Verify identity based on SMS
@function_tool
async def send_otp(context: RunContext) -> str:
    """Send a one-time code by SMS to the caller's number on file."""
    phone = context.session.room_io.linked_participant.attributes.get("sip.phoneNumber")
    code = await otp_service.send(phone)
    context.session.userdata["pending_otp"] = code
    return f"A 6-digit code has been sent to {phone[-4:]}. Please read it back."
```

Use [Tasks](https://docs.livekit.io/agents/logic/tasks/#define-task) to verify the user's identity before handing off to another agent to handle sensitive requests.

## Putting it together

Trunk and dispatch-rule controls decide *who gets through* and *where the call lands*. They're useful filters, but they lean on data the caller or upstream carrier can influence. `sip.phoneNumber` and custom header attributes inside the agent are good for a first-pass CRM lookup, but they carry the same caveat: none of them are proof of who is actually on the line.

Before your agent discusses anything sensitive, confirm the caller's identity in the conversation itself. Treat everything upstream of the agent as filtering and routing, and treat in-conversation verification as mandatory.