aicost
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

aicost

A simple, efficient library for calculating AI model costs across various providers. It's completely type safe.

Installation

npm install aicost

Usage

Calculate Cost

Calculate the cost of using an AI model based on input and output amounts.

import { calculateCost } from 'aicost'

const cost = calculateCost({
    provider: 'openai',
    model: 'gpt-3.5-turbo',
    inputAmount: 6032,
    outputAmount: 1238
})

console.log(cost)
{
  inputCost: 0.18096,
  outputCost: 0.07428,
  inputCostUnit: "token",
  outputCostUnit: "token",
}

Get information for a model

Retrieve detailed information about a specific AI model.

import { getModelInfo } from 'aicost'

const modelInfo = getModelInfo({
    provider: 'openai',
    model: 'gpt-4'
})

console.log(modelInfo)

List supported providers

List all available AI model providers.

import { getProviderList } from 'aicost'

const providers = getProviderList()

console.log(providers.includes('anthropic'))

List supported models from a provider

Get a list of all models offered by a specific provider.

import { getModelList } from 'aicost'

const models = getModelList('cohere')

console.log(models)

Credits

The information present on this package is extracted from the amazing work done at LiteLLM ↗, if you're using python, check them out!

/aicost/

    Package Sidebar

    Install

    npm i aicost

    Weekly Downloads

    237

    Version

    0.1.3

    License

    ISC

    Unpacked Size

    805 kB

    Total Files

    7

    Last publish

    Collaborators

    • henrykunh