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

# Aggregation Types

> How Fluxrate aggregates raw usage events into billable quantities — SUM, MAX, UNIQUE_COUNT, and LAST.

Each meter uses one **aggregation type** to collapse all usage events in a billing period into a single billable number.

## SUM

Adds all event values together.

**When to use**: Counting discrete actions — API calls, messages sent, tasks executed, tokens generated.

```
Events: 100, 250, 50, 600
SUM = 1,000
```

**SDK tracking:**

```json theme={null}
{
  "meter_token": "...",
  "customer_external_id": "cust_123",
  "quantity": 100
}
```

***

## MAX

Takes the highest single value observed during the period.

**When to use**: Peak capacity measurements — max concurrent connections, peak storage used at any point, highest queue depth.

```
Events: 15, 42, 7, 38, 55, 12
MAX = 55
```

**SDK tracking:**

```json theme={null}
{
  "meter_token": "...",
  "customer_external_id": "cust_123",
  "quantity": 55
}
```

***

## UNIQUE\_COUNT

Counts the number of **distinct values** of a specified property.

**When to use**: Monthly active users, unique API consumers, distinct items processed, unique devices.

```
Events (user_id property): user_a, user_b, user_a, user_c, user_b
UNIQUE_COUNT = 3 (user_a, user_b, user_c)
```

<Note>
  For `UNIQUE_COUNT` meters, the SDK endpoint reads `user_id` from the event `metadata`. Make sure to include it:

  ```json theme={null}
  {
    "meter_token": "...",
    "customer_external_id": "cust_123",
    "quantity": 1,
    "metadata": {
      "user_id": "end_user_456"
    }
  }
  ```
</Note>

***

## LAST

Takes the **most recent** event value received during the period.

**When to use**: Snapshot-based billing — current storage GB, current number of active seats, current record count.

```
Events (with timestamps):
  10:00 → 50 GB
  14:00 → 75 GB
  18:00 → 60 GB
LAST = 60 GB
```

**SDK tracking** (send current state periodically):

```json theme={null}
{
  "meter_token": "...",
  "customer_external_id": "cust_123",
  "quantity": 60,
  "timestamp": "2025-01-15T18:00:00Z"
}
```

***

## Choosing the Right Aggregation

| Use Case                   | Recommended Type |
| -------------------------- | ---------------- |
| API call billing           | SUM              |
| Data transferred           | SUM              |
| AI token usage             | SUM              |
| Monthly active users       | UNIQUE\_COUNT    |
| Storage billing (current)  | LAST             |
| Seat-based billing (peak)  | MAX              |
| Concurrent connection peak | MAX              |
| Messages processed         | SUM              |
| Inference requests         | SUM              |
