微算力 · API 导航与自营网关
API 接入 EN
未登录登录
💸

AI 令牌成本追踪与预算管家

Token Watch · v1.0.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
效率 安全 S 级 作者 vedantsingh60 公开目录收录
1.1k 下载 0 安装 5.1k 收藏 19 浏览

简介

本地运行的 AI 令牌成本追踪工具,支持预算预警、多模型比价与费用优化,零依赖零遥测。

原始描述

Track and analyze token usage and costs across AI providers with budget alerts, model cost comparison, optimization tips, and local data storage.

通过你的 Agent 添加

安装目录:token-watch/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/token-watch/
Codex CLI~/.codex/skills/token-watch/
DeepSeek Harness~/.agents/skills/token-watch/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

技能正文

TokenWatch

Track, analyze, and optimize token usage and costs across AI providers. Set budgets, get alerts, compare models, and reduce your spend.

Free and open-source (MIT License) • Zero dependencies • Works locally • No API keys required


Why This Skill?

After OpenAI's acquisition of OpenClaw, token costs are the #1 concern for power users. This skill gives you full visibility into what you're spending, where it's going, and exactly how to reduce it.

Problems it solves:

  • You don't know how much you're spending until the bill arrives
  • No way to compare costs across providers before choosing a model
  • No alerts when you're approaching your budget
  • No actionable suggestions for reducing spend

Features

1. Record Usage & Auto-Calculate Costs

from tokenwatch import TokenWatch

monitor = TokenWatch()

monitor.record_usage(
    model="claude-haiku-4-5-20251001",
    input_tokens=1200,
    output_tokens=400,
    task_label="summarize article"
)
# ✅ Recorded: $0.00192

2. Auto-Record from API Responses

from tokenwatch import record_from_anthropic_response, record_from_openai_response

# Anthropic
response = client.messages.create(model="claude-haiku-4-5-20251001", ...)
record_from_anthropic_response(monitor, response, task_label="my task")

# OpenAI
response = client.chat.completions.create(model="gpt-4o-mini", ...)
record_from_openai_response(monitor, response, task_label="my task")

3. Set Budgets with Alerts

monitor.set_budget(
    daily_usd=1.00,
    weekly_usd=5.00,
    monthly_usd=15.00,
    per_call_usd=0.10,
    alert_at_percent=80.0   # Alert at 80% of budget
)
# ✅ Budget set: daily=$1.0, weekly=$5.0, monthly=$15.0
# 🚨 BUDGET ALERT fires automatically when threshold is crossed

4. Dashboard

print(monitor.format_dashboard())
💰 SPENDING SUMMARY
  Today:   $0.0042  (4 calls, 13,600 tokens)
  Week:    $0.0231  (18 calls, 67,200 tokens)
  Month:   $0.1847  (92 calls, 438,000 tokens)

📋 BUDGET STATUS
  Daily:   [████░░░░░░░░░░░░░░░░] 42% $0.0042 / $1.00 ✅
  Monthly: [███████░░░░░░░░░░░░░] 37% $0.1847 / $0.50 ⚠️

💡 OPTIMIZATION TIPS
  🔴 Swap Opus → Sonnet for non-reasoning tasks (save ~$8.20/mo)
  🟡 High avg cost/call on gpt-4o — reduce prompt length

5. Compare Models Before Calling

# For 2000 input + 500 output tokens:
for m in monitor.compare_models(2000, 500)[:6]:
    print(f"{m['model']:<42} ${m['cost_usd']:.6f}")
gemini-2.5-flash                           $0.000300
gpt-4o-mini                                $0.000600
mistral-small-2501                         $0.000350
claude-haiku-4-5-20251001                  $0.003600
mistral-large-2501                         $0.007000
gemini-2.5-pro                             $0.007500

6. Estimate Before You Call

estimate = monitor.estimate_cost("claude-sonnet-4-5-20250929", input_tokens=5000, output_tokens=1000)
print(f"Estimated cost: ${estimate['estimated_cost_usd']:.6f}")

7. Optimization Suggestions

suggestions = monitor.get_optimization_suggestions()
for s in suggestions:
    savings = s.get("estimated_monthly_savings_usd", 0)
    print(f"[{s['priority'].upper()}] {s['message']}")
    if savings:
        print(f"  → Save ~${savings:.2f}/month")

8. Export Reports

monitor.export_report("monthly_report.json", period="month")

Supported Models (Feb 2026)

Provider Model Input/1M Output/1M
Anthropic claude-opus-4-6 $15.00 $75.00
Anthropic claude-sonnet-4-5-20250929 $3.00 $15.00
Anthropic claude-haiku-4-5-20251001 $0.80 $4.00
OpenAI gpt-4o $2.50 $10.00
OpenAI gpt-4o-mini $0.15 $0.60
OpenAI o1 $15.00 $60.00
OpenAI o3-mini $1.10 $4.40
Google gemini-2.5-pro $1.25 $10.00
Google gemini-2.5-flash $0.075 $0.30
Mistral mistral-large-2501 $2.00 $6.00
Mistral mistral-small-2501 $0.10 $0.30

To add a custom model: add it to PROVIDER_PRICING dict at the top of tokenwatch.py.


API Reference

TokenWatch(storage_path)

Initialize monitor. Data stored in .tokenwatch/ by default.

record_usage(model, input_tokens, output_tokens, task_label, session_id)

Record a single API call. Returns TokenUsageRecord with calculated cost.

set_budget(daily_usd, weekly_usd, monthly_usd, per_call_usd, alert_at_percent)

Configure spending limits. Alerts fire automatically when thresholds are crossed.

get_spend(period)

Get aggregated spend. Period: "today", "week", "month", "all", or "YYYY-MM-DD".

get_spend_by_model(period)

Spending breakdown by model, sorted by cost descending.

get_spend_by_provider(period)

Spending breakdown by provider.

compare_models(input_tokens, output_tokens)

Compare costs across all known models. Returns list sorted cheapest first.

estimate_cost(model, input_tokens, output_tokens)

Estimate cost before making a call.

get_optimization_suggestions()

Analyze usage and return ranked suggestions with estimated monthly savings.

format_dashboard()

Human-readable spending dashboard with budget bars and tips.

export_report(output_file, period)

Export full report to JSON.

record_from_anthropic_response(monitor, response, task_label)

Helper to auto-record from Anthropic SDK response object.

record_from_openai_response(monitor, response, task_label)

Helper to auto-record from OpenAI SDK response object.


Privacy & Security

  • ✅ Zero telemetry — No data sent anywhere
  • ✅ Local-only storage — Everything in .tokenwatch/ on your machine
  • ✅ No API keys required — The monitor itself needs no credentials
  • ✅ No authentication — No accounts or logins needed
  • ✅ Full transparency — MIT licensed, source code included

Changelog

[1.0.0] - 2026-02-16

  • ✨ Initial release — TokenWatch
  • ✨ Pricing table for 11 models across 5 providers
  • ✨ Budget alerts: daily, weekly, monthly, per-call thresholds
  • ✨ Model cost comparison (sorted cheapest to most expensive)
  • ✨ Cost estimation before making API calls
  • ✨ Optimization suggestions with estimated monthly savings
  • ✨ Auto-hooks for Anthropic and OpenAI response objects
  • ✨ Dashboard with progress bars and budget status
  • ✨ JSON export for reporting
  • ✨ Local-only storage, zero dependencies, MIT licensed

Last Updated: February 16, 2026 Current Version: 1.0.0 Status: Active & Community-Maintained

© 2026 UnisAI Community

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

cost-optimizationbudget-managementlocal-firstopen-sourceai-monitoringtoken-tracking

同类 Skill