LLM cost calculator
Interactive LLM API pricing calculator with rolling monthly total, workload presets, three discrete token and traffic sliders, a prompt-caching switch, live re-ranking model rows with proportional bars, and a four-part cost breakdown.
import { LLMCostCalculator } from '@uthereal/ui/llm-cost-calculator'Llmcost calculator playground
Estimated monthly cost
$4,437 per month with Claude Sonnet 5.5
Overview
LLMCostCalculator compares monthly API spend across models for any token and traffic workload. Readers jump between workload shortcuts (Chat, RAG, Agent, Batch, plus an auto-highlighting Custom segment), adjust Input tokens per request, Output tokens per request, and Requests per day on discrete sliders, and toggle Cached input to bill cacheHitRate of input tokens at each model’s cache read rate.
Every model re-ranks live from lowest to highest monthly cost inside a fixed-height stage. Rows glide to their new rank on a bounce-free spring while proportional bars resize and rolling prices count in place. Selecting any row updates the header total, the footer breakdown (Input, Cached, Output, Per request), and the selected model’s per-1M token rate line. All arithmetic runs purely locally via the exported computeLLMCost helper.
Use LLMCostCalculator on pricing pages, model selection settings, and internal FinOps tools. For configuring budget caps and spend notifications after choosing a model, use Spend alert. For nudging a workspace when it hits a usage allowance, use Upgrade prompt.
Usage
'use client'
import { useState } from 'react'
import {
LLMCostCalculator,
computeLLMCost,
type LLMModelPrice,
type LLMUsage,
} from '@uthereal/ui/llm-cost-calculator'
const models: LLMModelPrice[] = [
{
id: 'claude-sonnet-5-5',
name: 'Claude Sonnet 5.5',
provider: 'Anthropic',
brand: 'claude',
color: '#D97757',
input: 3,
cachedInput: 0.3,
output: 15,
},
{
id: 'gpt-6-luna',
name: 'GPT-6 Luna',
provider: 'OpenAI',
brand: 'openai',
input: 0.25,
cachedInput: 0.025,
output: 3,
},
]
export function ModelBudgetEstimator() {
const [usage, setUsage] = useState<LLMUsage>({
inputTokens: 16_000,
outputTokens: 500,
requestsPerDay: 5000,
cached: true,
})
return (
<LLMCostCalculator
models={models}
usage={usage}
onUsageChange={setUsage}
cacheHitRate={0.7}
description="List prices per 1M tokens, checked October 2026"
onSelectedChange={(_id, model) => {
const estimate = computeLLMCost(model, usage, { cacheHitRate: 0.7 })
console.log(model.name, estimate.total)
}}
/>
)
}Exported computeLLMCost(model, usage, { cacheHitRate, daysPerMonth }) is server-safe and deterministic, returning { input, cachedInput, output, total, perRequest } in US dollars so backend estimates and quotes match the panel exactly.
Examples
High-volume agent workload with caching
Start on a heavy multi-step agent workload (64,000 input tokens, 2,000 output tokens, 25,000 requests/day) with cacheHitRate={0.85} and defaultSelected="claude-opus-5-5" to illustrate compact $100K+ row formatting alongside the full-precision hero total.
Agent fleet monthly estimate
$93,900 per month with Claude Opus 5.5
Pricing feed error state
Pass error and retryAction (or React onRetry) when a live pricing API fails. Controls disable, placeholders hold the hero and breakdown steady, and the stage displays an inline error with a Try again button at the exact same height.
Estimated monthly cost
Prices unavailable
Pricing math and states
Workload axes and slider stops
| Control | Discrete stops | Unit spoken by aria-valuetext |
|---|---|---|
| Input tokens per request | 250 to 200,000 (11 stops) | {n} input tokens |
| Output tokens per request | 100 to 16,000 (8 stops) | {n} output tokens |
| Requests per day | 100 to 1,000,000 (13 stops) | {n} requests |
| Cached input | Boolean Switch applying cacheHitRate (0–1) to cachedInput | Switch state + caption text |
Controlled usage values between slider stops still compute exact costs; each slider displays its nearest stop.
Panel states
| State | Trigger | Behavior |
|---|---|---|
list | Default (models > 0) | Ranked radio group (lowest monthly cost first, stable tie-breaking), live bars, and footer breakdown. |
loading | loading={true} | Sets aria-busy, disables all controls, and renders pulsing skeleton rows matching exact list height. |
error | error string set | Disables controls and renders an icon, "Prices did not load", reason copy, and optional Try again. |
empty | models={[]} | Disables controls and shows "No models to compare" inside the fixed-height stage. |
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
title | stringDefault: "Estimated monthly cost" | Heading of the panel. |
description | stringDefault: "Sample list prices per 1M tokens, October 2026" | Line under the heading; say where your prices come from and when they were checked. |
note | stringDefault: "Sample prices for illustration, not a quote. Calculated in your browser, nothing was sent." | Fine print at the bottom of the panel. |
models | LLMModelPrice[]Default: [{"id":"claude-opus-5-5","name":"Claude Opus 5.5","provider":"Anthropic","brand":"claude","color":"#D97757","input":5,"cachedInput":0.5,"output":25},{"id":"claude-sonnet-5-5","name":"Claude Sonnet 5.5","provider":"Anthropic","brand":"claude","color":"#D97757","input":3,"cachedInput":0.3,"output":15},{"id":"claude-haiku-5-5","name":"Claude Haiku 5.5","provider":"Anthropic","brand":"claude","color":"#D97757","input":1,"cachedInput":0.1,"output":5},{"id":"gpt-6-1-sol","name":"GPT-6.1 Sol","provider":"OpenAI","brand":"openai","input":2.5,"cachedInput":0.25,"output":20},{"id":"gpt-6-luna","name":"GPT-6 Luna","provider":"OpenAI","brand":"openai","input":0.25,"cachedInput":0.025,"output":3},{"id":"gemini-4-argon","name":"Gemini 4 Argon","provider":"Google","brand":"google","input":2,"cachedInput":0.5,"output":12},{"id":"gemini-3-8-flash","name":"Gemini 3.8 Flash","provider":"Google","brand":"google","input":0.3,"cachedInput":0.075,"output":2.5},{"id":"deepseek-v4-1-flash","name":"DeepSeek V4.1 Flash","provider":"DeepSeek","brand":"deepseek","input":0.2,"cachedInput":0.02,"output":0.8}] | Models to compare with prices in US dollars per 1M tokens. Defaults to an eight-model sample lineup (Claude, GPT, Gemini, DeepSeek, October 2026 prices). An empty array shows the empty state. |
defaultUsage | LLMUsageDefault: {"inputTokens":16000,"outputTokens":500,"requestsPerDay":5000,"cached":true} | Starting workload when uncontrolled; defaults to the RAG preset (16,000 input tokens, 500 output tokens, 5,000 requests a day, cached). Edits do not reset a mounted instance. |
defaultSelected | string— | Model id selected on first render; defaults to the second model; falls back to the cheapest when not in models. |
presets | LLMUsagePreset[]Default: [{"id":"chat","label":"Chat","usage":{"inputTokens":2000,"outputTokens":500,"requestsPerDay":10000,"cached":false}},{"id":"rag","label":"RAG","usage":{"inputTokens":16000,"outputTokens":500,"requestsPerDay":5000,"cached":true}},{"id":"agent","label":"Agent","usage":{"inputTokens":64000,"outputTokens":2000,"requestsPerDay":2500,"cached":true}},{"id":"batch","label":"Batch","usage":{"inputTokens":8000,"outputTokens":250,"requestsPerDay":50000,"cached":false}}] | Workload shortcuts shown as a segmented control, plus an auto-highlighting Custom segment when the sliders match no preset. |
cacheHitRate | numberDefault: 0.6 | Share of input tokens billed at the cached rate while Cached input is on, 0 to 1; shown beside the switch as a percentage. |
daysPerMonth | integerDefault: 30 | Days in a billing month. |
loading | booleanDefault: false | Show placeholder rows with the list geometry and disable the controls while prices load. |
error | string— | Reason shown in place of the list when prices did not load. |
retryAction | string— | Registered host action requested when Try again is pressed in the error state. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | LLMCostCalculatorThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | LLMCostCalculatorMotionOptionsDefault: {} | Row glide spring, rolling number and swap timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
locale | string— | BCP 47 locale for currency and count formatting; omitted inherits the application locale. |
LLMModelPriceaccepts{ id, name, provider, brand?, color?, input, output, cachedInput? }with prices in US dollars per 1M tokens. Model IDs must be unique.LLMUsageaccepts{ inputTokens, outputTokens, requestsPerDay, cached }.LLMUsagePresetaccepts{ id, label, usage }. Passpresets={[]}to hide the segmented preset row.
React integration
| Prop | Purpose |
|---|---|
usage / onUsageChange | Controlled LLMUsage state and callback fired on every slider step, preset change, and cache toggle. |
selected / onSelectedChange | Controlled selected model ID and callback receiving (id, model) on pointer or keyboard selection. |
onRetry() | Called when Try again is pressed in the error state (takes precedence over retryAction). |
onAction(action) | Called with retryAction when Try again is pressed and onRetry is omitted. |
renderModelMark(model) | Custom 16px decorative mark rendered beside a model’s name; falls back to built-in brand marks or a monogram letter. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme, forwarded to the root panel and composed controls. |
ref, className, style | Applied to the root <section> element. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Tab | Moves across workload presets, the three sliders, Cached input, the selected model row, and Try again. |
ArrowLeft / ArrowRight | Switches workload presets, steps the focused slider by one stop, or moves between ranked model rows. |
PageUp / PageDown | Steps the focused RangeInput by two stops (Shift+Arrow also steps by 2). |
ArrowUp / ArrowDown | In the model list, selects the previous or next ranked model and moves focus with selection. |
Home / End | Jumps a slider to its first or last stop, or selects the lowest- or highest-cost model in the list. |
Space | Toggles Cached input or activates Try again. |
- The model list uses
role="radiogroup"with rovingtabIndex(0on the selected row,-1on others) and DOM order matching visual rank. Each row’saria-labelspeaks model name, provider, rank, and formatted monthly cost while hiding decorative rolling digits (aria-hidden="true"). - All three sliders speak formatted token and request counts via
aria-valuetext, never raw stop indexes. - Every visual
CountingNumberin the hero total and footer breakdown is paired with a visually hidden plain-text equivalent so screen readers never announce individual animated frames. - A pre-mounted polite
role="status"live region announces settled selection and total changes after a450msdebounce (skipping initial mount so nothing announces unprompted on page load). - Container queries stack the sliders below
600px, move the hero under the heading, place proportional bars on their own line (58pxrows), and wrap the breakdown to two columns below520px.
Motion & theming
Model rows position with pure transform and glide to new ranks on the critically damped smooth spring (0 bounce) alongside their proportional bars. Rolling totals and row costs count smoothly in place via DOM text updates without re-rendering React trees, while model names and price lines crossfade in single-cell grids.
Under prefers-reduced-motion: reduce, row glides, bar springs, counting numbers, and skeleton pulses stop while state swaps keep 120ms opacity fades. Setting motion="none" makes every row, bar, number, and state transition immediate (0ms) and halts skeleton pulse animation.
theme accepts mode, accent, and typed tokens across these groups:
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-border-width, --ui-shadow, --ui-disabled-opacity, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-track, --ui-info, --ui-success, --ui-warning, --ui-tone-foreground, --ui-overlay, --ui-tint-strength |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
accentTones | --ui-accent-strong, --ui-accent-subtle |
control | --ui-control-height, --ui-control-padding-x, --ui-control-gap, --ui-icon-size |
include | --ui-font-display |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, LLMCostCalculator is a leaf block. Always label prices as sample list prices rather than quotes, keep model and preset IDs unique, and wire retryAction only to a registered host action. See Building with agents.
{
"type": "LLMCostCalculator",
"props": {
"title": "Estimated monthly cost",
"description": "Sample list prices per 1M tokens, October 2026",
"cacheHitRate": 0.6,
"retryAction": "retry_llm_prices"
},
"children": []
}