Token Usage

How much of a context window is spoken for. The colour crosses to amber at 75% and destructive at 90%, because the number only matters once it is close.

src/components/ui/token-usage.tsx

About

From the component's own source, where it was written.

How much of a context window is spoken for.

The colour crosses to amber at 75% and destructive at 90%, because the number only matters once it is close — a green bar at 12% is noise, an amber one at 80% is a warning you can act on before the conversation truncates.

Install

npx astralyx-ui add token-usage

Usage

import { TokenUsage } from '@/components/ui/token-usage'

<TokenUsage used={18400} limit={200000} />

Composer

Change the props and the source below follows.

Context used18k / 200k
Props
tsx
<TokenUsage used={18400} limit={200000} />

Examples

Across the thresholds

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

TokenUsage

How much of a context window is spoken for.

Extends ComponentProps<'div'>.

PropTypeDefaultDescription
usednumberrequiredToken counts. The share is clamped at 100%.
limitnumberrequiredToken counts. The share is clamped at 100%.
labelstring'Context used'Text on the left.
size'sm' | 'default' | 'lg''sm'—
showNumbersbooleantrueThe compact "18.4k / 200k" readout.

Behaviour

TopicDetailDescription
thresholds75% / 90%Where the bar turns amber, then destructive.