Loading component…
Loading component…
Where an agent's tokens and cost go, as a Sankey diagram of cards – system prompt, tool results and memory flow into the models and on into answered, retried or cancelled
To reuse this local React demo, copy all files from the Code tab into the same folder, then import TokenFlow from ./token-flow.
import { TokenFlow, type TokenLink } from "@/components/ui/token-flow";
const links: TokenLink[] = [
{ from: "system", to: "sonnet", tokens: 9000 },
{ from: "tools", to: "sonnet", tokens: 104000 },
{ from: "sonnet", to: "done", tokens: 98000 },
{ from: "sonnet", to: "retry", tokens: 15000 },
];
export function RunCost() {
return (
<TokenFlow
title="Answer a refund question"
sources={[
{ id: "system", label: "System prompt", kind: "system" },
{ id: "tools", label: "Tool results", kind: "tool", apps: [{ name: "GitHub", path: githubPath }], total: 6 },
]}
models={[{ id: "sonnet", label: "Claude Sonnet 5.5", logo: <ClaudeLogo />, price: 6 }]}
outcomes={[
{ id: "done", label: "Answer delivered", tone: "delivered" },
{ id: "retry", label: "Retried", tone: "retried" },
]}
links={links}
previous={{ tokens: 140000, cost: 0.81 }}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| sources | TokenSource[] | The left column – { id, label, kind?, color?, avatar?, apps?, total?, file? }. kind is system, user, agent, tool, file or memory and picks the icon and the color; avatar is a photo for you; apps – { name, path?, icon?, color?, tile? } – show as up to three overlapping logo tiles and +N for the rest of total; file is the extension printed on the page | |
| models | TokenModel[] | The middle column – { id, label, logo?, price?, color? }. logo is any node on a small white tile (without it the first letter); price is a blended $ per million tokens, shown as $ / 1K in its details; color makes the bands shade into it – without one the model is a quiet hub and its bands soften toward it | |
| outcomes | TokenOutcome[] | The right column – { id, label, tone?, color? }. tone is delivered (green check), retried (orange arrows) or wasted (red cross) | |
| links | TokenLink[] | The bands – { from, to, tokens, cost? }, from a source to a model or from a model to an outcome. Others are left out, the same pair twice is added up | |
| previous | { tokens?, cost? } | The last run's totals – once the run is done the head shows a badge, e.g. −12% vs last run, green when it's less, red when it's more | |
| unit | "tokens" \| "cost" | What the bands' widths and the big number show – controlled; leave it out and the switch keeps its own | |
| defaultUnit | "tokens" \| "cost" | Where the switch starts – default tokens | |
| onUnitChange | (unit) => void | Called when the switch moves | |
| streaming | boolean | The run is still going – the wave sweeps across the bands faster and the pixel marks twinkle | |
| title | string | The name in the head – default Token flow | |
| height | number | The diagram's height in px – default 400; it grows when a column has more cards than fit (from eight on, cards go to one line) | |
| className | string | Extra class on the root – set the color variables on it, e.g. --ui-tfl-k-tool |
Fills its container; narrower than 600px it turns compact – sources and outcomes show their icon and number, models their logo, name and tokens – so all three columns fit a phone; a tap or Enter shows the rest
A column with more than seven cards shows them on one line each, and the diagram grows taller instead of crowding them
Long names end in …; the whole name is in the tooltip, the details and the button's label
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"