> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Telephony API

> Read the SIP signalling and audio quality of a PolyAI call, to see why it failed, rang too long or sounded bad.

The Telephony API exposes what PolyAI's telephony layer recorded for a voice call: the **Session Initiation Protocol (SIP)** messages exchanged between the carrier and PolyAI, known as the call's **SIP ladder**, and the **RTP Control Protocol (RTCP)** reports that describe packet loss and jitter on the audio. Use it to answer "why did this call fail?", "how long did it ring?", "who hung up?" and "was this a network problem or an agent problem?" from your own tooling.

> [!NOTE]
>
> This API is read-only and describes calls that already happened. To connect your own telephony platform to PolyAI, see the [SIP Trunking API](https://docs.poly.ai/api-reference/sip-trunking/introduction.md).

## Endpoints

| Endpoint | What it does |
| - | - |
| [`GET /api/v1/telephony/calls/{conversation_id}/sip`](https://docs.poly.ai/api-reference/telephony/endpoint/get-call-sip-ladder) | The SIP messages of one call, combined across legs: the carrier, PolyAI's SIP edge and the media server, including transfers. |
| [`GET /api/v1/telephony/calls/{conversation_id}/quality`](https://docs.poly.ai/api-reference/telephony/endpoint/get-call-audio-quality) | Packet loss and jitter per media stream for one call, plus a per-call rollup. |

Both endpoints are also available as [Data MCP](https://docs.poly.ai/mcp/data/capabilities.md#telephony) tools: `get-call-sip-ladder` and `get-call-audio-quality`.

## Base URL and authentication

Send an **account API key** in the `X-API-KEY` header (`Authorization: Bearer <key>` is also accepted). The key needs read access to conversations. Create keys from the **API Keys** tab in Agent Studio; see [API keys](https://docs.poly.ai/secrets/api-keys.md).

Keys are region-specific. Use the host of the region your account lives in.

| Region | Base URL |
| - | - |
| US | `https://api.us.poly.ai` |
| UK | `https://api.uk.poly.ai` |
| EU | `https://api.eu.poly.ai` |
| Studio | `https://api.studio.poly.ai` |

Both endpoints accept an optional `project_id`, the **Agent ID** shown in Agent Studio (`PROJECT-xxxxxxxx`). Use it to confirm a call belongs to a given agent; a call that does not belong to that agent returns `404`. It is required when you authenticate with a personal access token (PAT) instead of an account API key.

## Concepts

### Call identifier

`conversation_id` is the call SID: the same `conversation_id` the [Conversations API](https://docs.poly.ai/api-reference/conversations/introduction.md) and the [Traces API](https://docs.poly.ai/api-reference/traces/introduction.md) return for a voice call. A call is visible only to the account it belongs to; any other call returns `404`.

### Legs

One call usually involves several SIP dialogs, each with its own SIP `Call-ID`. The SIP endpoint returns every dialog it can link to the call as a **leg**: the carrier to PolyAI's SIP edge, PolyAI's SIP edge to the media server, and any further legs created by a transfer. Messages from all legs come back in one list, ordered by capture time, so you can read the call end to end.

A `Call-ID` is chosen by whoever starts the dialog, so two unrelated calls can occasionally share one. When a dialog's `Call-ID` also appears on a call of another account, or of another agent when you pass `project_id`, that leg is left out, because PolyAI cannot tell whose messages are whose. If no leg remains, the call returns `404`.

### SIP messages

Each message has a `method`: the request method (for example `INVITE`, `BYE` or `REFER`), `OTHER` for a method that is not a standard SIP method, or, for a response, the response code as a string (for example `180` or `200`). Responses also carry `response_code` and `reason`, the standard phrase for that code; the phrase the remote party sent is not returned.

With `include_sip_details=true`, each message also carries selected details taken from its headers and body:

| Field | What it holds | Needs PII access |
| - | - | - |
| `reason_headers` | Cause codes from `Reason` headers (`Q.850` or `SIP`), for example why a `BYE` or `CANCEL` was sent. | No |
| `refer_status` | The result of a transfer, from the `NOTIFY` that reports a `REFER`'s progress, for example `486`. | No |
| `sdp` | The media offered or answered: address, port, transport, whether it is encrypted (SRTP), codecs, direction (for example `sendonly` on hold) and packetization time. | Yes |
| `refer_to`, `referred_by`, `asserted_identity` | The numbers in `Refer-To`, `Referred-By` and `P-Asserted-Identity`. | Yes |
| `diversions` | Redirections from `Diversion` headers: the number diverted from and why. | Yes |

A leg's `final_response` is the first response of `200` or above to **any** request on that leg, not only to the `INVITE`. When a caller hangs up before the call is answered, the `200` that acknowledges the `CANCEL` arrives before the `487` that ends the `INVITE`, so `final_response` is `200`. To see how a leg really ended, read its messages.

### Audio quality

Audio quality comes from RTCP reports sent during the call. The API groups them into one **stream** per leg (`call_id`), reporting endpoint (`ssrc`) and source (`source_ssrc`), with:

| Field | Meaning |
| - | - |
| `packets_sent` | Packets the reporting endpoint itself sent, from its sender reports. |
| `packets_lost` | Cumulative packets lost, from the stream's last report. |
| `fraction_lost_avg_pct` / `fraction_lost_max_pct` | The average and the highest percentage of packets lost in a single reporting interval. |
| `jitter_avg_ms` / `jitter_max_ms` | Interarrival jitter in milliseconds, calculated assuming an 8 kHz RTP clock (narrowband audio). |

`packets_sent` counts what the reporter sent, while the loss and jitter fields describe what it received from `source_ssrc`. Do not divide one by the other to get a loss rate; use `fraction_lost_avg_pct` and `fraction_lost_max_pct`.

Loss or jitter that is high on every stream points to the network or the carrier. If the streams are clean but the call still went badly, look at the agent with the [Traces API](https://docs.poly.ai/api-reference/traces/introduction.md).

### Personal data

What the SIP endpoint returns depends on whether the API key can read personal data (PII).

Without PII access:

* **Phone numbers** in `from_user` and `to_user` keep only their last four digits, after `***`. A user part counts as a number when it holds a run of at least six digits once separators are ignored, whatever surrounds it, so `+442079460142`, `tel:+44-20-7946-0142` and `%2B442079460142` all become `***0142`.
* **Other user parts**, such as a SIP username, become `***`. Placeholders such as `anonymous`, `private`, `restricted`, `unavailable`, `unknown` and `withheld` are returned as they are.
* **Network details** (`src_ip`, `src_port`, `dst_ip`, `dst_port` and `user_agent`) are `null`, on messages and on legs.
* **SIP details** are limited to `reason_headers` and `refer_status`, even with `include_sip_details=true`.

With PII access, all of these are returned as recorded.

The audio quality endpoint returns no personal data.

## Time windows

`from` and `to` are optional ISO 8601 query parameters that set the window in which PolyAI looks for the call. `to` defaults to now and `from` to 14 days before now.

Telephony data is kept for 14 days, the retention limit. A `from` earlier than that is raised to the limit, and a call older than that returns `404`.

The window only locates the call. The messages and reports returned cover the call's own time span, from 5 minutes before its first message to about 3 minutes after its last. Messages outside that span, such as those of a transfer leg that continues long after the main leg ends, are not returned, and `truncated` does not flag them.

Responses carry `truncated`. It is `true` when the cap of 2,000 SIP messages or 5,000 RTCP reports was reached within that span, and later messages or reports are missing.

## Errors

| Status | Meaning |
| - | - |
| `400` | `project_id` is required for your credential and was not sent. |
| `401` | Missing or invalid API key. |
| `403` | Authenticated, but the key cannot read conversations. |
| `404` | The call has no telephony data, is older than 14 days, belongs to another account or does not match `project_id`. |
| `422` | A parameter is malformed, for example `from`, `to` or `include_sip_details`. |
| `429` | Too many requests. Wait for the `Retry-After` period, then retry. |
| `502` | The telephony data store did not answer. Retry with backoff. |
