# Connect Fastly

Costfluent reads your Fastly spend from your account's invoices, through Fastly's billing API, with
an automation token you create for it. One connection is one Fastly account, which Fastly calls a
customer, and the cost of everything invoiced to it.

## How Costfluent connects

Costfluent collects each closed month's Fastly cost from that month's invoice, and the running
month's from the month-to-date invoice Fastly keeps for it, per product, usage type and region.

Costfluent stores the token encrypted and uses it on `api.fastly.com` for three reads only, and
never for a request that changes anything: the customer the token belongs to, the account's
invoices, and the month-to-date invoice. The customer ID is the connection's identity, and the
token is only ever used for that connection.

Fastly's **Billing** role, which reads invoices, also manages the account's payment details
([User roles and permissions](https://www.fastly.com/documentation/guides/account-info/user-and-account-management/configuring-user-roles-and-permissions/),
read 2026-11-29). An automation token whose only scope is “Read-only access (global:read)” can use
that role to read, not to change anything.

:::caution
Give the token “Read-only access (global:read)” as its only scope, not “Global API access”, which
would let it change your account and services. Costfluent fetches the customer the token belongs to
for its ID alone; it never reads the customer's name or contact details.
:::

## Prerequisites

1. The Owner or Integration owner organization role in Costfluent.
2. A Fastly user with the **Superuser** role: only a superuser can create automation tokens
   ([Using API tokens](https://www.fastly.com/documentation/guides/account-info/user-and-account-management/using-api-tokens/),
   read 2026-11-29).

## Connect

### Create the token in Fastly

<Stepper>

1. Sign in to the Fastly control panel as a superuser, open “Account”, then “API tokens”, and select
   “Create token”. Fastly asks for your password again.
2. Select the “Automation token” card and enter a “Name” that names Costfluent.
3. Choose the “Billing” role, and under “Scope” tick only “Read-only access (global:read)”.
4. Under “Service access”, give the token access to all services: a token limited to some services
   may not read invoices.
5. Choose an “Expiration”. Fastly's default is 90 days, and the token stops working then, so note
   the date to replace it before.
6. Select “Create automation token” and copy the token. Fastly shows it only once.

</Stepper>

### Connect in Costfluent

<Stepper>

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

</Stepper>

Before storing anything, Costfluent reads the customer the token belongs to and then the first page
of its invoices, so a connection that saves can read your invoices. A second connection of the same
customer is refused. If Fastly does not answer during that check, the connection is saved anyway
and checked again automatically.

## Data and freshness

Fastly bills by the month. Costfluent files each invoice line's whole cost on the day its invoice's
billing period starts, the first of the month. Month and longer views are exact; a daily chart shows
each line on that one day, so daily cost for Fastly is not available.

The running month comes from Fastly's month-to-date invoice, and each sync reads it again whole, so
its figures grow through the month. A closed month comes from its posted invoice, which replaces
what the month-to-date invoice showed for it.

:::note
Fastly posts a month's invoice some days after the month ends, and does not say how many. Until it
does, the closed month keeps its month-to-date figures, and the running month waits behind it: it
shows nothing new until the invoice posts. Costfluent checks again each day, and once the invoice is
posted, the closed month takes the invoice's figures and the running month catches up with the
next sync. If no invoice has posted 31 days after the month ends, Costfluent stops waiting for it
and the month shows no Fastly cost.
:::

:::note
Amounts are in the invoice's currency. Each line is its amount as the invoice states it, and the
lines of an invoice add up to its total; an invoice whose lines do not fails its collection, naming
the invoice, and is never recorded in part. A coupon line or a negative line is a credit.
:::

Connecting imports as far back as your plan's backfill reaches, and at most six months
([Manage connections](/connect/manage-connections#how-it-behaves)), for each month Fastly has
invoiced.

## Reporting dimensions

- **Service** is the Fastly product the line names, such as a delivery or compute product, with its
  **Service category**: Networking for Network Services, Security for Security, and Other for any
  other product line.
- **SKU** is the line's product group.
- **Region** is the line's region, and Global for a line without one.
- The usage type, such as bandwidth or requests, is the unit of the line's quantity, and its rate
  the unit price.
- Fastly states money per invoice line, not per Fastly service, so Fastly rows carry no resource
  and cost is not split by service.
- The billing account and the sub-account are the customer, and the billing period is the
  invoice's 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 invoices are still readable, which workspaces the connection feeds, and which months
have been imported. **Run checks** runs the checks again on request.

### Rotating or removing access

Fastly does not rotate the token for you, and it stops working at its expiration. Before then,
create a new token the same way, select **Update credentials** on the connection page and paste it.
A token of another customer is refused. Once the connection reads with the new token, delete the
old one in the control panel: open “Account”, then “API tokens”, and select the trash icon beside it.

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

## Troubleshooting

The check's messages say what Fastly answered:

- **Fastly refused this API token: it is invalid, expired or revoked.** Create a new automation
  token with the Billing role and the global:read scope, as described above, and paste it.
- **This Fastly API token may not read the customer's invoices.** The token lacks the Billing role,
  or is limited to some services. Create a new one with the Billing role, the global:read scope and
  access to all services, as described above, and select **Update credentials**.
- **Fastly could not be reached to verify these credentials.** Fastly did not answer, or answered
  with an error of its own. Select **Run checks** later; a connection saved meanwhile is checked
  again automatically.
- **A sync that ends with "Reconnect it with an automation token with the Billing role".** Fastly
  refused the stored token while collecting: it has expired or was deleted. Create a new token and
  select **Update credentials**.

## From your assistant

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

```text
Which Fastly products and regions cost the most over the last three invoiced months?
```

```text
How does this month's Fastly cost to date compare with last month's invoice, per product?
```
