{T}
TokenMath.net
npx @tokenmath/tokenmath·Zero-Install Terminal Tool
npm @tokenmath/tokenmathv1.0.1

TokenMath CLI Companion

Inspect 31 frontier AI models, estimate token usage, calculate prompt invocation costs, and simulate diurnal off-peak discounts directly from your terminal, Unix pipelines, or automated CI/CD guardrails.

Instant Quickstart

Zero installation required with npx, or install globally for shorthand tokenmath execution.

Verified: September 16, 2026
$npm install -g @tokenmath/tokenmath
Installs global tokenmath binary in your PATH
Calculate exact API cost with input & output tokens:Bash / Zsh / PowerShell
npx @tokenmath/tokenmath calculate --model gpt-5-6-sol --input 10000 --output 2000
Pipe a prompt file directly into the cross-tokenizer counter:Standard Input Pipeline
cat prompt.txt | npx @tokenmath/tokenmath count
Compare two models side-by-side:Benchmark Matrix
npx @tokenmath/tokenmath compare claude-sonnet-5 gpt-5-6-sol --input 10000 --output 2000
Export verified pricing registry as clean JSON for scripts:Automation & CI
npx @tokenmath/tokenmath prices --json > pricing-cache.json

Command Reference

calculate (calc)

Computes total call and monthly run costs using first-party pricing equations.

--model <id> : Model identifier (e.g. claude-sonnet-5)
--input <int> : Explicit prompt token count
--output <int> : Explicit completion token count
--cached : Apply prompt caching read discount
--batch : Apply provider 24h batch API discount (50%)
--off-peak : Apply diurnal off-peak rate (e.g. DeepSeek)
count

Analyzes arbitrary text or files across Claude BPE, OpenAI o200k, Google Gemini, and DeepSeek tokenizers.

--text "..." : Pass inline string directly
--file <path> : Read file from disk
stdin : Pipe output from other command lines
compare

Provides side-by-side cost and technical capability comparisons between any two catalog models.

<modelA> <modelB> : The two model IDs to evaluate
--input <int> : Simulated input tokens
--output <int> : Simulated output tokens
prices (list)

Dumps the canonical, human-verified price sheet for all 31 models.

--provider <name> : Filter by provider (e.g. Anthropic, OpenAI)
--json : Output machine-readable JSON structure

CI/CD LLM Budget Guardrail Recipe

Block pull requests that exceed your maximum prompt token or budget thresholds

# .github/workflows/llm-budget-check.yml
name: LLM Token Budget Guardrail
on: [pull_request]

jobs:
  token-budget:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: Verify System Prompt Size
        run: |
          TOKENS=$(cat prompts/system.md | npx @tokenmath/tokenmath count | grep "Anthropic Claude" | awk '{print $5}')
          echo "System prompt contains $TOKENS tokens"
          if [ "$TOKENS" -gt 4000 ]; then
            echo "Error: System prompt exceeded 4,000 token limit! Found $TOKENS."
            exit 1
          fi
Want to explore the graphical tools and calculators instead?