Skip to content

UsagePage ​

What the agent CLIs of a host cost over a period: a total, a chart per day or hour, token tiles, a breakdown by model, folder and day, and the plan limits. The host scans the transcripts; the page only asks.

tsx
import { UsageDialog, UsagePage } from '@adecore/agents-react/usage';
tsx
import { UsageDialog, UsageLimitsCard, UsagePage } from '@adecore/agents-react/usage';
import { Button, ErrorBoundary } from '@adecore/ui';
import { useState } from 'react';
import { AgentDemo } from '../shared/agents.tsx';

export default function UsagePageDemo() {
    const [open, setOpen] = useState(false);

    return (
        <AgentDemo>
            <div className="flex items-center gap-2">
                <Button variant="primary" onClick={() => setOpen(true)}>
                    Open usage
                </Button>
                <UsageLimitsCard>
                    <Button variant="secondary">Plan limits</Button>
                </UsageLimitsCard>
            </div>
            <UsageDialog open={open} onOpenChange={setOpen}>
                <ErrorBoundary label="Usage">
                    <UsagePage />
                </ErrorBoundary>
            </UsageDialog>
        </AgentDemo>
    );
}
tsx
<UsageDialog open={open} onOpenChange={setOpen}>
    <ErrorBoundary label="Usage">
        <UsagePage key={scope.id} />
    </ErrorBoundary>
</UsageDialog>

UsageDialog is the frame; its content mounts only while open. UsagePage is the body and reads the host of its scope. Give it a key per host, since a picked account belongs to one host.

What it asks ​

While mounted, the page sends usage.subscribe, asks usage.summary for the period on screen, asks again on every usage.changed, and sends usage.unsubscribe on unmount. A failed request keeps the old numbers and says so. Without a connection it shows the last numbers or an empty state.

ChoiceValuesKept
Periodtoday (per hour), 7d, 30d, 90d (per day)Yes, 7d
Metriccost, tokensYes, cost
CurrencyUSD, EUR at the rate the summary carriesYes, USD
AccountAll, or one account once a CLI has severalNo

The period follows the viewer's calendar days and time zone. windowFor(period) builds that window, and dayOf(date) writes a date as the viewer's own YYYY-MM-DD. A period is a UsagePeriod and a metric a UsageMetric. The price table is in dollars, and the page can also show euros.

Props ​

PropType
pickersReactNodeControls of your own, first in the header, such as a picker of the host.
notice(stale: boolean) => ReactNodeA line over the numbers about the host; stale is true while older numbers show.

UsagePane ​

The usage section of the settings dialog: the currency and a button to the page. onOpenPage lets your app swap the settings for the usage dialog.

tsx
import { UsagePane } from '@adecore/agents-react/usage';
import { useState } from 'react';
import { AgentDemo } from '../shared/agents.tsx';

export default function UsagePaneDemo() {
    const [asked, setAsked] = useState(0);

    return (
        <AgentDemo>
            <div className="flex w-full max-w-xl flex-col gap-2">
                <UsagePane onOpenPage={() => setAsked((count) => count + 1)} />
                <p className="text-xs text-text-muted">
                    {asked === 0 ? 'The app opens the usage page from here.' : `Asked to open the usage page ${asked} times.`}
                </p>
            </div>
        </AgentDemo>
    );
}
tsx
<UsagePane onOpenPage={() => openUsage()} />

State ​

useUsageStore holds the three stored choices and, per scope, the summary, its request, its loading or failed state and the plan limits. askedKey(payload) is a summary's key. useUsage(select) reads the viewer's choices together with the summary and limits of the scope in context. The page draws a picked host as a scope of its own, so browsing another host's spend never moves the limit bars outside it.

Licenses and third-party notices are listed in each package.