token-dollars
v1.1.0
Published
Calculate costs for AI model API usage based on token consumption and pricing.
Readme
token-dollars
Calculate costs for AI model API usage based on token consumption and pricing.
Last verified: June 2026 from openai.com/api/pricing & ai.google.dev/gemini-api/docs/pricing.
All prices are USD per 1M tokens unless noted otherwise.
Update this file when providers reprice — prices change frequently.
Installation
npm i token-dollarsUsage
Import
import { Cost, Store } from 'token-dollars';Text model
const result = Cost('gpt-4.1', {
total_text_input_tokens: 1000000,
total_text_output_tokens: 500000,
total_cached_text: 200000,
});
console.log(result);
// {
// model: 'gpt-4.1',
// total: 3.9,
// breakdown: {
// textInputCost: 1.6, // (1M - 200K cached) × $2.00/M
// cachedTextInputCost: 0.1,
// textOutputCost: 4,
// audioInputCost: 0,
// cachedAudioInputCost: 0,
// audioOutputCost: 0,
// videoInputCost: 0,
// imageInputCost: 0,
// cachedImageInputCost: 0,
// whisperCost: 0
// }
// }Realtime / audio model
const result = Cost('gpt-realtime-2', {
total_text_input_tokens: 500000,
total_audio_input_tokens: 1000000,
total_audio_output_tokens: 500000,
total_cached_audio: 100000,
input_Transcript_Duration_whisper: 120, // 2 minutes
});
console.log(result.total);Time-billed model (translate / whisper realtime)
These models bill per second, not per token. Pass duration_seconds instead of token counts:
const result = Cost('gpt-realtime-translate', {
duration_seconds: 300, // 5 minutes
});
console.log(result.total); // 300/60 × $0.034 = $0.17
// { model: 'gpt-realtime-translate', total: 0.17, breakdown: { timeCost: 0.17 } }Gemini Live API
const result = Cost('gemini-live-2.5-flash', {
total_text_input_tokens: 200000,
total_audio_input_tokens: 50000,
total_audio_output_tokens: 30000,
total_video_input_tokens: 10000,
});Usage Object
All properties are optional and default to 0.
| Property | Description |
|---|---|
| total_text_input_tokens | Text input tokens |
| total_cached_text | Cached text input tokens (cheaper rate) |
| total_text_output_tokens | Text output tokens |
| total_audio_input_tokens | Audio input tokens |
| total_cached_audio | Cached audio input tokens |
| total_audio_output_tokens | Audio output tokens |
| total_video_input_tokens | Video input tokens (Gemini) |
| total_image_input_tokens | Image input tokens |
| total_image_cached_input_tokens | Cached image input tokens |
| input_Transcript_Duration_whisper | Whisper transcription duration in seconds |
| duration_seconds | Session duration for time-billed models |
Supported Models
OpenAI — GPT-5.x Flagship
| Model | Input | Cached | Output |
|---|---|---|---|
| gpt-5.5 | $5.00 | $0.50 | $30.00 |
| gpt-5.5-pro | $30.00 | — | $180.00 |
| gpt-5.4 | $2.50 | $0.25 | $15.00 |
| gpt-5.4-mini | $0.75 | $0.075 | $4.50 |
| gpt-5.4-nano | $0.20 | $0.02 | $1.25 |
| gpt-5.4-pro | $30.00 | — | $180.00 |
OpenAI — GPT-5 (original)
| Model | Input | Cached | Output |
|---|---|---|---|
| gpt-5 | $1.25 | $0.125 | $10.00 |
| gpt-5-mini | $0.25 | $0.025 | $2.00 |
| gpt-5-nano | $0.05 | $0.005 | $0.40 |
| gpt-5-pro | $15.00 | — | $120.00 |
| gpt-5-chat-latest | $1.25 | $0.125 | $10.00 |
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-4o (legacy)
| Model | Input | Cached | Output |
|---|---|---|---|
| gpt-4o | $2.50 | $1.25 | $10.00 |
| gpt-4o-2024-05-13 | $5.00 | — | $15.00 |
| gpt-4o-mini | $0.15 | $0.075 | $0.60 |
OpenAI — o-series Reasoning
| Model | Input | Cached | Output |
|---|---|---|---|
| o3 | $2.00 | $0.50 | $8.00 |
| o3-pro | $20.00 | — | $80.00 |
| o4-mini | $1.10 | $0.275 | $4.40 |
| o1 | $15.00 | $7.50 | $60.00 |
| o1-mini | $3.00 | $1.50 | $12.00 |
| o1-pro | $150.00 | — | $600.00 |
OpenAI — Realtime (token-billed)
| Model | Text In | Text Out | Audio In | Audio Out |
|---|---|---|---|---|
| gpt-realtime-2 | $4.00 | $24.00 | $32.00 | $64.00 |
| gpt-realtime-1.5 | $4.00 | $16.00 | $32.00 | $64.00 |
| gpt-realtime-mini | $0.60 | $2.40 | $10.00 | $20.00 |
OpenAI — Realtime (time-billed) — pass duration_seconds
| Model | Rate |
|---|---|
| gpt-realtime-translate | $0.034/min |
| gpt-realtime-whisper | $0.017/min |
OpenAI — Transcription
| Model | Input | Output | Est. cost |
|---|---|---|---|
| gpt-4o-transcribe | $2.50 | $10.00 | ~$0.006/min |
| gpt-4o-mini-transcribe | $1.25 | $5.00 | ~$0.003/min |
| whisper-1 | — | — | $0.006/min |
Google Gemini — Standard
| Model | Input | Cached | Output |
|---|---|---|---|
| gemini-3.5-flash | $1.50 | $0.15 | $9.00 |
| gemini-3.1-pro | $2.00 | $0.20 | $12.00 |
| gemini-3.1-flash-lite | $0.25 | $0.025 | $1.50 |
| gemini-2.5-pro | $1.25 | $0.125 | $10.00 |
| gemini-2.5-flash | $0.30 | $0.03 | $2.50 |
| gemini-2.5-flash-lite | $0.10 | $0.01 | $0.40 |
Google Gemini — Live / Realtime API
| Model | Text In | Audio In | Audio Out | Video In |
|---|---|---|---|---|
| gemini-live-2.5-flash | $0.30 | $1.00 | $4.00 | $2.00 |
| gemini-live-2.5-pro | $1.25 | $3.00 | $12.00 | $6.00 |
| gemini-2.5-flash-native-audio-latest | $0.50 | $3.00 | $12.00 | $3.00 |
API
Cost(model, usage)
Calculates the total cost for a given model based on usage.
Returns:
{
model: string,
total: number, // rounded to 6 decimal places
breakdown: {
textInputCost: number,
cachedTextInputCost: number,
textOutputCost: number,
audioInputCost: number,
cachedAudioInputCost: number,
audioOutputCost: number,
videoInputCost: number,
imageInputCost: number,
cachedImageInputCost: number,
whisperCost: number,
timeCost?: number, // only for time-billed models
}
}Returns { model, total: 0, breakdown: {} } for unknown models — no throw.
Store
An object containing pricing for all supported models. Each entry includes:
pricing— Rates per 1M tokens (or per minute for time-based models)asp— Provider:"openai"or"google"billingUnit—"time"for per-minute models, otherwise token-basedwssUrl— WebSocket endpoint (realtime models only)
Pricing Notes
- All token rates are per 1M tokens in USD
- Cached tokens are billed at a reduced rate (typically 50–90% less than base input)
- Whisper/transcription costs are per minute of audio
- Time-billed realtime models use
duration_seconds, not token counts - Gemini Live API bills per turn on the full session context window
- Reasoning models (o-series, Gemini 2.5+) include internal thinking tokens in output costs
- Costs are rounded to 6 decimal places
License
ISC
