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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ai-calc

v1.1.8

Published

A comprehensive price calculator for token-based AI models. Automatically calculate and summarize the total cost of all AI API calls in your script, providing a detailed output after execution.

Downloads

62

Readme

AI-CALC: Token Price Calculator for GPT and OpenAI Models

Easily calculate and summarize the total cost of AI API calls for models like GPT-3, GPT-4, and Amazon Bedrock with AI-CALC. This tool provides detailed cost estimates for OpenAI and AWS AI models, helping you manage token usage costs effectively.

Installation

Install the package via npm:

npm install ai-calc

If you are installing directly from the source, run the build command:

npm run build

Usage

TypeScript Example

Calculate total for multiple calls:

import PriceCalculator from 'ai-calc';

import OpenAI from "openai"; // your model package
const openai = new OpenAI(); // your constructor/config

// Example usage
const priceCalculator = new PriceCalculator();

// Add custom model or update/override existing
// priceCalculator.addOrUpdateModel('custom-model', 0.02, 0.04);

const model1 = "gpt-4-1106-preview";
const completion1 = await openai.chat.completions.create({
    messages: [
        { "role": "user", "content": "Say hello!" }
    ],
    model: model1,
});

const model1Price = priceCalculator.calculateTokenPrice(model1, completion1.usage);
console.log(model1Price);

const model2 = "gpt-4-turbo";
const completion2 = await openai.chat.completions.create({
    messages: [
        { "role": "user", "content": "Say good-bye!" }
    ],
    model: model2,
});

const model2Price = priceCalculator.calculateTokenPrice(model2, completion2.usage);
console.log(model2Price);

console.log('Total Input Price:', priceCalculator.getTotalInputPrice());
console.log('Total Output Price:', priceCalculator.getTotalOutputPrice());
console.log('Total Combined Price:', priceCalculator.getTotalCombinedPrice());

JavaScript Example

const PriceCalculator = require('ai-calc');

const OpenAI = require("openai"); // your model package
const openai = new OpenAI(); // your constructor/config

// Example usage
const priceCalculator = new PriceCalculator();

// Add custom model or update/override existing
// priceCalculator.addOrUpdateModel('custom-model', 0.02, 0.04);

let completion;
const model1 = "gpt-4-1106-preview";
const completion1 = await openai.chat.completions.create({
    messages: [
        { "role": "user", "content": "Say hello!" }
    ],
    model: model1,
});

const model1Price = priceCalculator.calculateTokenPrice(model1, completion1.usage);
console.log(model1Price);

const model2 = "gpt-4-turbo";
const completion2 = await openai.chat.completions.create({
    messages: [
        { "role": "user", "content": "Say good-bye!" }
    ],
    model: model2,
});

const model2Price = priceCalculator.calculateTokenPrice(model2, completion2.usage);
console.log(model2Price);

console.log('Total Input Price:', priceCalculator.getTotalInputPrice());
console.log('Total Output Price:', priceCalculator.getTotalOutputPrice());
console.log('Total Combined Price:', priceCalculator.getTotalCombinedPrice());

License

MIT License

Author: James Malin

Keywords

  • ai
  • token price calculator
  • openai
  • gpt
  • model cost calculator
  • ai token pricing
  • openai token costs
  • gpt-3
  • gpt-4
  • gpt-3.5 turbo
  • ai model cost
  • openai api
  • token usage cost
  • ai pricing tool
  • ai cost estimation
  • ai api pricing
  • gpt token pricing
  • openai pricing
  • total usage cost
  • gpt cost
  • gpt calculator
  • amazon bedrock calculator
  • bedrock cost
  • aws ai calculator
  • aws model cost