Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 820 Bytes

File metadata and controls

46 lines (31 loc) · 820 Bytes

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