Generation stats
The small print under an AI answer: the model, tokens in and out, how long it took, how fast, what it cost, and why it stopped when that was not normal.

No script. Numbers are written in PHP, in the app's locale. The popover
variant is a native disclosure; with Alpine it also closes on Escape and on a
press outside, and with the package's script it stays on screen.
Use it
<x-ds::generation-stats
:model="$message->model"
:inputTokens="$message->input_tokens"
:outputTokens="$message->output_tokens"
:cachedTokens="$message->cache_read_tokens"
:duration="$message->duration_ms"
:cost="$message->cost"
currency="USD"
:finishReason="$message->stop_reason"
/>
Reads "claude-sonnet · 1,234 in · 356 out · 2.4s · 148 tok/s · $0.0042". A stop for any reason but a normal one adds a warning badge, "Stopped: length".
Behind an info button, or as a table:
<x-ds::generation-stats variant="popover" … />
<x-ds::generation-stats variant="table" :compact="true" … :items="['Region' => 'eu-west']" />
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
model | string | — | |
inputTokens, outputTokens, cachedTokens | int | — | Left out, not shown. |
duration | int | — | Milliseconds: "850 ms" is "0.9s", 64 000 is "1m 4s". |
tokensPerSecond | number | output ÷ duration | |
cost | number or string | — | In the currency's units. Under one unit it keeps two significant figures ("$0.0042"). Formatted by Support\Money. |
currency | string | USD | ISO 4217. |
finishReason | string | — | stop, end_turn, stop_sequence, tool_use and the like show nothing; anything else is a warning badge. max_tokens reads "length". |
items | array | [] | More rows, [label => value]. |
variant | inline popover table | inline | |
compact | bool | false | Token counts as 1.2K (the exact count on hover). |
locale | string | the app's | |
placement | as popover's | top-start | Where the popover opens. |
label | string | Generation details | Names the list and the info button. |
finishText | string | Stopped: :reason | The badge. |
Accessibility
- A description list: every number is read with its name ("Input tokens 1,234"), even on the one muted line, where the names are visually hidden and the separators and short units ("in", "tok/s") are not read.
- The info button is named by
label; Escape closes the table and returns focus to it. - The badge is a word, not a colour.
Don't
- Don't stream these. They describe a finished answer; render them once it has finished. The metric ticker and counter are for numbers that move.
- Don't sum costs as floats to pass in. Pass the string your ledger holds.
From the package repo: edit this page on GitHub.