@avakado.ai/token-dollars
v1.0.26
Published
USD pricing engine for LLM API usage. Pass a model id and a usage object, get a dollar cost.
Downloads
3,994
Maintainers
Readme
@avakado.ai/token-dollars
USD cost for a model id + a usage object.
Rates are a versioned catalog (one file per provider). Updating a price is a data change, not a calculator change. Last verified 2026-08-21 from:
import { cost } from '@avakado.ai/token-dollars';
const result = cost('gpt-4.1', {
input: 800_000, // uncached text tokens
cached: 200_000,
output: 500_000,
});
result.total; // 5.7
result.currency; // 'USD'
result.breakdown; // per-meter dollarsProvider usage blobs work as-is (OpenAI Chat/Realtime, Anthropic Messages, Gemini usageMetadata).
Install
npm i @avakado.ai/token-dollarsUsage object
input is uncached. Cached / cache-write / audio / image / video are separate meters.
| Field | Meaning |
|---|---|
| input | Uncached text input tokens |
| cached | Cached text input tokens |
| output | Text output tokens (includes reasoning / thinking) |
| cacheWrite | Cache-write tokens (OpenAI GPT-5.6+ 1.25x meter) |
| cacheWrite5m / cacheWrite1h | Anthropic 5-minute / 1-hour cache writes |
| text / audio / image / video | { input, cached?, output? } per modality |
| serviceTier | 'standard' (default), 'batch', 'flex', 'fast' |
Legacy keys still work. total_text_input_tokens is treated as an OpenAI-style total (cached tokens are subtracted before the uncached rate is applied).
cost('gpt-realtime-2.1', {
text: { input: 20_000, output: 8_000 },
audio: { input: 40_000, cached: 10_000, output: 12_000 },
});
cost('claude-sonnet-5', {
input_tokens: 10_000,
output_tokens: 2_000,
cache_read_input_tokens: 50_000,
cache_creation: { ephemeral_5m_input_tokens: 4_000 },
});
cost('gpt-5.6-sol', { input: 300_000, output: 8_000 }, { serviceTier: 'fast' });Unknown models throw UnknownModelError. Pass { unknownReturnsZero: true } only if you want the old silent $0 behavior.
Supported models
Prices are USD per 1M tokens. Cached is the cache-hit / cache-read rate.
OpenAI — GPT-4.1
| Model | Input | Cached | Output |
|---|---|---|---|
| gpt-4.1 | $2.00 | $0.50 | $8.00 |
| gpt-4.1-mini | $0.40 | $0.10 | $1.60 |
| gpt-4.1-nano | $0.10 | $0.025 | $0.40 |
OpenAI — GPT-5.6
Prompts >272K input tokens use the long row for the whole request. Cache writes are 1.25× uncached input.
| Model | Input | Cached | Cache write | Output | Long in / out |
|---|---|---|---|---|---|
| gpt-5.6-sol | $5.00 | $0.50 | $6.25 | $30.00 | $10 / $45 |
| gpt-5.6-terra | $2.00 | $0.20 | $2.50 | $12.00 | $4 / $18 |
| gpt-5.6-luna | $0.20 | $0.02 | $0.25 | $1.20 | $0.40 / $1.80 |
batch / flex are 0.5× standard. fast is 2× standard.
OpenAI — Realtime
gpt-realtime-2.0 is an alias of gpt-realtime-2.
| Model | Text in / cached / out | Audio in / cached / out | Image in / cached |
|---|---|---|---|
| gpt-realtime | $4 / $0.40 / $16 | $32 / $0.40 / $64 | $5 / $0.50 |
| gpt-realtime-1.5 | $4 / $0.40 / $16 | $32 / $0.40 / $64 | $5 / $0.50 |
| gpt-realtime-2 | $4 / $0.40 / $24 | $32 / $0.40 / $64 | $5 / $0.50 |
| gpt-realtime-2.1 | $4 / $0.40 / $24 | $32 / $0.40 / $64 | $5 / $0.50 |
| gpt-realtime-mini | $0.60 / $0.06 / $2.40 | $10 / $0.30 / $20 | $0.80 / $0.08 |
| gpt-realtime-2.1-mini | $0.60 / $0.06 / $2.40 | $10 / $0.30 / $20 | $0.80 / $0.08 |
Google Gemini
| Model | Input | Cached | Output | Notes |
|---|---|---|---|---|
| gemini-2.5-flash | $0.30 | $0.03 | $2.50 | Audio in $1.00 |
| gemini-2.5-flash-lite | $0.10 | $0.01 | $0.40 | Audio in $0.30 |
| gemini-2.5-pro | $1.25 | $0.125 | $10.00 | >200K prompt: $2.50 / $15 |
| gemini-3.5-flash | $1.50 | $0.15 | $9.00 | |
| gemini-3.1-flash-lite | $0.25 | $0.025 | $1.50 | Audio in $0.50 |
Native audio / Live API (gemini-2.5-flash-native-audio-latest): text $0.50 / $2.00, audio $3.00 / $12.00, video in $3.00.
Anthropic Claude
| Model | Input | Cache read | 5m write | 1h write | Output |
|---|---|---|---|---|---|
| claude-opus-4-8 | $5.00 | $0.50 | $6.25 | $10.00 | $25.00 |
| claude-sonnet-5 | $2.00 | $0.20 | $2.50 | $4.00 | $10.00 |
| claude-haiku-4-5-20251001 | $1.00 | $0.10 | $1.25 | $2.00 | $5.00 |
claude-haiku-4-5 resolves to the dated snapshot.
Updating prices
Catalog lives in src/catalog/. One file per provider. To add or reprice a model, edit the defineModel({...}) entry — do not touch cost.js.
// src/catalog/openai.js
defineModel({
id: 'gpt-4.1',
provider: 'openai',
source: 'https://developers.openai.com/api/docs/models/gpt-4.1',
rates: {
standard: text(2.00, 8.00, { cachedInput: 0.50 }),
batch: text(1.00, 4.00, { cachedInput: 0.25 }),
},
});text(input, output, extras) and audio(input, output, extras) are USD per 1M tokens. Bump VERIFIED_AT in src/catalog/define.js when you refresh from the vendor pages.
API
cost(model, usage?, options?) → {
model, provider, currency: 'USD',
total, // 6 decimal places
breakdown, // per-meter USD
usage, // canonical meters
rates, // rates that were applied
meta: { billing, serviceTier, contextBand, verifiedAt, source },
warnings,
}
costMany([{ model, usage }, ...])
getModel(id) / hasModel(id) / listModels() / StoreLicense
UNLICENSED (Campus Root proprietary). Publishing to the public npm registry does not grant a license to use it.
