{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-usage-01",
  "description": "Tokens per day stacked by model against the daily average, with the total cost and the cost per million tokens; hovering a day splits it by model.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/ai-usage.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/ai-usage/ai-usage-01.tsx",
      "content": "'use client'\n\nimport {\n  formatTokens,\n  formatUsd,\n  modelPalette,\n} from '@/registry/components/dashboardblocks/ai-usage'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  chartAxisProps,\n  chartBarCursor,\n  chartGridProps,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  Bar,\n  BarChart,\n  CartesianGrid,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface ModelUsage {\n  cost: number\n  id: string\n  label: string\n}\n\ninterface UsageDay {\n  label: string\n  tokens: Record<string, number>\n}\n\ninterface AiUsage1Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  days?: UsageDay[]\n  description: string\n  models?: ModelUsage[]\n  title: string\n}\n\nconst DAYS = [\n  'Sep 13',\n  'Sep 14',\n  'Sep 15',\n  'Sep 16',\n  'Sep 17',\n  'Sep 18',\n  'Sep 19',\n  'Sep 20',\n  'Sep 21',\n  'Sep 22',\n  'Sep 23',\n  'Sep 24',\n  'Sep 25',\n  'Sep 26',\n]\nconst WEEKEND = new Set([0, 1, 7, 8])\n\nconst exampleProps: AiUsage1Props = {\n  days: DAYS.map((label, index) => {\n    const load = WEEKEND.has(index) ? 0.45 : 1 + index * 0.03\n    return {\n      label,\n      tokens: {\n        embeddings: Math.round(3_100_000 * load),\n        fast: Math.round(8_400_000 * load),\n        reasoning: Math.round(2_600_000 * load * (index > 9 ? 1.4 : 1)),\n      },\n    }\n  }),\n  description: 'Tokens per day by model over the last 14 days.',\n  models: [\n    { cost: 1_184, id: 'reasoning', label: 'Reasoning' },\n    { cost: 312, id: 'fast', label: 'Fast' },\n    { cost: 19, id: 'embeddings', label: 'Embeddings' },\n  ],\n  title: 'Token usage',\n}\n\nconst AiUsage1 = (props: AiUsage1Props) => {\n  const { days = [], description, models = [], errorMessage, status, title } = props\n  const state = getBlockState(status, days)\n  const colorOf = (index: number) => modelPalette[index % modelPalette.length]\n  const rows = days.map((day) => ({ label: day.label, ...day.tokens }))\n  const totals = models.map((model) =>\n    days.reduce((sum, day) => sum + (day.tokens[model.id] ?? 0), 0),\n  )\n  const tokens = totals.reduce((sum, value) => sum + value, 0)\n  const cost = models.reduce((sum, model) => sum + model.cost, 0)\n  const average = days.length > 0 ? tokens / days.length : 0\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <dl className='grid grid-cols-2 gap-x-6 gap-y-4 border-t pt-4 @lg:grid-cols-3'>\n              <div className='col-span-2 flex flex-col gap-1 @lg:col-span-1'>\n                <dt className='text-muted-foreground text-sm'>Tokens</dt>\n                <dd>\n                  <KPIValue\n                    className='whitespace-nowrap'\n                    value={tokens}\n                    format={formatTokens}\n                  />\n                </dd>\n              </div>\n              {state !== 'empty' && state !== 'error' && (\n                <>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Cost</dt>\n                    <dd>\n                      <KPIValue className='text-2xl' value={cost} format={formatUsd} />\n                    </dd>\n                  </div>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Per million tokens</dt>\n                    <dd>\n                      <KPIValue\n                        className='text-2xl'\n                        value={tokens > 0 ? (cost / tokens) * 1_000_000 : 0}\n                        format={formatUsd}\n                      />\n                    </dd>\n                  </div>\n                </>\n              )}\n            </dl>\n            <BlockReady className='text-sm'>\n              <div className='flex flex-col gap-1.5'>\n                <p\n                  aria-hidden\n                  className='text-muted-foreground flex items-center gap-1.5 text-xs'\n                >\n                  All {days.length} days, averaging\n                  <span className='tabular-nums'>{formatTokens(average)}</span> a day\n                  <span className='border-foreground/50 w-3 border-t border-dashed' />\n                </p>\n                <ul className='flex flex-wrap gap-x-6 gap-y-2 text-sm'>\n                  {models.map((model, index) => (\n                    <li key={model.id} className='flex items-baseline gap-1.5'>\n                      <span\n                        aria-hidden\n                        className='size-2.5 shrink-0 self-center rounded-[3px]'\n                        style={{ backgroundColor: colorOf(index) }}\n                      />\n                      <span className='text-muted-foreground'>{model.label}</span>\n                      <span className='font-medium tabular-nums'>\n                        {formatTokens(totals[index])}\n                      </span>\n                      <span className='text-muted-foreground text-xs tabular-nums'>\n                        {formatUsd(model.cost)}\n                      </span>\n                    </li>\n                  ))}\n                </ul>\n              </div>\n            </BlockReady>\n            {state ? (\n              <ChartPlaceholder height={240} />\n            ) : (\n              <ChartPanelFigure className='h-60'>\n                <ResponsiveContainer width='100%' height='100%'>\n                  <BarChart\n                    aria-label={`${title} chart`}\n                    data={rows}\n                    margin={{ top: 8, right: 8, bottom: 0, left: 0 }}\n                  >\n                    <CartesianGrid {...chartGridProps} />\n                    <XAxis\n                      {...chartAxisProps}\n                      dataKey='label'\n                      interval='preserveStartEnd'\n                      minTickGap={20}\n                    />\n                    <YAxis\n                      {...chartAxisProps}\n                      tickFormatter={formatTokens}\n                      width={chartValueAxisWidth}\n                    />\n                    <Tooltip\n                      content={(tooltipProps) => (\n                        <ChartTooltipContent\n                          {...tooltipProps}\n                          valueFormatter={formatTokens}\n                        />\n                      )}\n                      cursor={chartBarCursor}\n                    />\n                    {models.map((model, index) => (\n                      <Bar\n                        key={model.id}\n                        dataKey={model.id}\n                        fill={colorOf(index)}\n                        name={model.label}\n                        radius={index === models.length - 1 ? [4, 4, 0, 0] : 0}\n                        stackId='tokens'\n                      />\n                    ))}\n                    {average > 0 && (\n                      <ReferenceLine {...chartReferenceProps} y={average} />\n                    )}\n                  </BarChart>\n                </ResponsiveContainer>\n              </ChartPanelFigure>\n            )}\n            {!state && (\n              <ChartPanelTable\n                caption={`${title}: ${description}`}\n                columns={[\n                  { key: 'label', label: 'Day' },\n                  ...models.map((model) => ({\n                    format: formatTokens,\n                    key: model.id,\n                    label: model.label,\n                  })),\n                ]}\n                rows={rows}\n              />\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport {\n  AiUsage1,\n  exampleProps as aiUsage1ExampleProps,\n  type AiUsage1Props,\n  type ModelUsage,\n  type UsageDay,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/ai-usage/ai-usage-01.tsx"
    }
  ],
  "meta": {
    "shows": "Tokens per day stacked by model against the daily average, with the total cost and the cost per million tokens; hovering a day splits it by model.",
    "size": "full",
    "usedWith": [
      "ai-usage-02",
      "ai-usage-03",
      "ai-usage-04"
    ],
    "component": "AiUsage1",
    "props": "{ days?: { label: string; tokens: Record<string, number> }[]; description: string; models?: { cost: number; id: string; label: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
