@tokenmath/tokenmath
v1.0.1
Published
Zero-dependency developer CLI for LLM token counting, API pricing calculation, and CI/CD budget guardrails.
Readme
TokenMath.net — AI Token Counter & LLM Cost Calculator
TokenMath.net is a production-ready, privacy-first developer utility for real-time AI token counting, prompt caching economics modeling, multimodal calculations, and LLM API budget planning.
Key Features
- Universal Token Counter: Live token counts across GPT-6 (
o200k_base), GPT-4 (cl100k_base), Claude 5 (calibrated BPE), Gemini 3 (SentencePiece), and DeepSeek/Llama. - Cost Estimator & Budget Planner: Detailed input, cached read/write, output, and batch pricing with volume scaling.
- Price Comparison Matrix: Interactive 19-model price matrix with multi-column sorting and 1-click CSV Export.
- Multimodal Calculators:
- Audio & Video: Gemini 1 fps video frame tokens (290 tok/s), Whisper STT per-minute rates, and OpenAI TTS.
- Vision Calculator: High/low-res downscaling and 512×512 tiling calculations for OpenAI, Anthropic, and Google.
- Developer Tools:
- Prompt Sanitizer & PII Redactor: 100% client-side redaction of API keys (
sk-...,ghp_..., AWS, DB strings), emails, and IPs with whitespace minification. - Vector Embeddings & RAG Ingestion: Dimension sizes, chunking parameters, and vector database pricing.
- GPU TCO Break-Even Solver: Rented H100/A100/L40S vs Cloud API cost inflection threshold.
- Prompt Sanitizer & PII Redactor: 100% client-side redaction of API keys (
- Model Directory (
/models) & Dedicated Model Pages (/model/[slug]): 19 pre-rendered static deep-dive pages with Schema.orgProductstructured data. - Developer Guide (
/guide) & FAQ (/faq): 12-minute technical guide on caching architecture, batch discounts, and rate limits. - TokenMath CLI Companion (
npx @tokenmath/tokenmath): Zero-install terminal utility to calculate API invocation costs, compare models, and pipe prompt files into CI/CD budget guardrails. - Automated Price Sync (
/api/sync-prices): Programmatic endpoint ready for weekly GitHub Actions cron jobs.
TokenMath CLI Companion (@tokenmath/tokenmath)
Execute calculations and count tokens directly in your terminal with zero installation:
# Instant calculation with caching and explicit tokens
npx @tokenmath/tokenmath calculate --model gpt-5-6-sol --input 10000 --output 2000
# Pipe prompt files to count tokens
cat prompt.txt | npx @tokenmath/tokenmath count
# Head-to-head comparison
npx @tokenmath/tokenmath compare claude-sonnet-5 gpt-5-6-sol --input 10000 --output 2000
# Export master pricing registry as JSON
npx @tokenmath/tokenmath prices --jsonOr install globally:
npm install -g @tokenmath/tokenmath
tokenmath calculate --model claude-sonnet-5 --prompt system.txtTech Stack
- Framework: Next.js 16 (App Router, Turbopack)
- Language: TypeScript (Strict Mode)
- Styling: Tailwind CSS, Lucide Icons
- Tokenizers:
gpt-tokenizer(exact BPE) + calibrated statistical models - Architecture: 100% Client-Side Calculations (Zero Prompts Transmitted or Stored)
Getting Started
1. Install Dependencies
npm install2. Run Development Server
npm run devOpen http://localhost:3000 in your browser.
3. Production Build
npm run build
npm run start -- -p 3030Deployment Guide
Option 1: Vercel (Recommended)
- Push your repository to GitHub:
git init git add . git commit -m "feat: initial production release of TokenMath.net" git remote add origin https://github.com/<your-username>/tokenmath.git git push -u origin main - Go to vercel.com and click "Add New Project".
- Import your
tokenmathrepository. - Next.js is auto-detected. Click Deploy.
- Under Project Settings > Domains, connect
tokenmath.net.
Option 2: Cloudflare Pages / Netlify
- Build command:
npm run build - Output directory:
.next(or standalone) - Node.js Version:
>= 20.x
Post-Launch Monetization (Google AdSense)
- Open
public/ads.txtand replacepub-XXXXXXXXXXXXXXXXwith your official Google AdSense publisher ID:google.com, pub-XXXXXXXXXXXXXXXX, DIRECT, f08c47fec0942fa0 - When your AdSense account is approved, paste your client script in
components/AdSlot.tsx. - Ad placements can be turned ON/OFF anytime via the hidden Admin Console at
/admin.
License & Privacy
TokenMath.net is designed with a privacy-first philosophy. No user input, prompt text, uploaded documents, or calculated figures are ever sent to any remote server or third party.
