闲社服务运行正常AI智能体自动化平台
a

API成本追踪

技能标识:api-cost-tracker

Track AI API costs across OpenAI, Anthropic, Google AI with budget alerts, analytics, and optimization tips

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

API成本追踪

API 成本追踪器 💰

跨多提供商的全方位AI API成本追踪。监控支出、设定预算、获取警报,优化您的AI成本。

功能特性

  • - ✅ 多提供商支持 - OpenAI、Anthropic、Google AI
  • ✅ 实时追踪 - 实时监控成本发生情况
  • ✅ 预算警报 - 接近限额时自动通知
  • ✅ 使用分析 - API使用的详细洞察
  • ✅ 成本优化 - 降低支出的实用建议
  • ✅ 导出报告 - 支持JSON、CSV、Markdown格式
  • ✅ 历史数据 - 追踪长期成本变化
  • ✅ 模型对比 - 跨模型成本比较

安装

bash
cd api-cost-tracker
npm install

快速开始

bash

追踪所有提供商


node scripts/main.mjs track

追踪特定提供商

node scripts/main.mjs track --provider openai

查看分析

node scripts/main.mjs analytics

设置预算

node scripts/main.mjs budget set 100 --monthly

导出报告

node scripts/main.mjs export --format markdown --output report.md

配置

编辑 config.json:

json
{
providers: {
openai: {
enabled: true,
apiKey: ${OPENAIAPIKEY}
},
anthropic: {
enabled: true,
apiKey: ${ANTHROPICAPIKEY}
},
google: {
enabled: true,
apiKey: ${GOOGLEAIKEY}
}
},
budgets: {
daily: 10,
weekly: 50,
monthly: 200
},
alerts: {
enabled: true,
thresholds: [50, 75, 90, 100],
webhook: https://your-webhook.com/alert
},
tracking: {
autoTrack: true,
interval: 300000
}
}

API 参考

track(options)

追踪API使用和成本。

选项:

  • - provider (字符串):指定提供商或all
  • period (字符串):today、week、month、all

返回:
json
{
total: 45.67,
providers: {
openai: 32.10,
anthropic: 10.50,
google: 3.07
},
models: {
gpt-4: 28.50,
claude-3: 10.50
}
}

analytics(period)

获取详细分析。

周期: day、week、month、year

返回:

  • - 成本趋势
  • 使用模式
  • 模型效率
  • 优化建议

budget.set(amount, period)

设置预算限额。

budget.check()

检查当前预算状态。

export(format, options)

导出成本报告。

格式: json、csv、markdown

使用示例

追踪每日成本

bash node scripts/main.mjs track --period today

输出:

💰 API 成本 - 今日
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
OpenAI
GPT-4:$12.50(125K tokens)
GPT-3.5:$2.30(230K tokens)
小计:$14.80

Anthropic
Claude-3:$8.20(82K tokens)
小计:$8.20

━━━━━━━━━━━━━━━━━━━━━━━━━━━━
总计:$23.00
预算:$200/月(已使用11.5%)

设置预算警报

bash node scripts/main.mjs budget set 100 --monthly node scripts/main.mjs alerts enable

导出月度报告

bash node scripts/main.mjs export --format markdown --period month --output monthly-report.md

比较模型

bash node scripts/main.mjs compare --models gpt-4,claude-3,gemini-pro

定价参考

OpenAI(每1K tokens)

  • - GPT-4:$0.03(输入)/ $0.06(输出)
  • GPT-4 Turbo:$0.01 / $0.03
  • GPT-3.5 Turbo:$0.0005 / $0.0015

Anthropic(每1K tokens)

  • - Claude-3 Opus:$0.015 / $0.075
  • Claude-3 Sonnet:$0.003 / $0.015
  • Claude-3 Haiku:$0.00025 / $0.00125

Google AI(每1K tokens)

  • - Gemini Pro:$0.00025 / $0.0005
  • Gemini Ultra:$0.0025 / $0.0075

与OpenClaw集成

添加到您的HEARTBEAT.md以实现自动追踪:

markdown
每6小时:

  • - 运行:node /path/to/api-cost-tracker/scripts/main.mjs track
  • 如果预算 > 75%则发出警报

自动预算监控

bash

添加到crontab


0 /6 cd /path/to/api-cost-tracker && node scripts/main.mjs check-budget

高级功能

成本优化建议

运行优化分析:
bash
node scripts/main.mjs optimize

获取建议如:

  • - 简单任务切换到GPT-3.5
  • 快速响应使用Claude-3 Haiku
  • 批量请求减少API调用
  • 缓存常见响应

Webhook集成

配置警报发送到webhooks:

json
{
webhooks: [
{
url: https://your-slack-webhook.com,
events: [budgetexceeded, highusage]
}
]
}

历史分析

bash

查看最近30天


node scripts/main.mjs history --days 30

比较月份

node scripts/main.mjs compare --period month --previous

数据存储

成本数据本地存储:

data/
├── costs/
│ ├── 2026-03-01.json
│ ├── 2026-03-02.json
│ └── ...
├── budgets.json
└── alerts.log

故障排除

API密钥问题

bash

测试API密钥

node scripts/main.mjs test-keys

数据缺失

bash

重建数据库

node scripts/main.mjs rebuild

测试

bash
npm test

许可证

MIT - 免费用于个人和商业用途。

支持

  • - GitHub Issues:[your-repo]
  • OpenClaw Discord:https://discord.gg/clawd

路线图

  • - [ ] 更多提供商(Cohere、AI21等)
  • [ ] 实时仪表板
  • [ ] 团队成本分摊
  • [ ] 自定义定价规则
  • [ ] 预测分析

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 api-cost-tracker-1776284604 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 api-cost-tracker-1776284604 技能

通过命令行安装

skillhub install api-cost-tracker-1776284604

下载

⬇ 下载 api-cost-tracker v1.0.0(免费)

文件大小: 10.8 KB | 发布时间: 2026-4-16 15:58

v1.0.0 最新 2026-4-16 15:58
Initial release of API Cost Tracker – monitor and manage AI API usage and costs across major providers.

- Track real-time spending on OpenAI, Anthropic, and Google AI APIs.
- Set budgets with customizable alerts and webhook integration.
- Analyze usage with detailed analytics and model cost comparisons.
- Export reports in JSON, CSV, or Markdown formats.
- Get optimization tips and maintain historical cost data locally.
- Supports automated checks, easy configuration, and troubleshooting commands.
返回顶部