UI

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

Sample list prices per 1M tokens, October 2026

$4,437 per month with Claude Sonnet 5.5

Workload
60% of input billed at the cache read rate
Input
$2,880
Cached
$432
Output
$1,125
Per request
$0.030

Claude Sonnet 5.5: $3.00 in, $0.30 cached, $15.00 out per 1M tokens.Sample prices for illustration, not a quote. Calculated in your browser, nothing was sent.

Loading interactive preview…

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

Sample list prices per 1M tokens, October 2026

$93,900 per month with Claude Opus 5.5

Workload
85% of input billed at the cache read rate
Input
$36,000
Cached
$20,400
Output
$37,500
Per request
$0.125

Claude Opus 5.5: $5.00 in, $0.50 cached, $25.00 out per 1M tokens.Sample prices for illustration, not a quote. Calculated in your browser, nothing was sent.

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

Sample list prices per 1M tokens, October 2026

Prices unavailable

Workload
60% of input billed at the cache read rate
Prices did not loadCould not reach the pricing catalog (503 Service Unavailable). Check your connection and try again.
Input
$0.00
Cached
$0.00
Output
$0.00
Per request
$0.00000

Sample prices for illustration, not a quote. Calculated in your browser, nothing was sent.

Pricing math and states

Workload axes and slider stops

ControlDiscrete stopsUnit spoken by aria-valuetext
Input tokens per request250 to 200,000 (11 stops){n} input tokens
Output tokens per request100 to 16,000 (8 stops){n} output tokens
Requests per day100 to 1,000,000 (13 stops){n} requests
Cached inputBoolean Switch applying cacheHitRate (0–1) to cachedInputSwitch state + caption text

Controlled usage values between slider stops still compute exact costs; each slider displays its nearest stop.

Panel states

StateTriggerBehavior
listDefault (models > 0)Ranked radio group (lowest monthly cost first, stable tie-breaking), live bars, and footer breakdown.
loadingloading={true}Sets aria-busy, disables all controls, and renders pulsing skeleton rows matching exact list height.
errorerror string setDisables controls and renders an icon, "Prices did not load", reason copy, and optional Try again.
emptymodels={[]}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.

ArgumentType / defaultDescription
titlestringDefault: "Estimated monthly cost"Heading of the panel.
descriptionstringDefault: "Sample list prices per 1M tokens, October 2026"Line under the heading; say where your prices come from and when they were checked.
notestringDefault: "Sample prices for illustration, not a quote. Calculated in your browser, nothing was sent."Fine print at the bottom of the panel.
modelsLLMModelPrice[]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.
defaultUsageLLMUsageDefault: {"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.
defaultSelectedstring—Model id selected on first render; defaults to the second model; falls back to the cheapest when not in models.
presetsLLMUsagePreset[]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.
cacheHitRatenumberDefault: 0.6Share of input tokens billed at the cached rate while Cached input is on, 0 to 1; shown beside the switch as a percentage.
daysPerMonthintegerDefault: 30Days in a billing month.
loadingbooleanDefault: falseShow placeholder rows with the list geometry and disable the controls while prices load.
errorstring—Reason shown in place of the list when prices did not load.
retryActionstring—Registered host action requested when Try again is pressed in the error state.
recipestudio | softDefault: "studio"Visual treatment. Both recipes preserve interaction behavior.
themeLLMCostCalculatorThemeDefault: {}Color mode, accent, and typed semantic token overrides.
motionnone | subtle | expressiveDefault: "subtle"Animation preset. System reduced-motion preferences take precedence.
motionOptionsLLMCostCalculatorMotionOptionsDefault: {}Row glide spring, rolling number and swap timing overrides in milliseconds.
dirltr | rtl—Reading direction; inherited from the page when omitted.
localestring—BCP 47 locale for currency and count formatting; omitted inherits the application locale.
  • LLMModelPrice accepts { id, name, provider, brand?, color?, input, output, cachedInput? } with prices in US dollars per 1M tokens. Model IDs must be unique.
  • LLMUsage accepts { inputTokens, outputTokens, requestsPerDay, cached }.
  • LLMUsagePreset accepts { id, label, usage }. Pass presets={[]} to hide the segmented preset row.

React integration

PropPurpose
usage / onUsageChangeControlled LLMUsage state and callback fired on every slider step, preset change, and cache toggle.
selected / onSelectedChangeControlled 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.
presetApplication defaults overridden by explicit instance arguments.
tokensCSS variables applied after the typed theme, forwarded to the root panel and composed controls.
ref, className, styleApplied to the root <section> element.
Native attributesid, aria-*, data-*, and remaining <section> props forwarded to the root element.

Keyboard & accessibility

KeyAction
TabMoves across workload presets, the three sliders, Cached input, the selected model row, and Try again.
ArrowLeft / ArrowRightSwitches workload presets, steps the focused slider by one stop, or moves between ranked model rows.
PageUp / PageDownSteps the focused RangeInput by two stops (Shift+Arrow also steps by 2).
ArrowUp / ArrowDownIn the model list, selects the previous or next ranked model and moves focus with selection.
Home / EndJumps a slider to its first or last stop, or selects the lowest- or highest-cost model in the list.
SpaceToggles Cached input or activates Try again.
  • The model list uses role="radiogroup" with roving tabIndex (0 on the selected row, -1 on others) and DOM order matching visual rank. Each row’s aria-label speaks 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 CountingNumber in 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 a 450ms debounce (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 (58px rows), and wrap the breakdown to two columns below 520px.

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 groupCSS 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": []
}

On this page