ngx-prompt-kit

Cost Display

ngx-prompt-kit original — not part of ibelick/prompt-kit

Renders the running USD/EUR/CHF/JPY/… cost of an LLM exchange. Pricing is consumer-supplied — pass the per-million rates and the token counts, the component handles the math and the locale-aware formatting.

Examples

Compact · USD

Default. Just the total. Realistic GPT-4o pricing — $2.50/1M input, $10.00/1M output. Locale pinned to en-US for the canonical $-prefix format; omit [locale] to use the runtime default.

$0.012

Detailed · EUR

display='detailed' shows the input/output breakdown. Currency switches to EUR — symbol placement and decimal handling come from the locale.

0,0111 € (in: 0,0029 €, out: 0,0082 €)

Session summary · CHF

display='session-summary' is a chip designed for status-bar placement. costPrecision=2 to land on the natural 'this session' rounding.

CHF 0.25 this session

Zero-decimal currency · JPY

Intl.NumberFormat handles currency-specific quirks. JPY has no minor unit — the formatter drops the decimals automatically. Same component, no special-casing in your code.

¥1,828¥1,828 (in: ¥472, out: ¥1,356)

With cost limit

Set [costLimit] to drive the four-tier color state — muted under 75%, amber 75–90%, destructive 90–100%, bold destructive past 100%. (overLimit) emits once per crossing.

Normal · 50%$1.25
Warn · 80%$2.00
Danger · 95%$2.375
Over · 105%$2.625

Installation

Add the cost-display component (and the cn() utility) to your project.

ng generate ngx-prompt-kit:cost-display

Component API

PkCostDisplay

PropTypeDefaultDescription
inputTokensnumber 0 Prompt/input tokens consumed.
outputTokensnumber 0 Completion/output tokens consumed.
inputPricePer1Mnumber | null null USD per 1M input tokens (null hides cost). Consumer-supplied — see Notes.
outputPricePer1Mnumber | null null USD per 1M output tokens (null hides cost). Consumer-supplied — see Notes.
currencystring "USD" ISO 4217 currency code (e.g. 'USD', 'EUR', 'CHF', 'GBP', 'JPY'). Symbol placement and decimal handling derive from the locale.
localestring | undefinedBCP-47 locale tag (e.g. "en-US", "de-CH", "ja-JP"). Defaults to the runtime locale.
costPrecisionnumber 4 Maximum decimal places. Default 4 handles fractions of a cent; drop to 2 for $0.43-style output.
costLimitnumber | null null Optional max cost in the same currency. Drives the four-tier color state and the (overLimit) output.
display"compact" | "detailed" | "session-summary" "compact" compact: bare total. detailed: total + input/output breakdown. session-summary: chip-style with "this session" suffix.
showBreakdownboolean false Force the (in: $X, out: $Y) breakdown in compact / session-summary modes. Detailed mode shows it by default.
classstringExtra classes for the host.

Outputs

PropTypeDefaultDescription
overLimit(over: boolean) => voidFires once each time totalCost crosses costLimit (true on cross-over, false on cross-back).