npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

token-dollars

v1.0.2

Published

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

Downloads

21

Readme

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