Loading component…
Loading component…
Where the money and tokens of an agent run go – every LLM call, tool call and sub-agent as a waterfall step, the most expensive on top, with a switch between cost and tokens
To reuse this local React demo, copy all files from the Code tab into the same folder, then import CostWaterfall from ./cost-waterfall.
import { CostWaterfall, type CostStep } from "@/components/ui/cost-waterfall";
const steps: CostStep[] = [
{ id: "plan", name: "Plan the report", kind: "llm", status: "done", model: "Opus 5.5",
tokensIn: 4120, tokensOut: 960, cost: 0.044, duration: 3000,
input: "Write a report on LLM API prices…", output: "1. Research 2. Write 3. Review" },
{ id: "research", name: "Researcher", kind: "agent", status: "running", model: "Gemini 3.8 Flash", duration: 8500,
children: [
{ id: "s1", name: "web_search", kind: "tool", status: "done", detail: "API prices 2026", cost: 0.01, duration: 1300,
input: '{ "query": "LLM API pricing 2026" }', output: "10 results" },
] },
];
export function RunCost() {
return <CostWaterfall steps={steps} task="Report on LLM API prices in 2026" />;
}| Name | Type | Default | Description |
|---|---|---|---|
| steps | CostStep[] | { id, name, kind, status, model?, detail?, icon?, tokensIn?, tokensOut?, cost?, duration?, input?, output?, error?, children? } – the run's steps in order, sub-agents hold theirs as children | |
| kind | "agent" \| "llm" \| "tool" | Per step – picks the bar's tint and what its details are called: Task/Result, Prompt/Response, Input/Output | |
| status | "running" \| "done" \| "failed" | Per step – running steps shimmer, failed ones turn red with their error in the details | |
| cost / tokensIn / tokensOut | number | Per step, its own – sub-agents add up their children, so don't pre-sum. A negative cost is a credit and steps the waterfall back | |
| duration | number | Per step, in ms – how long it took or runs so far | |
| input / output / error | string | Per step – the prompt and response, or the tool's input and output, shown when the row opens | |
| task | string | What the run is about – muted next to the title | |
| status | "running" \| "done" \| "failed" | Overrides the run's state in the bar – by default Live while a step runs | |
| mode / defaultMode | "cost" \| "tokens" | "cost" | What the bars measure, controlled or uncontrolled |
| onModeChange | (mode) => void | The switch was used | |
| collapsed / defaultCollapsed | string[] | [] | Ids of folded sub-agents, controlled or uncontrolled |
| onCollapsedChange | (collapsed: string[]) => void | A sub-agent was folded or opened | |
| openId / defaultOpenId | string \| null | null | The step whose details are open, controlled or uncontrolled |
| onOpenChange | (id: string \| null, step?: CostStep) => void | Details opened (with the step) or closed | |
| maxHeight | number | Long runs: the rows scroll past this height in px | |
| formatCost | (amount: number) => string | dollars, e.g. "$0.042" | Formats every cost |
| title | string | "Run cost" | Heading of the bar |
| className | string | Extra class on the root |
Built on a container query: wide, the steps sit on the left, the waterfall in the middle, the numbers on the right
Under 720px the In and Out columns step aside – in the tokens view the step's tokens take the cost's place
Under 520px each row stacks: name, cost and time on one line, the bar across the whole width under it
Touch screens get larger targets for the switch and the chevrons
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"