# Usage breakdown

Who and what is driving usage and what changed: ranked by member, model or feature, compared with the period before, and drillable.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Usage breakdown. Six members over half a year. One member's agent runs doubled her spend; click her row to see which model. Preview: https://chatcn.dev/preview/usage-breakdown-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/usage-breakdown
```

## Usage

```tsx
import { UsageBreakdown } from "@/components/ui/chatcn/pro/usage-breakdown"

<UsageBreakdown
  records={records}   // { day, model, member, feature, cost, tokens, requests }, one per day and group
  ranges={[7, 30, 90]}
  defaultMetric="cost"
  defaultDimension="member"
  currency="USD"
/>
```

Pick spend, tokens or requests and a range. Rows rank members, models or features by that metric with their share of the total, a small trend across the range and the change against the same number of days before; groups with nothing before are marked New. Click a row to look inside it: a member opens their models, a model opens its features, and each step stays as a filter chip that can be removed. It answers the follow up questions to `cost-explorer`, which charts spend by day. Records are summed in the browser, so pass daily rollups, not raw requests.

## Examples

### States

Example: States. Tokens by model over 90 days, a range with no usage, and a narrow frame. Preview: https://chatcn.dev/preview/usage-breakdown-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `records` | `UsageRecord[]` | `{ day, model, member, feature, cost, tokens, requests }` |
| `ranges`, `defaultRange` | `number[]`, `number` | In days; default 7, 30 and 90 |
| `defaultMetric` | `"cost" | "tokens" | "requests"` |  |
| `defaultDimension` | `"member" | "model" | "feature"` |  |
| `now` | `Date` | The last day of every range |
| `currency`, `locale` | `string` | Formatting |
| `labels` | `Partial<UsageBreakdownLabels>` | Every string, for translation |

## Accessibility

- Metric, range and breakdown are native radio groups.
- Each row is a button named with its value, share and what clicking it shows.
- Changes read as up or down, not only as an arrow.

## Motion

None.

Source: https://chatcn.dev/docs/components/usage-breakdown