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

# Anthropic Billing Setup

> Connect Anthropic API and subscription billing data to Costory via Admin API key or Terraform.

<Tabs>
  <Tab title="Terraform">
    ```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 "anthropic_admin_api_key" {
      type        = string
      description = "Anthropic admin API key used to fetch billing data."
      sensitive   = true
    }

    provider "costory" {
      token = var.costory_api_token
    }

    resource "costory_billing_datasource_anthropic" "main" {
      name          = "Anthropic Billing"
      admin_api_key = var.anthropic_admin_api_key
    }
    ```
  </Tab>

  <Tab title="Manual setup">
    Open Costory and go to **Billing > Import new billing datasource > Anthropic**. The stepper guides you through each field.

    1. Generate an **Anthropic Admin API key** in your organization admin settings.
    2. Provide a datasource name and the **Admin API key** in the Costory stepper.

    On first sync, Costory backfills up to **12 months** of historical usage data.
  </Tab>
</Tabs>

**What Costory includes**

* **API usage** and **subscription usage** from Anthropic billing exports.
* **Included plan usage** labeled as `Included<subscription_type>` in
  **Charge description** (for Business/Enterprise plans).
* **Per-model breakdown** (group by **Service name** = model).
* **Per-actor attribution** using user email or API key name.

**What Costory does not include**

* **Taxes, credits, and adjustments** outside usage line items.
* **Non-usage fees** that do not appear in the Anthropic billing export.

**How to analyze Anthropic costs**

* **Included vs API usage:** filter by **Charge description**:
  * `Included<subscription_type>` for subscription usage.
  * `API` for pay-as-you-go usage.
* **Per-user email spend:** group by **Resource name** or **Sub account id**
  (mapped to the actor email or API key name).
* **Per-model costs:** group by **Service name** (model) and break down by
  **SKU** (`input` vs `output` tokens).

<Note>
  Anthropic costs are attributed to **input tokens**. Output token rows are
  included for usage analysis but have \$0 cost.
</Note>
