https://github.com/meistrari/aicost
Calculate how much a LLM completion costs
https://github.com/meistrari/aicost
Last synced: 5 months ago
JSON representation
Calculate how much a LLM completion costs
- Host: GitHub
- URL: https://github.com/meistrari/aicost
- Owner: meistrari
- Created: 2024-02-15T14:33:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-15T18:04:51.000Z (5 months ago)
- Last Synced: 2024-11-15T19:19:00.428Z (5 months ago)
- Language: TypeScript
- Size: 325 KB
- Stars: 5
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# aicost
A simple, efficient library for calculating AI model costs across various providers. It's completely type safe.## Installation
```bash
npm install aicost
```## Usage
### Calculate Cost
Calculate the cost of using an AI model based on input and output amounts.```ts
import { calculateCost } from 'aicost'const cost = calculateCost({
provider: 'openai',
model: 'gpt-3.5-turbo',
inputAmount: 6032,
outputAmount: 1238
})console.log(cost)
```
```ts
{
inputCost: 0.18096,
outputCost: 0.07428,
inputCostUnit: "token",
outputCostUnit: "token",
}
```### Get information for a model
Retrieve detailed information about a specific AI model.```ts
import { getModelInfo } from 'aicost'const modelInfo = getModelInfo({
provider: 'openai',
model: 'gpt-4'
})console.log(modelInfo)
```### List supported providers
List all available AI model providers.```ts
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.```ts
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 ↗**](https://github.com/BerriAI/litellm/), if you're using python, check them out!