Skip to main content
Glama

TokenWise: Zero-Dependency LLM & AI Agent FinOps CLI + MCP Server

tokenwise is a lightweight, zero-dependency Python CLI and Model Context Protocol (MCP) server for developers and AI engineers to estimate, audit, and optimize LLM costs across major providers (OpenAI, Anthropic, Google) completely offline.

Features

  • Zero Dependencies: Runs anywhere with Python 3.9+ using only the Python standard library.

  • Offline-First: Heuristic tokenization calibrated for modern models, no API keys or proxies required.

  • Multi-Provider Registry (2025/2026): Supports gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, o4-mini, gpt-4o, claude-opus-4, claude-sonnet-4, claude-3-7-sonnet, claude-3-5-haiku, gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash, and legacy models.

  • Codebase Scanner & CI Gate: Detect expensive/legacy model defaults, missing max_tokens caps, and bloated prompts with --markdown PR comments and --fail-on-high.

  • Log Auditor & HTML Executive Report: Audit JSONL, JSON, or CSV usage logs for spend, model-routing savings, --max-cost CI budget gates, and standalone --html reports.

  • MCP Server Mode (tokenwise mcp): Zero-dependency JSON-RPC 2.0 stdio server so AI coding agents (Claude Code, Cursor, Windsurf) can self-check prompt costs before calling frontier models.

Related MCP server: TokenOracle MCP

Installation

pip install tokenwise

For local/editable installation:

git clone https://github.com/<your-org>/tokenwise.git
cd tokenwise
pip install -e .

Usage

1. Estimate Cost for a Prompt

tokenwise estimate --text "How do I optimize my LLM costs?" --output-tokens 1000 --monthly-requests 50000
tokenwise estimate --file prompt.txt --models gpt-4.1 gpt-4.1-mini claude-sonnet-4

2. Scan a Codebase for Cost Risks

tokenwise scan ./src
tokenwise scan ./src --markdown --fail-on-high

3. Audit Usage Logs & Export HTML Report

tokenwise audit usage.jsonl
tokenwise audit usage.jsonl --max-cost 25.00
tokenwise audit usage.jsonl --html finops-report.html

4. List Supported Models & Pricing

tokenwise models
tokenwise models --provider anthropic --json

5. Run as an MCP Server (Claude Code / Cursor / Windsurf)

Start the stdio server:

tokenwise mcp

Add to your MCP client configuration (e.g., .mcp.json or Cursor MCP settings):

{
  "mcpServers": {
    "tokenwise": {
      "command": "tokenwise",
      "args": ["mcp"]
    }
  }
}

Exposed MCP tools: estimate_prompt_cost, scan_codebase_costs, audit_usage_log, list_model_pricing.

6. One-Command CI, MCP & Pre-Commit Setup (tokenwise init)

Scaffold .mcp.json and .github/workflows/tokenwise.yml in any repo:

tokenwise init
tokenwise init --all          # Also generates .pre-commit-config.yaml
tokenwise init --mcp --force  # Overwrite existing .mcp.json

Or reference .pre-commit-hooks.yaml directly in .pre-commit-config.yaml via the tokenwise-scan hook.

TokenWise FinOps Team Kit ($19)

Want automated PR cost-risk comments, Slack/Discord daily spend alerts, and an executive LLM model-routing playbook? Check out the TokenWise FinOps Team Kit (pro_kit/).

Pricing Data

Prices are based on public API list rates and provided for estimation and FinOps auditing purposes.

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Estimates, compares, and controls LLM API costs before agents spend tokens, with tools for cost estimation, model comparison, and budget checking.
      27 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables LLM clients and coding agents to analyze prompts and recommend the cheapest AI model that meets the task requirements across text, voice, video, and other modalities, projecting monthly cost savings against a flagship baseline.
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides coding agents with pre-flight cost estimation by analyzing local logs to forecast token usage and quota impact before expensive work, exposing tools for remaining quota, per-task cost estimates, and attempt affordability.
      MIT