
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Stop guessing. Know exactly what your AI API calls cost—before you make them.
Real-time token counter and cost calculator for GPT-5, Claude 4.5, Gemini 2.5, DeepSeek, and 20+ AI models. Built for developers who are tired of surprise API bills.
# You write a prompt...
$ cat my-prompt.txt | your-ai-tool
# Later that month...
💸 Your OpenAI Bill: $347.23
What happened? You had no idea that your 100-line context was costing $2.50 per call.
# Check BEFORE you send
$ ai-tokens count my-prompt.txt
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TOKEN ANALYSIS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Model: GPT-4o
Input Tokens: 2,847 tokens
Est. Cost: $0.01424
Output (est): 500 tokens
Est. Cost: $0.00750
Total Cost: $0.02174
💡 Cost Optimization:
• Switch to gpt-4o-mini → Save 96% ($0.0004)
• Reduce context by 1k tokens → Save $0.005
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Now you know. $0.02 per call. Make an informed decision.
# No install required
npx ai-tokens count "Your prompt here"
# Or install globally
npm install -g ai-tokens
Uses official tokenizers (tiktoken for OpenAI, estimations for others)
Up-to-date pricing for GPT-5, Claude 4.5, Gemini 2.5, DeepSeek, and 20+ models
See exactly how much you'd save with cheaper alternatives
ai-tokens count ./prompts/analyze-code.txt
cat large-context.md | ai-tokens count -m claude-opus-4
Color-coded warnings, optimization tips, comparison tables
ai-tokens count prompt.txt
# Shows: tokens, cost, optimizations
ai-tokens count prompt.txt --model claude-sonnet-4
ai-tokens count prompt.txt -m gpt-4o-mini
ai-tokens count prompt.txt --output 1000
# Estimates cost for 1000 token response
ai-tokens compare prompt.txt
# Output:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MODEL COST COMPARISON
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Current: GPT-4o ($0.0097)
┌──────────────────┬──────────┬────────┬─────┐
│ Model │ Cost │ Savings│ % │
├──────────────────┼──────────┼────────┼─────┤
│ Gemini Flash │ $0.0002 │ +$0.01 │ 98% │
│ GPT-4o Mini │ $0.0004 │ +$0.01 │ 96% │
│ Claude Haiku │ $0.0030 │ +$0.01 │ 70% │
└──────────────────┴──────────┴────────┴─────┘
🎯 Best Alternative: gemini-1.5-flash
Save $0.0095 (98%)
ai-tokens models
# Shows pricing for all supported models:
# - GPT-4o, GPT-4, GPT-3.5
# - Claude Opus, Sonnet, Haiku
# - Gemini Pro, Flash
# - Llama 3.1 (405B, 70B, 8B)
ai-tokens count prompt.txt --simple
# Output: 2847 tokens | $0.0217 | gpt-4o
$ ai-tokens count code-review-prompt.txt
Input Tokens: 3,245 tokens
Total Cost: $0.0487
💡 This costs more than a coffee ☕
Consider using gpt-4o-mini to save 95%
$ ai-tokens compare docs-prompt.txt -m gpt-4
Current Model: GPT-4
Cost: $0.157
🎯 Switch to GPT-4o → Save $0.141 (90%)
$ for file in prompts/*.txt; do
ai-tokens count "$file" -m claude-sonnet-4 --simple
done
# Quick cost estimate for all prompts
Stop getting surprised by your AI bill.
| Model | Input Price | Output Price |
|---|---|---|
| GPT-5 | $1.25/M | $5.00/M |
| GPT-5 Mini | $0.15/M | $0.60/M |
| Claude Sonnet 4.5 | $3.00/M | $15.00/M |
| Gemini 2.5 Pro | $1.25/M | $5.00/M |
| Gemini 2.5 Flash | $0.30/M | $1.20/M |
| DeepSeek R1 | $0.14/M | $0.28/M |
| Model | Input Price | Output Price |
|---|---|---|
| GPT-4o | $2.50/M | $10.00/M |
| GPT-4o Mini | $0.15/M | $0.60/M |
| Claude Opus 4 | $15.00/M | $75.00/M |
| Claude Sonnet 4 | $3.00/M | $15.00/M |
| Claude Haiku 3.5 | $1.00/M | $5.00/M |
| Gemini 2.0 Flash | FREE | FREE |
| Gemini 1.5 Pro | $1.25/M | $5.00/M |
| DeepSeek Chat | $0.14/M | $0.28/M |
20+ models supported - Pricing auto-updated from LiteLLM community data
Prices as of January 2025
tiktoken (OpenAI's official tokenizer) for GPT models# Global install
npm install -g ai-tokens
# Or use directly
npx ai-tokens count "your prompt"
# Or add to project
npm install ai-tokens
ai-tokens budget set 50)ai-tokens interactive)ai-tokens report)Pull requests welcome! Especially for:
MIT © Daniel Shashko
Daniel Shashko
Found this useful? Tweet your cost savings!
Stop guessing. Start knowing. 💰
FAQs
Real-time token counter and cost calculator for AI APIs
We found that ai-tokens demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.