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

# Charges

> Charges (prices) define how much a customer is billed on a plan — fixed fees and usage-based pricing.

A **Charge** is a price component attached to a plan. Plans can have multiple charges — for example, a base subscription fee plus per-unit charges for multiple usage meters.

## Charge Types

| Type    | Description                                     |
| ------- | ----------------------------------------------- |
| `FIXED` | A flat amount billed each billing period        |
| `USAGE` | A per-unit price, calculated from metered usage |

## Creating a Fixed Charge

```bash theme={null}
curl -X POST https://api.fluxrate.co/api/v1/plans/<plan_id>/charges \
  -H "Content-Type: application/json" \
  -H "Cookie: access_token=<token>" \
  -d '{
    "type": "FIXED",
    "unit_price": 99.00,
    "display_name": "Pro monthly subscription"
  }'
```

## Creating a Usage Charge

```bash theme={null}
curl -X POST https://api.fluxrate.co/api/v1/plans/<plan_id>/charges \
  -H "Content-Type: application/json" \
  -H "Cookie: access_token=<token>" \
  -d '{
    "type": "USAGE",
    "meter_id": "<meter_id>",
    "unit_price": 0.005,
    "display_name": "Storage (per GB)"
  }'
```

## Charge Fields

| Field          | Required           | Description                                           |
| -------------- | ------------------ | ----------------------------------------------------- |
| `type`         | ✅                  | `FIXED` or `USAGE`                                    |
| `unit_price`   | ✅                  | Price per unit (for USAGE) or flat amount (for FIXED) |
| `meter_id`     | Required for USAGE | The meter whose events are aggregated for billing     |
| `display_name` |                    | How the charge appears on invoices                    |

## Managing Charges

### View Plan Charges

```bash theme={null}
GET /api/v1/plans/<plan_id>
```

The response includes a `charges` array with all active charges.

### Deactivate a Charge

```bash theme={null}
curl -X PATCH https://api.fluxrate.co/api/v1/plans/<plan_id>/charges/<charge_id> \
  -H "Content-Type: application/json" \
  -H "Cookie: access_token=<token>" \
  -d '{
    "status": "INACTIVE"
  }'
```

<Warning>
  Charge deactivation is **permanent**. An inactive charge cannot be reactivated. Create a new charge to replace it.

  Status can only transition from `ACTIVE` → `INACTIVE`.
</Warning>

## How Usage Charges are Calculated

At invoice generation time, Fluxrate:

1. Finds all `UsageEvent` records for the linked meter within the billing period
2. Applies the meter's aggregation type (SUM, MAX, UNIQUE\_COUNT, LAST)
3. Multiplies the result by `unit_price`
4. Creates a line item on the invoice

```
Usage = aggregate(events in period, aggregation_type)
Line Item Total = Usage × unit_price
```

## Multiple Charges on One Plan

Plans can have multiple charges of any type:

```
Enterprise Plan
├── Base Fee (FIXED) → $500/month
├── API Calls (USAGE) → $0.0005/call
├── Storage (USAGE) → $0.02/GB
└── Premium Support (FIXED) → $100/month
```

Each charge generates a separate line item on the invoice, giving customers full transparency into what they're being billed for.
