# Twilio

> Connect a Twilio API key to LevelFour.

Source: https://docs.levelfour.ai/connectors/twilio


## Prerequisites

* A Twilio account.
* An Administrator or Developer, to create the API key.

## Connect

### Create an API key in Twilio

While signed into your main Twilio account, create a **Restricted** API key with these permissions if your account offers Restricted keys, otherwise a **Standard** key:

| Permission                                  | What it is for                              |
| ------------------------------------------- | ------------------------------------------- |
| `/twilio/billing/usage/read`                | Daily cost and usage by category            |
| `twilio/taskrouter/workspaces/list`         | Finding your Flex workspace, for idle seats |
| `twilio/taskrouter/workspaces.workers/list` | Listing your Flex seats, for idle seats     |

Copy the API Key SID, the API Secret, and your Account SID.

> **Note**
>
> A key created in the main account rolls up costs from every subaccount, as if the parent incurred them. If you need per-subaccount attribution instead, connect each subaccount separately with its own key.

### Add it to LevelFour

Open **Connect Providers**, select **Twilio**, and paste the three values. Click **Add Account SID**.

## Confirming it worked

The connection moves to **Connected** and a **Twilio** board appears under **Boards**. Your first data appears within a day.

## How LevelFour reads your Twilio bill

LevelFour reads Twilio's daily usage records and groups them the way Twilio does:

* **Product** is the Twilio product a charge belongs to, such as WhatsApp, Voice, SMS & MMS, Flex or Phone Numbers.
* **Category** is Twilio's own name for the charge, such as "Channels - WhatsApp - Template Marketing".
* **Account** is the Account SID the charge was billed to.

Twilio reports some usage twice, under a parent category and under its own, or under two names. LevelFour counts each charge once. Where Twilio's total for a day differs from the sum of its categories, LevelFour adds a line called **Not itemized** for the difference, so your days add up to what Twilio charged.

Twilio charges Flex named users, phone numbers, Premium Support and minimum spend adjustments for the whole month on a single day. LevelFour spreads each charge over the days of its month: the month's total stays the same, and the day Twilio posted it no longer reads as a spike.

If Twilio bills you in another currency, LevelFour converts each day to US dollars at that day's exchange rate. Your total in Twilio's currency does not change, but a spread charge can differ slightly in dollars from the same charge converted on the day Twilio posted it.

The board shows each category's cost per unit, such as the cost of one WhatsApp marketing message or one minute of outbound calling, beside the same figure for the period before.

The board opens on the last 30 days. If Twilio has billed you for less time than that, it opens on the days that have data, and never on fewer than seven.

## Finding idle Flex seats

On the Named User plan, Twilio charges for every Flex seat on the account, whether or not anyone uses it. LevelFour lists the seats in your Flex workspace and recommends removing a seat that has stayed **Offline** for 30 days. LevelFour prices the saving at what your bill charged per seat last month.

To remove a seat, delete its Worker in the **Flex Task Assignment** workspace under **TaskRouter**, then remove the person's Flex access in the Twilio Console or in your identity provider, or the seat comes back at their next sign-in. Twilio stops charging for it from the next calendar month.

LevelFour reads only the seat list. It never reads Flex user profiles, message content or call recordings.

## Rotating or removing access

### Rotating the credential

Create a new API key in Twilio, paste it into **Connect Providers**, then delete the old key.

### Removing access

Disconnect Twilio under **Connect Providers**, then delete the API key from Twilio's console.

## Troubleshooting

| Symptom                                 | What to do                                                                                                                                                                                                                  |
| --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Subaccount spend appears twice          | You connected the main account (which already rolls up subaccounts) and one or more subaccounts separately. Connect one or the other, not both                                                                              |
| No idle Flex seats are ever recommended | The key cannot list TaskRouter workspaces and workers. Use a Standard key, or add the two TaskRouter permissions above. On Active User Hour pricing Twilio does not charge for idle seats, so there is nothing to recommend |
| A **Not itemized** line appears         | Twilio's total for a day differs from the sum of its categories. The line keeps the day equal to what Twilio charged, and it is slightly negative when the categories add up to more than the total                         |
| Recent days keep changing               | Expected. Today's and the current month's usage are not final until Twilio closes them                                                                                                                                      |

## Next

* [Connect Providers](/connectors) lists every provider you can connect
