Skip to content

Token counter and LLM cost estimator CLI

License

Notifications You must be signed in to change notification settings

chu2bard/tokenmeter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

127 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tokenmeter

Token counter and LLM cost estimator. Counts tokens for any text and estimates API costs across OpenAI, Anthropic and Google models.

Install

npm install
npm run build

cleanup: revisit later

CLI

# count tokens in a file
node dist/cli.js count --file README.md

# count tokens in text
node dist/cli.js count --text "hello world" --model gpt-4o

# estimate cost
node dist/cli.js cost --input 10000 --output 2000 --provider openai

# list models
node dist/cli.js models

todo: performance

API

import { countTokens, estimateCost } from "tokenmeter";

const result = countTokens("hello world", "gpt-4o");
console.log(result.tokens);

const costs = estimateCost(1000, 500, "gpt-4o");
# note: revisit later
console.log(costs[0].totalCost);

License

MIT

About

Token counter and LLM cost estimator CLI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published