> ## 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.

# ClickHouse Billing Setup

> Connect ClickHouse Cloud billing data to Costory to analyze compute, storage, and data transfer costs.

> [tab] Terraform
>
> To install and authenticate the provider, see [Terraform setup](https://docs.costory.io/setup/terraform.md).
>
> ```hcl theme={null}
> terraform {
>   required_providers {
>     costory = {
>       source  = "costory-io/costory"
>       version = ">= 0.1.0"
>     }
>   }
> }
>
> variable "costory_api_token" {
>   type        = string
>   description = "Costory API token."
>   sensitive   = true
> }
>
> variable "clickhouse_cloud_key_secret" {
>   type        = string
>   description = "ClickHouse Cloud API key secret."
>   sensitive   = true
> }
>
> provider "costory" {
>   token = var.costory_api_token
> }
>
> resource "costory_billing_datasource_clickhouse_cloud" "main" {
>   name            = "ClickHouse Cloud Billing"
>   key_id          = "key-id"
>   key_secret      = var.clickhouse_cloud_key_secret
>   organization_id = "org-123"
> }
> ```

> [tab] Manual setup
>
> Open Costory and go to **Billing > Import new billing datasource > ClickHouse**. The stepper guides you through each field.
>
> 1. Generate a **ClickHouse Cloud API Key** and Secret with billing/organization read access.
> 2. Provide your **Organization ID**, **API Key**, and **API Secret** in the Costory stepper.
>
> On first sync, Costory backfills historical usage and service data.

**What Costory includes**

Costory ingests your daily usage metrics and translates them directly into standardized FinOps dimensions.

* **Compute & Storage costs:** Direct visibility into `computeCHC`, `storageCHC`, and `backupCHC` charges.
* **Data Transfer metrics:** Breakdown of networking costs including `dataTransferCHC`, `publicDataTransferCHC`, and `interRegion` tier transfers.
* **Service & Resource context:** Breakdowns by `dataWarehouseId`, `serviceId`, environment `state`, and `provider`.
* **Custom Tags:** Any service tags applied in ClickHouse are automatically ingested as Costory labels (prefixed with `clickhouse_`).

**What Costory does not include**

* **ClickHouse Open Source / Self-managed:** Only ClickHouse Cloud is supported.
* **Taxes and support fees:** Non-usage invoice items are not currently mapped from the usage metrics API.

**How to analyze ClickHouse costs**

* **Per-Service or per-Cluster spend:** Group by **Resource name** (Service display name) or **Resource ID** (`entityId`).
* **Spend by Metric:** Group by **SKU** to compare `compute`, `storage`, and `dataTransfer` costs.
* **By Environment:** Group by the `service_state` label or any custom `clickhouse_*` labels you have defined in your infrastructure.

> [!NOTE]
>
> ClickHouse metrics are recorded in ClickHouse Credits (`CHC`) and converted to a standard currency. Costory normalizes these values so they sit alongside your AWS, GCP, and Azure spend.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.