File: context.md | Updated: 11/15/2025
Slash Forward
Docs Cookbook Providers Playground AI ElementsAI ElementsLeft sparkleRight sparkle AI GatewayGateway
Search...⌘KFeedback GitHub Vercel LogoSign in with Vercel
Chatbot
A compound component system for displaying AI model context window usage, token consumption, and cost estimation.
The Context component provides a comprehensive view of AI model usage through a compound component system. It displays context window utilization, token consumption breakdown (input, output, reasoning, cache), and cost estimation in an interactive hover card interface.
Preview
Code
31.3%
AI Elements
shadcn CLI
Manual
npx ai-elements@latest add context
tokenlens library<Context />Prop
Type
maxTokens?number
usedTokens?number
usage?LanguageModelUsage
modelId?ModelId
...props?ComponentProps<HoverCard>
<ContextTrigger />Prop
Type
children?React.ReactNode
...props?ComponentProps<Button>
<ContextContent />Prop
Type
className?string
...props?ComponentProps<HoverCardContent>
<ContextContentHeader />Prop
Type
children?React.ReactNode
...props?ComponentProps<div>
<ContextContentBody />Prop
Type
children?React.ReactNode
...props?ComponentProps<div>
<ContextContentFooter />Prop
Type
children?React.ReactNode
...props?ComponentProps<div>
All usage components (ContextInputUsage, ContextOutputUsage, ContextReasoningUsage, ContextCacheUsage) share the same props:
Prop
Type
children?React.ReactNode
className?string
...props?ComponentProps<div>
The Context component uses a compound component pattern with React Context for data sharing:
<Context> - Root provider component that holds all context data<ContextTrigger> - Interactive trigger element (default: button with percentage)<ContextContent> - Hover card content container<ContextContentHeader> - Header section with progress visualization<ContextContentBody> - Body section for usage breakdowns<ContextContentFooter> - Footer section for total costThe component uses Intl.NumberFormat with compact notation for automatic formatting:
When a modelId is provided, the component automatically calculates costs using the tokenlens library:
Costs are formatted using Intl.NumberFormat with USD currency.
The component uses Tailwind CSS classes and follows your design system:
currentColor for theme adaptationtext-xs class for consistencyConfirmation
An alert-based component for managing tool execution approval workflows with request, accept, and reject states.
Conversation
Wraps messages and automatically scrolls to the bottom. Also includes a scroll button that appears when not at the bottom.
On this page
Installation
Features
Props
<Context />
<ContextTrigger />
<ContextContent />
<ContextContentHeader />
<ContextContentBody />
<ContextContentFooter />
Usage Components
Component Architecture
Token Formatting
Cost Calculation
Styling
GitHubEdit this page on GitHub Scroll to topCopy pageOpen in chat