← 返回
开发者工具 Key 中文

LLM Cost Tracker

Track, analyze, and optimize LLM API spending across providers (OpenAI, Anthropic, Google, DeepSeek, etc.). Use when the user asks about API costs, token usa...
跨提供商追踪、分析和优化大语言模型API费用(OpenAI、Anthropic、Google、DeepSeek等),用于用户询问API费用和token使用情况。
johnnywang2001
开发者工具 clawhub v1.0.0 1 版本 100000 Key: 需要
★ 0
Stars
📥 579
下载
💾 25
安装
1
版本
#latest

概述

API Cost Tracker

Monitor and optimize your LLM API spending directly from your agent.

Quick Start

Run cost analysis:

python3 scripts/cost_tracker.py --summary

Commands

Check Current Spend

python3 scripts/cost_tracker.py --provider openai --period today
python3 scripts/cost_tracker.py --provider anthropic --period week
python3 scripts/cost_tracker.py --all --period month

Set Budget Alert

python3 scripts/cost_tracker.py --set-budget 100 --period month --alert telegram

Cost Breakdown by Model

python3 scripts/cost_tracker.py --breakdown model --period week

Optimization Recommendations

python3 scripts/cost_tracker.py --optimize

This analyzes usage patterns and recommends:

  • Model downgrades for simple tasks (e.g., use Haiku instead of Opus for classification)
  • Caching opportunities (repeated similar prompts)
  • Batch processing windows (off-peak pricing where available)
  • Context window optimization (trim unnecessary context)

Supported Providers

ProviderMethodSetup
-------------------------
OpenAIUsage APIOPENAI_API_KEY env var
AnthropicUsage APIANTHROPIC_API_KEY env var
Google AIBilling APIGOOGLE_API_KEY env var
DeepSeekUsage APIDEEPSEEK_API_KEY env var

Budget Alerts

Configure in ~/.openclaw/cost-tracker.json:

{
  "budgets": {
    "daily": 10,
    "weekly": 50,
    "monthly": 200
  },
  "alertChannels": ["telegram", "discord"],
  "alertThresholds": [50, 75, 90, 100]
}

Alerts fire at each threshold percentage. At 100%, optionally pause non-critical agent tasks.

Output Format

Reports generate as markdown tables suitable for any messaging surface:

Provider    | Model              | Tokens    | Cost
------------|--------------------|-----------|---------
Anthropic   | claude-opus-4-6   | 2.1M      | $63.00
Anthropic   | claude-sonnet-4-6 | 5.4M      | $16.20
OpenAI      | gpt-4o            | 1.8M      | $9.00
            | TOTAL              |           | $88.20

Advanced: Cost Optimization Patterns

See references/optimization-guide.md for detailed strategies on reducing API spend by 30-60% without sacrificing quality.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 05:00 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

productivity

Agent Invoice Generator

johnnywang2001
根据自然语言或结构化数据生成专业的PDF发票,适用于用户请求创建发票、向客户计费或生成收据等场景。
★ 0 📥 649
developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,794
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 668 📥 324,133