# Connect Twilio

Costfluent reads your Twilio spend from your account's daily usage records, through Twilio's Usage
Records API, with a restricted API key you create for it. One connection is one Twilio account,
named by its Account SID, and the cost of everything that account is billed for.

## How Costfluent connects

Costfluent collects each day's Twilio cost from the account's daily usage records, one record per
usage category and day, such as outbound voice minutes or outbound SMS messages.

Costfluent stores the key's SID and secret encrypted and uses them on `api.twilio.com` for one read
only, and never for a request that changes anything: the account's daily usage records
(`/2010-04-01/Accounts/{AccountSid}/Usage/Records/Daily.json`). The Account SID is the connection's
identity, and the key is only ever used for that connection.

A parent account's usage records include the usage of all its subaccounts
([UsageRecord resource](https://www.twilio.com/docs/usage/api/usage-record), read 2026-11-26). A
subaccount is an account of its own, with its own Account SID.

:::caution
Connect the parent account for everything, or each subaccount for a split, never both. A subaccount
connected beside its parent is counted twice, once in each connection, and Costfluent cannot see
that the two overlap.
:::

## Prerequisites

1. The Owner or Integration owner organization role in Costfluent.
2. A Twilio Console user who can create API keys in the account, in region US1
   ([Restricted API keys](https://www.twilio.com/docs/iam/api-keys/restricted-api-keys), read
   2026-11-26).

## Connect

### Create the key in Twilio

<Stepper>

1. Sign in to the Twilio Console of the account you want to connect, and copy its **Account SID**
   from “Account Info” on the home page. It starts with `AC`.
2. Open “Account”, then “API keys & tokens”, and select “Create API key”.
3. Enter a “Friendly name” that names Costfluent, keep the region “United States (US1)”, and choose
   the key type “Restricted”.
4. Allow only reading usage records (`/twilio/billing/usage/read`), and create the key.
5. Copy the key's SID, which starts with `SK`, and its secret. Twilio shows the secret only once.

</Stepper>

### Connect in Costfluent

<Stepper>

1. Open **Settings**, then **Integrations**, select **Twilio**, and open the **Connect** tab.
2. Select "Add API key", keep the suggested **Display name** or enter your own, and paste the
   **Account SID**, the **API key SID** and the **API key secret**.
3. Select "Test connection" to see each check, or "Connect" to save.

</Stepper>

Before storing anything, Costfluent checks that the Account SID and the key's SID have Twilio's
documented shape, so an Auth Token pasted into the API key SID field is never sent, and then reads
one day of the account's usage records with the key, so a connection that saves can read them. A
second connection of the same account is refused. If Twilio does not answer during that check,
nothing is saved: the account is only the connection's once the key has read it, so connect again
later.

## Data and freshness

Connecting imports as far back as your plan's backfill reaches, and at most six months
([Manage connections](/connect/manage-connections#how-it-behaves)). Cost arrives by GMT day, in the
account's billing currency, the day after it is incurred, and each sync reads the recent days again,
so a day Twilio revises is replaced, not counted twice.

Twilio's categories nest: “calls” holds “calls-inbound”, which holds “calls-inbound-local”. Costfluent
keeps each day's most detailed categories only, so a cost is counted once, and drops a category
another one of that day extends, and the totals Twilio names in its reference: “totalprice”, “pv”,
“lookups”, “programmablevoiceconnectivity”, “recordings”, “authy-calls-outbound” and
“authy-sms-outbound”. A category that cost nothing that day is skipped.

:::note
Twilio warns that some of its costs may sit in no usage category. Each day therefore gets one more
row, category “other”, holding the day's total price less its categories, so every day in
Costfluent equals Twilio's own total. If Twilio adds a total of its own that Costfluent does not
know yet, its categories count twice and “other” turns negative by that much: the day's total stays
right.
:::

## Reporting dimensions

- **Service** is the first part of the usage category, such as `calls`, `sms` or `phonenumbers`,
  with the **Service category** Other.
- **SKU** is the usage category, such as `calls-outbound`, and the charge description Twilio's own,
  such as “Outbound Voice Minutes”.
- The quantity is the record's usage in its unit, such as minutes or messages; “other” has none.
- The billing account and the sub-account are the connected account's Account SID. A parent
  account's rows include its subaccounts' usage and are not split by subaccount.
- Twilio rows carry no resource or tag, their region is Global, and the billing period is the
  calendar month.

## Update or disconnect

### After connecting

The **Manage** tab lists the connection by its display name. Open the gear icon beside it to see
whether the usage records are still readable, which workspaces the connection feeds, and which days
have been imported. **Run checks** runs the checks again on request.

### Rotating or removing access

Twilio does not rotate API keys for you. Create a new restricted key the same way, select **Update
credentials** on the connection page and paste its SID and secret with the same Account SID. A key
that cannot read that account's usage records is refused. Once the connection reads with the new
key, delete the old one in the Twilio Console under “API keys & tokens”.

To retire the connection, remove it in Costfluent, then delete its key. Removing it erases the cost
it imported ([Remove a connection](/connect/manage-connections#remove-a-connection)).

## Troubleshooting

The check's messages say what Twilio answered:

- **A Twilio Account SID is written AC followed by 32 hexadecimal digits.** Copy the Account SID from
  “Account Info” on the Twilio Console's home page.
- **A Twilio API key SID is written SK followed by 32 hexadecimal digits.** Paste the key's SID, not
  the Account SID or an Auth Token.
- **Twilio refused this API key for the account.** The key was deleted, belongs to another account,
  or may not read usage records. Create a restricted key in region US1 of this account that can
  read usage records, as described above, and paste its SID and secret.
- **Twilio found no account … for this API key.** Check the Account SID, and create the key in that
  account.
- **Twilio could not be reached to verify these credentials.** Twilio did not answer, or answered
  with an error of its own, and nothing was saved. Connect again later; for a connection that
  already exists, select **Run checks** later.
- **A sync that ends with "Reconnect it with a restricted API key with Usage Records read".** Twilio
  refused the stored key while collecting: it was deleted or lost its permission. Create a new key
  and select **Update credentials**.

## From your assistant

With the [Costfluent MCP server](/developers/mcp) connected, your assistant answers these with `query_costs`.

```text
Which Twilio usage categories cost the most over the last 30 days?
```

```text
How did our daily Twilio SMS and voice cost change this month compared with last month?
```
