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

# Cloudflare Billing Setup

> Connect Cloudflare PayGo billing to Costory with an API token and Account ID. Self-serve usage only, not enterprise contract billing.

Workers, R2, and other PayGo products often sit on a separate bill from AWS, GCP, and Azure. Connect Cloudflare with an **API token** and **Account ID** so that spend lands in [Explorer](/features/cost-explorer) with your other [billing datasources](/setup/billing).

This connector imports **PayGo** (self-serve) usage only.

<Warning>
  PayGo and self-serve accounts only. Enterprise contract billing is not on the public usage API. Validation fails with a coverage error if the account is not covered.
</Warning>

<Tabs>
  <Tab title="Manual setup">
    <Steps>
      <Step title="Create an API token">
        In [Cloudflare Dashboard > My Profile > API Tokens](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/), create a token. Permission: **Account / Billing / Read**, scoped to this account. Copy the token immediately. It is shown once. Global API keys and Origin CA keys will not work.
      </Step>

      <Step title="Copy the Account ID">
        Copy the **Account ID** from the dashboard Overview page (right-hand sidebar) or from the URL (`/accounts/<account-id>/...`). It is 32 hex characters.
      </Step>

      <Step title="Connect in Costory">
        Go to [Integrations](https://app.costory.io/integration), click **+ Add integration**, then choose **Cloudflare** under **Billing**. The connect URL is `/integration/new/cloudflare/billing`.&#x20;
      </Step>

      <Step title="Enter connection details">
        Fill **Connection name** (default **Cloudflare**), **API token**, and **Account ID**. **Start date** is optional. Leave it empty to use Costory's default lookback.
      </Step>

      <Step title="Validate, then save">
        Click **Validate**. Costory calls `GET /client/v4/accounts/<account-id>/billing-usage/info` with `Authorization: Bearer`. **Save** stays disabled until the token can read PayGo billing for that account. If this is the only billing source and it is demo data, Costory asks you to confirm before replacing it.
      </Step>
    </Steps>

    On first sync, Costory backfills up to **12 months** of PayGo usage, depending on what Cloudflare retains. New data then follows the usual [data refresh](/docs/data-refresh) cadence. SaaS sources typically appear in about **10 minutes**.
  </Tab>

  <Tab title="Terraform">
    Not supported yet.
  </Tab>
</Tabs>

## Field reference

| Field               | Required | Description                                                                  |
| ------------------- | -------- | ---------------------------------------------------------------------------- |
| **Connection name** | Yes      | Label in **Integrations**.                                                   |
| **API token**       | Yes      | Token with **Account / Billing / Read**. Stored in Costory's secret manager. |
| **Account ID**      | Yes      | 32-character Cloudflare account id.                                          |
| **Start date**      | No       | Optional start of the first sync. Leave empty for the default lookback.      |

## What Costory includes

Costory pulls PayGo billable usage from Cloudflare's [usage API](https://developers.cloudflare.com/api/resources/billing/subresources/usage/methods/get_account_usage_info_v1/) and maps it into [Standard Columns](/docs/standard-columns).

Typical lines include usage for PayGo products on that account (Workers, R2, and other products Cloudflare returns on the usage API).

**How to analyze Cloudflare costs**

* Spend by product: group by **Service name** or **SKU**
* Spend over time: use the same date presets as other billing sources in Explorer

**What Costory does not include**

* Enterprise contract invoices and committed-use billing (not on the public PayGo API)
* Taxes, credits, or invoice adjustments outside the usage API
* Zone-level analytics that are not billed on PayGo usage

<Info>
  Rotate the API token from **Integrations** when you need a new credential. The Account ID stays the same.
</Info>

## Troubleshooting

| Issue                                     | What to check                                                                                                                      |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Failed to authenticate                    | Confirm you pasted an **API token**, not a Global API key or Origin CA key. Recreate the token with **Account / Billing / Read**.  |
| Account not found                         | Confirm the **Account ID** is 32 hex characters from Overview, not a zone id.                                                      |
| Coverage / access denied                  | The account is not on PayGo. Enterprise contract billing is not available yet.                                                     |
| Validation succeeds but Explorer is empty | Wait for the first sync (about 10 minutes). Check the datasource date range on [Integrations](https://app.costory.io/integration). |

## Related pages

<CardGroup cols={2}>
  <Card title="Billing Data" icon="database" href="/setup/billing">
    All billing providers and shared setup notes.
  </Card>

  <Card title="Explorer" icon="chart-line" href="/features/cost-explorer">
    Filter and group Cloudflare spend with the rest of your stack.
  </Card>

  <Card title="Standard Columns" icon="book" href="/docs/standard-columns">
    Normalized cost fields across providers.
  </Card>

  <Card title="Scaleway billing" icon="server" href="/setup/billing/scaleway">
    Import Scaleway consumption the same way.
  </Card>
</CardGroup>
