← 返回
未分类 Key 中文

LLM Cost Tracker

Track OpenClaw LLM token usage and cost from OpenRouter API. Reports: last 24h, 7d, 30d, 90d, 365d with model breakdown. Skills that trigger this: - "llm cos...
追踪 OpenClaw LLM 通过 OpenRouter API 的 token 使用量和费用,提供过去 24 小时、7 天、30 天、90天、365 天的报告,并按模型细分。触发关键词包括:“llm cos”。
joeyiptk
未分类 clawhub v1.1.2 2 版本 100000 Key: 需要
★ 0
Stars
📥 440
下载
💾 0
安装
2
版本
#automation#configuration#cost-tracking#latest#llm#monitoring#openrouter#token-metrics

概述

llm-cost-tracker

Track and report LLM token usage and cost for OpenClaw via OpenRouter.

Quick Start

python3 scripts/collect_usage.py --init      # first-time: create DB + backfill
python3 scripts/run_tracker.py               # telegram report (default)
python3 scripts/run_tracker.py --output terminal  # full terminal report
python3 scripts/run_tracker.py --output debug     # per-request debug

Core Design

  • Source of truth: usage.cost.total from OpenRouter — never recomputed from token counts
  • Data source: OpenClaw session JSONL files (including .reset files from context compaction)
  • Deduplication: by openrouter_request_id — safe to re-run backfill anytime
  • Time windows: 24h rolling (UTC); 7d/30d/90d/365d calendar days (configurable timezone)

Schema: request_facts

ColumnSource
----------------
openrouter_request_idresponseId (unique key)
created_at_utcentry timestamp
modelmodel ID
prompt_tokensusage.input
completion_tokensusage.output
cached_tokensusage.cacheRead
cache_write_tokensusage.cacheWrite
reasoning_tokensusage.reasoning
total_tokensusage.totalTokens
billed_costusage.cost.total (canonical)

Configuration

config/env.json (all fields optional):

{
  "SESSIONS_DIR": "",
  "TIMEZONE": "Asia/Hong_Kong",
  "UTC_OFFSET_HOURS": 8
}
  • SESSIONS_DIR: override session file location (empty = auto-detect)
  • TIMEZONE / UTC_OFFSET_HOURS: for calendar-day window calculations
  • API key: auto-detected from ~/.openclaw/agents/main/agent/auth-profiles.json or OPENROUTER_API_KEY env var

Scheduled Reports

openclaw cron add --name "llm-cost:collect" --message "collect usage data" \
  --cron "5 0 * * *" --tz "Asia/Hong_Kong" --session isolated --no-deliver

openclaw cron add --name "llm-cost:daily" --message "llm cost" \
  --cron "0 9 * * *" --tz "Asia/Hong_Kong" --session isolated

版本历史

共 2 个版本

  • v1.1.2 当前
    2026-05-29 21:08 安全 安全
  • v1.1.1
    2026-05-08 00:16 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

knowledge-advisor

joeyiptk
知识顾问,从书籍和学习资料中提取、组织知识并运用于实际情境,充当持续顾问。
★ 0 📥 355

OpenClaw Backup

joeyiptk
使用内置的 `openclaw backup create` 命令备份OpenClaw 工作区、配置和状态,同时处理旧备份的清理和健康检查。
★ 0 📥 304

modern-portfolio-theory

joeyiptk
现代投资组合理论优化器 — 构建、回测并管理多元化投资组合
★ 0 📥 261