Generation stats

The small print under an AI answer: model, tokens, time, speed, cost, and an unusual stop. No live counting; numbers formatted in PHP.

Anatomy

inline:  div[data-ds-generation-stats=inline]
         ├── dl[aria-label]  div(sep "·" aria-hidden, dt.sr-only, dd value + unit aria-hidden) …
         └── badge (warning) "Stopped: length"

table:   div > dl.grid  dt / dd …  (+ "Finished" / badge)

popover: div[data-ds-generation-stats=popover]
         ├── details[x-data][toggle, click.outside, focusout, Escape]
         │   ├── summary  info icon + sr-only label
         │   └── div  popover surface, x-ds-anchor, placement classes as fallback
         │       └── p label + the table
         └── badge

Formatting

  • tokens: Chart::format, grouped ("1,234"), or compact ("1.2K") with the exact count as the value's title
  • duration (ms): AgentState::duration short ("2.4s", "1m 4s"), the long form as title
  • speed: output ÷ seconds when not given, "148 tok/s"
  • cost: Support\Money with the currency's symbol; under one unit, enough places for two significant figures (at most six)
  • finish reason: stop, end_turn, stop_sequence, eos, complete(d), tool_use, tool_calls, function_call, pause_turn are normal; anything else is a warning badge (finishText), max_tokens worded "length"

The popover

A native details: with no script, its summary opens and closes it, the panel absolutely placed (placement, top-start by default). Inline Alpine (no shared behaviour) mirrors open and closes it on a press outside, on focus leaving, and on Escape (stopping it only when it consumed it, and returning focus to the summary). x-ds-anchor, an enhancement, keeps it on screen. The panel grows in from @starting-style, motion-safe.

Accessibility

Rolea description list (dl) named by label
Nameeach value by its dt (visually hidden inline)
Keyboardpopover: Tab to the info button, Enter or Space opens, Escape closes
Focusthe info button draws the system ring

Do not

  • Do not render bare numbers. Every value has its label.
  • Do not count up. These describe a finished answer.

From the package repo: edit this page on GitHub.

Was this page helpful?