Skip to content

Cost Meter

What a run costs while it streams. The dollars and the token count roll like an odometer, turning only the places that change; the rate comes from the last two seconds, the split shows input, cached and output, and a budget line warns at 80%. When the stream ends, the numbers stay.

On this page
Used for
  • The bill of one run, live
  • A per-run budget
  • Model cost next to an answer
  • Cached versus fresh input

Examples

Model

Installation

Installation is part of Pro

Pro components install from a licensed registry. The live preview stays open to everyone.

Props

usagerequired
{ input, output, cached? }
Tokens so far. Pass new counts as the run streams; the meter works out the rest.
pricerequired
{ input, output, cached? }
US dollars per million tokens. Cached input is billed at the input price when it has none.
streaming
boolean
Defaultfalse
The run is live: the dot is lit and the rate shows. Turning it off announces the total once.
budget
number
A cap for this run in dollars. Amber from 80%, red past it with the overspend named.
label
string
Default"This run"
The run's name in the header and in the region's label.
Format
-
Four decimals under $1, three under $10, two above, so a streaming run always shows a digit turning.
Motion
-
Dollars and tokens on the motion lib's Odometer (MOTION.travel, carried from the right); the split and the budget bar resize on the slow token, ease in-out. Reduced motion: numbers change at once.

Accessibility

  • The meter is a labelled region; the rolling digits are hidden from assistive tech and the plain number is read instead.
  • The total is announced once when the run finishes, never on every tick.
  • The budget state is said in words (82% used, Over by $0.0140), not by colour alone.

What it handles

  1. 01Prices input, cached input and output separately from per-million rates and adds them up as the counts come in.
  2. 02Rolls the dollars and the token count like an odometer, turning only the places that changed and carrying from the right.
  3. 03Shows four decimals under a dollar and three under ten, so a streaming run always has a digit moving.
  4. 04Reads tokens per second from the last two seconds of counts and drops the rate when the stream stops.
  5. 05Draws the input, cached and output split as one thin bar, with each share's tokens and dollars under it.
  6. 06Puts a budget line under the numbers: amber from 80%, red past it with the overspend in dollars.

States

First render
Nothing
none
Streaming
Changed places roll up from below
420ms, ease out, roll
Split or budget changes
The bars resize
280ms, ease in-out
Finished
The rate becomes Done and the total is announced
none on the numbers: they stay
Reduced motion
Numbers change at once
0ms

Works with

When to use

When to use

  • Showing what one agent or chat run costs while it streams, next to the answer.
  • A per-run budget where people should see the spend climb before it crosses the line.

When not to use

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Cost Meter to my app and wire it to my own data.
  • I need showing what one agent or chat run costs while it streams, next to the answer. Set that up with the Knowns UI Cost Meter.
  • Which Cost Meter props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "cost-meter" }) and search_docs({ query: "cost meter" }). Pro props, full examples and source come back once your license key is in the MCP config.

Need help?

Stuck on Cost Meter, or found something off? We read every message.