Context

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.

Installation

pnpm dlx shadcn-svelte@latest add https://svelte-ai-elements.vercel.app/r/context.json

If you prefer using jsrepo, please install via the command below:

pnpm dlx jsrepo add @ai/elements/ai-elements/context

Usage

Props

Context

PropTypeDefaultDescription
usedTokensnumber-Number of tokens currently used
maxTokensnumber-Maximum number of tokens allowed
usageLanguageModelUsage-Detailed token usage breakdown (input, output, reasoning, cached)
modelIdstring-Model identifier for cost estimation
closeDelaynumber0Delay in milliseconds before closing the hover card
openDelaynumber0Delay in milliseconds before opening the hover card
childrenSnippet-Child components (typically ContextTrigger and ContextContent)

ContextTrigger

PropTypeDefaultDescription
variant'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link''ghost'Button variant style
size'default' | 'sm' | 'lg' | 'icon'-Button size
childrenSnippet-Custom trigger content (defaults to percentage display with icon)

ContextContent

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the content container
childrenSnippet-Content to display in the hover card (typically header, body, footer)

ContextContentHeader

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the header
childrenSnippet-Custom header content (defaults to percentage and token count display)

ContextContentBody

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the body
childrenSnippet-Body content (typically usage breakdown components)

ContextContentFooter

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the footer
childrenSnippet-Custom footer content (defaults to total cost display)

ContextInputUsage

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the input usage display
childrenSnippet-Custom content for input token usage display

ContextOutputUsage

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the output usage display
childrenSnippet-Custom content for output token usage display

ContextReasoningUsage

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the reasoning usage display
childrenSnippet-Custom content for reasoning token usage display

ContextCacheUsage

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the cache usage display
childrenSnippet-Custom content for cache token usage display