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 🙏

© 2026 – Pkg Stats / Ryan Hefner

handonweb-openai-costs

v1.0.0

Published

Calculate OpenAI API costs before making calls. Supports GPT-4o, GPT-4.1, o3, o4-mini, GPT-5, and more.

Downloads

99

Readme

handonweb-openai-costs

Calculate OpenAI API costs before making calls. Supports all current models including GPT-4o, GPT-4.1, o3, o4-mini, GPT-5, embeddings, Whisper, TTS, and DALL-E 3. Zero dependencies.

Install

npm install handonweb-openai-costs

Usage

const { calculateCost, listModels, getModelPricing } = require('handonweb-openai-costs');

// Calculate cost for 1000 input + 500 output tokens
const cost = calculateCost('gpt-4o', 1000, 500);
console.log(cost);
// { inputCost: 0.0000025, outputCost: 0.000005, totalCost: 0.0000075, currency: 'USD' }

// Check a million tokens on GPT-4o-mini
const big = calculateCost('gpt-4o-mini', 1_000_000, 1_000_000);
console.log(`Total: $${big.totalCost}`); // Total: $0.75

// List all supported models
console.log(listModels());
// ['gpt-4o', 'gpt-4o-mini', 'gpt-4.1', ...]

// Get raw pricing for a model
const pricing = getModelPricing('gpt-4.1');
console.log(pricing);
// { inputPer1M: 2.00, outputPer1M: 8.00, description: '...' }

Supported Models

| Model | Input (per 1M tokens) | Output (per 1M tokens) | |-------|----------------------|------------------------| | gpt-4o | $2.50 | $10.00 | | gpt-4o-mini | $0.15 | $0.60 | | gpt-4.1 | $2.00 | $8.00 | | gpt-4.1-mini | $0.40 | $1.60 | | gpt-4.1-nano | $0.10 | $0.40 | | gpt-5 | $10.00 | $30.00 | | gpt-5-mini | $1.50 | $6.00 | | o3 | $10.00 | $40.00 | | o3-mini | $1.10 | $4.40 | | o4-mini | $1.10 | $4.40 | | gpt-4-turbo | $10.00 | $30.00 | | gpt-3.5-turbo | $0.50 | $1.50 | | text-embedding-3-small | $0.02 | — | | text-embedding-3-large | $0.13 | — |

Plus whisper, tts-1, and dall-e-3 with their own pricing structures.

API

calculateCost(model, inputTokens, outputTokens?)

Returns { inputCost, outputCost, totalCost, currency }. Throws if the model is unknown.

listModels()

Returns an array of all supported model name strings.

getModelPricing(model)

Returns the raw pricing object for a model, or null if not found.

About Hand On Web

We build AI chatbots, voice agents, and automation tools for businesses.

Licence

MIT