LLM Cost Estimate

LLM Cost Estimate is a copy-paste React component that stops surprise bill from an llm batch before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/llm-cost-estimate
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsSurprise bill from an LLM batch

Was this component page useful?

How do I install LLM Cost Estimate?

pnpm dlx shadcn@latest add @bollard/llm-cost-estimate

The files land in your project. They're yours to edit.

How do I use LLM Cost Estimate in React?

llm-cost-estimate-usage.tsx
import { LlmCostEstimate, type ModelPrice } from "@/components/ui/llm-cost-estimate"

<LlmCostEstimate
  models={MODELS}
  pricesAsOf="2026-10-01"
  now={new Date(2026, 9, 14, 11).getTime()}
  items={50_000}
  inputTokens={1_240}
  expectedOutputTokens={60}
  lastRunCost={3.1}
  locale="en-US"
  onRun={(run) => new Promise<void>((resolve) => setTimeout(() => { setRan(`Started on ${run.model}${run.batch ? " as a batch job" : ""}, max_tokens ${run.maxTokens ?? "not set"}`); resolve() }, 600))}
/>

What input mistakes does LLM Cost Estimate catch?

  • No max_tokens: worst-case cost shown
  • Request bigger than the model's context window
  • Run many times larger than the last one
  • Premium model picked for a bulk job, with a switch
  • Batch API discount on bulk jobs
  • Price table older than staleAfterDays

What props does LLM Cost Estimate accept?

LlmCostEstimate props
PropTypeDefault
models* (required)

Your price table. Nothing is hard-coded: prices change, so pass the ones you read and when.

ModelPrice[]—
pricesAsOf* (required)

When the prices in `models` were read. Shown, and flagged once older than `staleAfterDays`.

string | number | Date—
model

Controlled model id.

string—
defaultModel

Initial model id when uncontrolled. Defaults to the first row.

string—
onModelChange

Called with the chosen model id.

(id: string) => void—
maxTokens

Controlled max_tokens; `null` means not set.

number | null—
defaultMaxTokens

Initial max_tokens when uncontrolled.

number | nullnull
onMaxTokensChange

Called with the new max_tokens, or null when cleared.

(value: number | null) => void—
batch

Controlled: send through the Batch API (needs `batchDiscount` on the model).

boolean—
defaultBatch

Initial batch choice when uncontrolled.

booleanfalse
onBatchChange

Called when the Batch API toggle changes.

(batch: boolean) => void—
items

Requests in the run.

number1
prompt

One request's prompt, to estimate input tokens from. Ignored when `inputTokens` is given.

string—
inputTokens

Exact input tokens per request from a real tokenizer.

number—
expectedOutputTokens

Typical reply length in tokens, if you know it.

number—
lastRunCost

Cost of the last comparable run, to catch a run many times bigger.

number—
jumpFactor

Multiple of the last run that counts as a jump.

number10
bulkItems

Requests at which the run counts as bulk, for the costly-model check.

number100
costlyFactor

How many times pricier than the cheapest fitting model counts as costly.

number10
staleAfterDays

Days after pricesAsOf before the price table is called stale.

number60
currency

ISO 4217 code for the table's prices.

string"USD"
locale

BCP 47 locale for numbers and currency.

string—
now

"Now" in epoch ms, for deterministic rendering. Read from the clock after mount when omitted.

number—
onRun

Called on Run. With findings left, the first click jumps to them and the second runs. May return a Promise.

(run: { model: string; maxTokens: number | null; batch: boolean; expectedCost: number; worstCost: number }) => void | Promise<void>—
messages

Any visible string.

Partial<LlmCostMessages>—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is LLM Cost Estimate accessible?

  • Model select and max-tokens input have visible labels
  • Inputs get aria-invalid when a finding applies
  • Focus moves to the first finding's fix after a change

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Set spend limits and max_tokens on the server or API key; the estimate doesn't cap anything.

  • Token counts are estimates unless you pass inputTokens; real tokenizers differ by model
  • Prices come only from your table; it doesn't fetch provider pricing
  • Doesn't enforce a budget; your API key limits or server must

What expensive mistakes does LLM Cost Estimate stop?

Surprise bill from an LLM batch

Also known as

token counter · openai cost · llm pricing · max_tokens · context window · batch api · prompt playground · anthropic api

Field type

What dependencies does LLM Cost Estimate require?

LLM Cost Estimate facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameLLM Cost Estimate
Registry identifier@bollard/llm-cost-estimate
Install commandnpx shadcn@latest add @bollard/llm-cost-estimate
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about LLM Cost Estimate

What form validation mistake does LLM Cost Estimate catch?

LLM Cost Estimate prevents surprise bill from an LLM batch. Estimates an LLM batch's tokens and cost from your own dated price table before it runs, so a missing max_tokens or wrong model doesn't cause a surprise bill. Catches: No max_tokens: worst-case cost shown, Request bigger than the model's context window, Run many times larger than the last one, Premium model picked for a bulk job, with a switch, Batch API discount on bulk jobs, Price table older than staleAfterDays. Limitation: validate llm-cost-estimate schemas on backend.

How do I install llm-cost-estimate with shadcn?

Run `npx shadcn@latest add @bollard/llm-cost-estimate`. Sources added: registry/default/llm-cost-estimate/cost.ts, registry/default/llm-cost-estimate/llm-cost-estimate.tsx. Package requirements: lucide-react.

What props customize LLM Cost Estimate?

LLM Cost Estimate accepts `models`, `pricesAsOf`, `model`, `defaultModel`, `onModelChange`. Configures token counter, openai cost, llm pricing behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of llm-cost-estimate?

Token counts are estimates unless you pass inputTokens; real tokenizers differ by model. Prices come only from your table; it doesn't fetch provider pricing. Doesn't enforce a budget; your API key limits or server must Server requirement: Set spend limits and max_tokens on the server or API key; the estimate doesn't cap anything.

How does LLM Cost Estimate meet accessibility guidelines?

Model select and max-tokens input have visible labels. Inputs get aria-invalid when a finding applies. Focus moves to the first finding's fix after a change. Minimizes errors: openai bill too high, forgot max_tokens.

Which components pair with LLM Cost Estimate?