← 返回 Skills 市场
k5rs4n

API Cost Tracker

作者 k5rs4n · GitHub ↗ · v1.0.0
cross-platform ⚠ suspicious
472
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install api-cost-tracker
功能描述
Track AI API costs across OpenAI, Anthropic, Google AI with budget alerts, analytics, and optimization tips
使用说明 (SKILL.md)

API Cost Tracker 💰

Comprehensive AI API cost tracking across multiple providers. Monitor spending, set budgets, get alerts, and optimize your AI costs.

Features

  • Multi-Provider Support - OpenAI, Anthropic, Google AI
  • Real-Time Tracking - Monitor costs as they happen
  • Budget Alerts - Get notified when approaching limits
  • Usage Analytics - Detailed insights into API usage
  • Cost Optimization - Tips to reduce spending
  • Export Reports - JSON, CSV, Markdown formats
  • Historical Data - Track costs over time
  • Model Comparison - Compare costs across models

Installation

cd api-cost-tracker
npm install

Quick Start

# Track all providers
node scripts/main.mjs track

# Track specific provider
node scripts/main.mjs track --provider openai

# View analytics
node scripts/main.mjs analytics

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

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

Configuration

Edit config.json:

{
  "providers": {
    "openai": {
      "enabled": true,
      "apiKey": "${OPENAI_API_KEY}"
    },
    "anthropic": {
      "enabled": true,
      "apiKey": "${ANTHROPIC_API_KEY}"
    },
    "google": {
      "enabled": true,
      "apiKey": "${GOOGLE_AI_KEY}"
    }
  },
  "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 Reference

track(options)

Track API usage and costs.

Options:

  • provider (string): Specific provider or 'all'
  • period (string): 'today', 'week', 'month', 'all'

Returns:

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

analytics(period)

Get detailed analytics.

Period: 'day', 'week', 'month', 'year'

Returns:

  • Cost trends
  • Usage patterns
  • Model efficiency
  • Optimization suggestions

budget.set(amount, period)

Set budget limit.

budget.check()

Check current budget status.

export(format, options)

Export cost report.

Formats: 'json', 'csv', 'markdown'

Usage Examples

Track Daily Costs

node scripts/main.mjs track --period today

Output:

💰 API Costs - Today
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
OpenAI
  GPT-4: $12.50 (125K tokens)
  GPT-3.5: $2.30 (230K tokens)
  Subtotal: $14.80

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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total: $23.00
Budget: $200/month (11.5% used)

Set Budget Alert

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

Export Monthly Report

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

Compare Models

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

Pricing Reference

OpenAI (per 1K tokens)

  • GPT-4: $0.03 (input) / $0.06 (output)
  • GPT-4 Turbo: $0.01 / $0.03
  • GPT-3.5 Turbo: $0.0005 / $0.0015

Anthropic (per 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 (per 1K tokens)

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

Integration with OpenClaw

Add to your HEARTBEAT.md for automated tracking:

Every 6 hours:
- Run: node /path/to/api-cost-tracker/scripts/main.mjs track
- Alert if budget > 75%

Automated Budget Monitoring

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

Advanced Features

Cost Optimization Tips

Run optimization analysis:

node scripts/main.mjs optimize

Get suggestions like:

  • Switch to GPT-3.5 for simple tasks
  • Use Claude-3 Haiku for fast responses
  • Batch requests to reduce API calls
  • Cache common responses

Webhook Integration

Configure alerts to send to webhooks:

{
  "webhooks": [
    {
      "url": "https://your-slack-webhook.com",
      "events": ["budget_exceeded", "high_usage"]
    }
  ]
}

Historical Analysis

# View last 30 days
node scripts/main.mjs history --days 30

# Compare months
node scripts/main.mjs compare --period month --previous

Data Storage

Cost data is stored locally:

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

Troubleshooting

API Key Issues

# Test API keys
node scripts/main.mjs test-keys

Missing Data

# Rebuild database
node scripts/main.mjs rebuild

Testing

npm test

License

MIT - Free for personal and commercial use.

Support

Roadmap

  • More providers (Cohere, AI21, etc.)
  • Real-time dashboard
  • Team cost sharing
  • Custom pricing rules
  • Predictive analytics
安全使用建议
This skill is inconsistent: the docs say it will read provider APIs, send webhook alerts, and use API keys, but the included script only simulates usage (creates demo entries and writes local JSON files). Before installing or providing any API keys: 1) Inspect scripts/main.mjs fully (and confirm whether it actually calls provider APIs or sends webhooks). 2) If you need real cross-provider tracking, ask the author for proof of implemented integrations or an updated release that actually uses the provider APIs securely. 3) Do not paste real API keys into config.json or environment variables unless you verify the code will use them as expected (and that network endpoints are legitimate). 4) If you plan to run automated jobs (cron/heartbeat), test in an isolated environment first. Confidence is medium because parts of the main script were truncated and tests expect exports that may not be present; additional information (full/main.mjs that includes API integration or explicit network code) would raise confidence and could change the verdict to benign if implementation matches documentation.
功能分析
Type: OpenClaw Skill Name: api-cost-tracker Version: 1.0.0 The OpenClaw AgentSkills skill bundle 'api-cost-tracker' is classified as benign. The code and documentation align with the stated purpose of tracking AI API costs. There is no evidence of intentional malicious behavior such as data exfiltration, unauthorized remote execution, or hidden backdoors. The skill stores data locally, uses environment variables for API keys (as expected), and provides instructions for automated execution via cron jobs, which is a legitimate use case for an agent managing its own tasks. No prompt injection attempts against the agent were found in the markdown files.
能力评估
Purpose & Capability
The name/description promise real-time tracking across OpenAI, Anthropic, and Google AI using API keys and webhooks. The code, however, only computes costs from provided token counts, stores local demo entries, and does not integrate with provider APIs or fetch usage from those services. The listed optional env vars (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_AI_KEY) are plausible for the described purpose but are not consumed by the CLI shown. Webhook alerting is present in config examples but the script contains no network/send logic for webhooks.
Instruction Scope
SKILL.md instructs users to set API keys, run automated tracking, add crontab entries, and configure webhooks. The runtime instructions in scripts/main.mjs (as provided) only create demo tracking entries, save to local data files, and print reports. Several advertised CLI commands (e.g., test-keys, alerts enable, check-budget, rebuild) appear in docs but are not implemented (the main script is truncated and the implemented commands shown are limited). This grants broad expectations to the user that the skill does not meet.
Install Mechanism
No install spec beyond normal npm usage. package.json lists no external dependencies and there are no network download/install steps. This is low install risk.
Credentials
Required env vars are reasonable for the declared purpose (API keys for the three providers) and are marked optional. However, the code shown does not read or use those env vars, so requesting them in docs/config.json is currently misleading. Do not assume keys will be used safely — they are not consumed in the visible code.
Persistence & Privilege
The skill does not request elevated privileges or persistent platform presence (always:false). It writes only to a local ./data directory. Autonomous invocation is allowed by default (normal for skills) but there is no evidence of the skill modifying other skills or system-wide settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install api-cost-tracker
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /api-cost-tracker 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
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.
元数据
Slug api-cost-tracker
版本 1.0.0
许可证
累计安装 1
当前安装数 1
历史版本数 1
常见问题

API Cost Tracker 是什么?

Track AI API costs across OpenAI, Anthropic, Google AI with budget alerts, analytics, and optimization tips. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 472 次。

如何安装 API Cost Tracker?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install api-cost-tracker」即可一键安装,无需额外配置。

API Cost Tracker 是免费的吗?

是的,API Cost Tracker 完全免费(开源免费),可自由下载、安装和使用。

API Cost Tracker 支持哪些平台?

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

谁开发了 API Cost Tracker?

由 k5rs4n(@k5rs4n)开发并维护,当前版本 v1.0.0。

💬 留言讨论