New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

token-dollars

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

token-dollars

Calculate costs for AI model API usage based on token consumption and pricing.

latest
npmnpm
Version
1.0.2
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

token-dollars

Calculate costs for AI model API usage based on token consumption and pricing.

Installation

npm i token-dollars

Usage

Import

import { Cost, Store } from 'token-dollars';

Calculate Cost

Calculate the total cost for a model based on usage statistics:

const usage = {
  total_text_input_tokens: 1000000,
  total_text_output_tokens: 500000,
  total_cached_text: 200000
};

const result = Cost('gpt-4o', usage);
console.log(result);
// {
//   model: 'gpt-4o',
//   total: 3.75,
//   breakdown: {
//     textInputCost: 2.5,
//     cachedTextInputCost: 0.25,
//     textOutputCost: 5,
//     audioInputCost: 0,
//     cachedAudioInputCost: 0,
//     audioOutputCost: 0,
//     whisperCost: 0
//   }
// }

Usage Object

The usage parameter accepts the following optional properties:

  • total_text_input_tokens - Total number of text input tokens
  • total_cached_text - Total number of cached text tokens
  • total_text_output_tokens - Total number of text output tokens
  • total_audio_input_tokens - Total number of audio input tokens
  • total_cached_audio - Total number of cached audio tokens
  • total_audio_output_tokens - Total number of audio output tokens
  • input_Transcript_Duration_whisper - Whisper transcription duration in seconds

Audio and Whisper Example

const usage = {
  total_text_input_tokens: 500000,
  total_audio_input_tokens: 1000000,
  total_audio_output_tokens: 500000,
  input_Transcript_Duration_whisper: 120 // 2 minutes
};

const result = Cost('gpt-realtime', usage);
console.log(result.total); // Total cost including audio and whisper

Supported Models

The package includes pricing for the following models:

OpenAI Models

  • gpt-5
  • gpt-5-mini
  • gpt-5-nano
  • gpt-5-chat-latest
  • gpt-5-pro
  • gpt-4.1
  • gpt-4.1-mini
  • gpt-4.1-nano
  • gpt-4o
  • gpt-4o-2024-05-13
  • gpt-4o-mini
  • gpt-realtime
  • gpt-realtime-mini

Google Models

  • gemini-2.5-flash-native-audio-latest

API

Cost(model, usage)

Calculates the total cost for a given model based on usage statistics.

Parameters:

  • model (string) - The model identifier (must exist in Store)
  • usage (object) - Usage statistics object containing token counts and transcription duration

Returns:

  • object - Cost calculation result
    • model (string) - The model identifier
    • total (number) - Total cost (rounded to 6 decimal places)
    • breakdown (object) - Detailed cost breakdown by component
      • textInputCost (number)
      • cachedTextInputCost (number)
      • textOutputCost (number)
      • audioInputCost (number)
      • cachedAudioInputCost (number)
      • audioOutputCost (number)
      • whisperCost (number)

Store

An object containing pricing information for all supported models. Each model entry includes:

  • pricing - Pricing per million tokens or per minute (for Whisper)
  • asp - API service provider (e.g., "openai", "google")
  • wssUrl - WebSocket URL (for realtime models)

Pricing Notes

  • Token costs are calculated per million tokens
  • Whisper transcription costs are calculated per minute
  • Costs are rounded to 6 decimal places
  • Missing usage properties default to 0

License

ISC

FAQs

Package last updated on 05 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts