← 返回 Skills 市场
aaroncxxx

Token Cost

作者 aaroncxxx · GitHub ↗ · v2.1.0 · MIT-0
cross-platform ✓ 安全检测通过
146
总下载
0
收藏
0
当前安装
8
版本数
在 OpenClaw 中安装
/install how-much-token-did-this-chat-used
功能描述
Track and display token usage for the current OpenClaw session and recent sessions, with cost estimation and remaining days projection. Auto-detects active m...
使用说明 (SKILL.md)

Token 用量查询 v2.1

关于作者 — 十五年老米粉了!!冲!!! v2.1 优化:7天趋势图、费用告警、Top烧钱会话、加权剩余天数、JSON增强。

核心原则

  • 纯读取、无写入 — 所有数据实时获取
  • 动态识别模型 — 不写死模型列表,从 session_status 解析
  • Credit 自动计算 — 从 sessions_list 累计 totalTokens
  • 精确计量 — 使用实际输入/输出比,不硬编码估算比例

数据源

数据 工具 说明
当前会话 session_status tokens in/out、model、context、cache
历史会话 sessions_list(limit=10) totalTokens、updatedAt
成本计算 scripts/cost.py 动态匹配计费规则

工作流

Step 1: 获取当前会话

Call session_status → 解析 model、tokens in/out、cache、context。

Step 2: 获取历史会话 + 按日聚合

Call sessions_list(limit=10):

  1. 今日累计:筛选今天(Asia/Shanghai)的会话,累加 totalTokens
  2. 近 10 会话平均:所有会话 totalTokens 之和 ÷ 会话数
  3. 近 7 天趋势:按日聚合,生成每日 token 消耗数据
  4. Top 烧钱会话:按 totalTokens 降序排列,取前 5

Step 3: 运行成本计算

python3 "{baseDir}/scripts/cost.py" \
  --input \x3Ctokens_in> \
  --output \x3Ctokens_out> \
  --total \x3Ctoday_total_tokens> \
  --used \x3Ccumulative_used> \
  --credit \x3Ctotal_credit> \
  --avg \x3Cavg_daily_tokens> \
  --model \x3Cmodel_name> \
  --cache-pct \x3Ccache_hit_pct> \
  --context \x3Ccontext_tokens> \
  --context-max \x3Cmax_context> \
  --session-count \x3Ctoday_session_count> \
  --daily '[["04-27",12400],["04-26",8200],...]' \
  --top-sessions '[["session-abc",12400,0.0372],...]' \
  --warn 80,95

其他命令:

python3 "{baseDir}/scripts/cost.py" --list-models
python3 "{baseDir}/scripts/cost.py" --help
python3 "{baseDir}/scripts/cost.py" ... --json

输出格式

📊 成本与额度报告
🧠 模型: mimo-v2.5-pro
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 当前会话
   📥 输入: 1,234  📤 输出: 567
   💾 缓存: 45%  📚 上下文: 12.5k/1.0m (1.2%)
   💰 费用: ¥0.0047
   ⚠️  Credit 使用率 82.3%,已超过 80% 阈值,请关注消耗速度

📅 今日累计 (3 会话): ¥0.0156 (≈ 4,200 Credit)
📊 近 10 会话平均: 5,600 tokens/会话

📈 近 5 天消耗趋势
   04-27  ████████████  12,400 tokens
   04-26  ███████░░░░░   8,200 tokens
   04-25  ████░░░░░░░░   4,100 tokens
   04-24  █████████░░░  10,300 tokens
   04-23  ██████░░░░░░   6,800 tokens

🔥 最近会话消耗 Top 3
   1. session-abc123…    12,400 tokens  ¥0.0372
   2. session-def456…     8,200 tokens  ¥0.0246
   3. session-ghi789…     4,100 tokens  ¥0.0123

💳 Credit
   已用: 456,789 / 555,555 (82.2%)
   ⏳ 预计可用: 8.3 天
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

新增功能

📈 7 天趋势图

从 sessions_list 按日聚合,文本柱状图展示消耗趋势。

  • 只显示最近 7 天有数据的日期
  • 自动缩放柱状图比例

⚠️ 费用告警

通过 --warn 80,95 设置阈值(默认 80% 和 95%):

  • 80% → ⚠️ 警告:"请关注消耗速度"
  • 95% → 🔴 严重:"建议立即补充额度"

🔥 Top 烧钱会话

从 sessions_list 按 totalTokens 降序,展示前 5 名最烧钱会话。

⏳ 加权剩余天数

不再用简单平均,改为加权:

  • 近 3 天权重 60%(近期行为更准)
  • 近 7 天权重 30%
  • 近 30 天权重 10%
  • 不足时自动降级使用可用数据

计费规则

模型 输入/1k 输出/1k
mimo-v2-pro ¥0.002 ¥0.004
mimo-v2.5-pro ¥0.002 ¥0.004
mimo-v2.5 ¥0.002 ¥0.004

未知模型自动 fallback 到默认费率。

注意事项

  • Credit 已用 = 所有会话累计 totalTokens
  • Token 单价为参考值,实际以服务商计费为准
  • 费用计算使用实际输入/输出比
  • 时区:Asia/Shanghai (UTC+8)

版本历史

v2.1.0 (2026-04-27)

  • 📈 新增近 7 天消耗趋势(文本柱状图)
  • ⚠️ 新增费用告警阈值 --warn(默认 80%/95%)
  • 🔥 新增 Top 烧钱会话分列
  • ⏳ 剩余天数改为加权平均(近3天60% + 近7天30% + 近30天10%)
  • 📋 JSON 增强:trend / top_sessions / alerts 字段
  • 🎨 输出格式优化,信息密度提升

v2.0.0 (2026-04-23)

  • 🐛 修复今日累计计算(按日期过滤)
  • 🐛 修复 avg_daily(按日聚合)
  • ✅ 使用实际输入/输出比
  • ✅ 新增 mimo-v2.5 系列费率
  • ✅ 支持 --json / --list-models
安全使用建议
This skill appears to do exactly what it claims: read session metadata (via session_status and sessions_list), run a local Python script, and produce a token/cost report. Before installing, confirm you are comfortable the platform APIs (session_status/sessions_list) expose only the session metadata you expect (tokens, model, timestamps) because the report includes session identifiers and usage totals. You can also review scripts/cost.py in your environment (it's plain Python, no networking or subprocess calls) to verify no hidden behavior. If you use shared or sensitive sessions, note that top-sessions output may reveal session IDs and usage patterns in the chat output.
功能分析
Type: OpenClaw Skill Name: how-much-token-did-this-chat-used Version: 2.1.0 The skill is a utility for tracking token usage and estimating costs within the OpenClaw environment. It utilizes standard internal tools (session_status and sessions_list) to gather data and processes it using a local Python script (scripts/cost.py). The script performs purely mathematical calculations and string formatting without any network access, file system modifications, or suspicious execution patterns.
能力评估
Purpose & Capability
Name, description, SKILL.md and scripts/cost.py align: the skill reads session_status and sessions_list, computes token costs and projections, and prints a report. No unrelated credentials, binaries, or install steps are required.
Instruction Scope
Runtime instructions are limited to calling the platform-provided APIs (session_status, sessions_list) and invoking the bundled scripts/cost.py with calculated arguments. The instructions do not direct reading of arbitrary files, accessing unrelated env vars, or sending data to external endpoints. Note: the output may include session IDs (shortened) and cost/credit figures derived from the session data.
Install Mechanism
This is an instruction-only skill with a local Python script; there is no install spec, no downloads, and no third-party package installation. Risk from install mechanism is minimal.
Credentials
The skill declares no required environment variables or credentials and the code does not read environment secrets. The inputs are provided by the runtime (session data) and command-line parameters; requested data (tokens, model, credits) are proportionate to computing costs.
Persistence & Privilege
always is false and the skill does not request persistent system presence or modify other skills. It simply runs a local script when invoked.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install how-much-token-did-this-chat-used
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /how-much-token-did-this-chat-used 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v2.1.0
7天趋势图(文本柱状图); 费用告警阈值 --warn 80/95%; Top烧钱会话分列; 剩余天数加权平均(近3天60%+7天30%+30天10%); JSON增强(trend/top_sessions/alerts); 输出格式优化
v2.0.0
how-much-token-did-this-chat-used v2.0.0 - Fix: Today's cumulative tokens now sum only sessions from today (Asia/Shanghai), not all sessions. - Fix: Daily average (avg_daily) now aggregates per day, providing a true daily usage average. - Change: Cost estimation now uses actual input/output token ratio, not a hardcoded 70/30 split. - New: Added support and rates for mimo-v2.5 line of models. - New: Support for command-line options: --cache-pct, --context, --context-max, --session-count, --json (for JSON output), and --list-models. - Improved: Better parameter validation, error messages, and legacy position-argument compatibility. - Updated: Output format and documentation refined for clarity and consistency.
v1.4.1
- Added a new README.md file. - Updated SKILL.md with a detailed changelog section. - No functional changes to code logic; documentation improvements only.
v1.4.0
how-much-token-did-this-chat-used v1.4.0 - Added dynamic cost estimation and remaining days projection for token usage. - Introduced scripts/cost.py for automated model billing rate detection and calculation. - Credit usage is now auto-calculated from session history, not hardwired. - Output includes estimated session cost, daily usage, and projected days left. - SKILL.md reorganized: clearer workflow, billing rules, and updated output examples.
v1.3.0
**This version introduces automatic model/billing detection and daily usage stats.** - Auto-detects active model (MiMo, Doubao, OpenAI, etc.) from session status for matching billing rules. - Adds display of today's total token usage across all sessions. - Updates average and totals for the last 10 sessions to reflect actual usage. - Removes manual edits/local writes; all data is read-only and sourced in real time (except Credit if available). - Output clearly shows current session, today's totals, and last 10 averages with model identified.
v1.2.0
**Added MiMo V2 Credit balance tracking and output.** - Now displays MiMo V2 Credit balance along with token usage stats. - Updated trigger phrases to include "credit", "余额", and related queries. - Shows credit usage from a local JSON file; guides user on updating credit numbers. - Output formats expanded: full report shows both token stats and credit status; credit-only output supported. - Notes clarify manual update requirement for credit balance.
v1.1.0
Expanded to support recent sessions and aggregate stats: - Now tracks and displays token usage for the current session and recent sessions (e.g. last 10 chats) - When requested, aggregates token and cost stats across multiple recent sessions - Added output format for per-session breakdown and grand totals - Introduced optional persistent cumulative tracking via a local JSON file - Updated triggers and notes to reflect new multi-session and aggregate capabilities
v1.0.0
how-much-token-did-this-chat-used v1.0.0 - Initial release of the skill to display token usage for the current OpenClaw session. - Presents bilingual (Chinese/English) statistics: input/output/thinking tokens, cache hit rate, context window usage, and estimated session cost. - Triggered by queries about token usage, session stats, or related keywords in English and Chinese. - Not designed for historical stats or pricing information outside the current session.
元数据
Slug how-much-token-did-this-chat-used
版本 2.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 8
常见问题

Token Cost 是什么?

Track and display token usage for the current OpenClaw session and recent sessions, with cost estimation and remaining days projection. Auto-detects active m... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 146 次。

如何安装 Token Cost?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install how-much-token-did-this-chat-used」即可一键安装,无需额外配置。

Token Cost 是免费的吗?

是的,Token Cost 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Token Cost 支持哪些平台?

Token Cost 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Token Cost?

由 aaroncxxx(@aaroncxxx)开发并维护,当前版本 v2.1.0。

💬 留言讨论