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.

Generation stats

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

PropTypeDefaultWhat it does
modelstring—
inputTokens, outputTokens, cachedTokensint—Left out, not shown.
durationint—Milliseconds: "850 ms" is "0.9s", 64 000 is "1m 4s".
tokensPerSecondnumberoutput ÷ duration
costnumber or string—In the currency's units. Under one unit it keeps two significant figures ("$0.0042"). Formatted by Support\Money.
currencystringUSDISO 4217.
finishReasonstring—stop, end_turn, stop_sequence, tool_use and the like show nothing; anything else is a warning badge. max_tokens reads "length".
itemsarray[]More rows, [label => value].
variantinline popover tableinline
compactboolfalseToken counts as 1.2K (the exact count on hover).
localestringthe app's
placementas popover'stop-startWhere the popover opens.
labelstringGeneration detailsNames the list and the info button.
finishTextstringStopped: :reasonThe 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.

Was this page helpful?