Token Counter
Display and track token usage with cost estimation for AI model interactions. Features progress bar, breakdown by input/output, and visual warnings when approaching limits.
Preview
Installation
Usage
Examples
With Cost Estimation
Warning States
Safe (< 70%)
Warning (70-90%)
Danger (> 90%)
Different Models with Pricing
GPT-4 (expensive)
GPT-3.5 Turbo (affordable)
Compact Variant
Custom Thresholds
Customize when warnings appear (50% warning, 75% danger):
Without Cost Display
Props
| Name | Type | Default | Description |
|---|---|---|---|
inputTokensRequired | number | — | |
outputTokensRequired | number | — | |
maxTokens | number | 4096 | |
inputCostPer1K | number | 0.03 | |
outputCostPer1K | number | 0.06 | |
showCost | boolean | true | Display cost estimate |
showBreakdown | boolean | true | |
variant | 'default' | 'compact' | 'default' | |
warningThreshold | number | 70 | Percentage of limit to show warning (default: 0.8) |
dangerThreshold | number | 90 | |
isRTL | boolean | false | |
label | string | — | |
labelAr | string | — |
Accessibility
Screen Reader
The component includes descriptive labels and tooltips. Token counts and costs are formatted with proper number formatting for screen readers.
Visual Indicators
Multiple visual cues indicate status: progress bar color, warning badge, and border color changes. This ensures warnings are visible even without relying solely on color.
Tooltips
Info icon provides context about tokens. Cost tooltip breaks down input/output costs separately for transparency.
Related Components
Choose AI models with different token limits
Adjust max tokens parameter
Display messages that consume tokens