← 返回
未分类 中文

Api Cost Tracker

Track, analyze, and optimize AI API costs across OpenAI, Anthropic, OpenRouter, Google, and other LLM providers. Parses billing data, usage logs, or API resp...
跨平台跟踪、分析并优化AI API费用,解析账单、使用日志和API响应。
charlie-morrison charlie-morrison 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 269
下载
💾 0
安装
1
版本
#latest

概述

API Cost Tracker

Analyze and optimize AI API costs across multiple providers with detailed breakdowns, trend detection, and actionable savings recommendations.

Quick Start

# Analyze OpenRouter usage (from activity page export)
python3 scripts/api_cost_tracker.py openrouter --file activity.json

# Analyze OpenAI usage (from billing export)
python3 scripts/api_cost_tracker.py openai --file usage.json

# Analyze from environment (auto-detect provider from API keys)
python3 scripts/api_cost_tracker.py auto --days 30

# Cost breakdown by model
python3 scripts/api_cost_tracker.py openrouter --file activity.json --by model

# Cost breakdown by day with trend analysis
python3 scripts/api_cost_tracker.py openrouter --file activity.json --by day --trends

# Find most expensive requests
python3 scripts/api_cost_tracker.py openrouter --file activity.json --top 20

# Compare current vs optimized (model substitution analysis)
python3 scripts/api_cost_tracker.py openrouter --file activity.json --optimize

# Set budget alert threshold
python3 scripts/api_cost_tracker.py openrouter --file activity.json --budget 50.00

# Output as markdown report
python3 scripts/api_cost_tracker.py openrouter --file activity.json --output markdown

# Output as JSON
python3 scripts/api_cost_tracker.py openrouter --file activity.json --output json

Supported Providers

ProviderInput FormatAuto-detect
------------------------------------
OpenAIBilling CSV/JSON export, API responsesOPENAI_API_KEY
AnthropicUsage API, console exportANTHROPIC_API_KEY
OpenRouterActivity JSON, API responsesOPENROUTER_API_KEY
Google AIBilling exportGOOGLE_AI_API_KEY
GenericCSV with columns: timestamp, model, tokens_in, tokens_out, costN/A

Analysis Features

  1. Cost Breakdown — by model, day, week, feature/tag, request type
  2. Trend Detection — spending velocity, anomaly detection, projected monthly cost
  3. Optimization Report — model substitution suggestions, caching opportunities, prompt compression candidates
  4. Budget Alerts — daily/weekly/monthly thresholds with projected overrun warnings
  5. Top Spenders — most expensive individual requests or sessions
  6. Model Comparison — cost-per-quality analysis using common benchmarks

Output Formats

  • Terminal (default) — colored tables and charts
  • Markdown — report suitable for documentation
  • JSON — structured data for programmatic use
  • CSV — spreadsheet-compatible export

How It Works

The script:

  1. Reads usage data from the specified source (file, API, or environment)
  2. Normalizes all entries to a common format (timestamp, model, input_tokens, output_tokens, cost)
  3. Applies current provider pricing to calculate/verify costs
  4. Groups and aggregates by the requested dimension
  5. Runs optimization analysis comparing current models to cheaper alternatives
  6. Generates the report in the requested format

Pricing Database

Built-in pricing for 50+ models (updated March 2026). Override with --pricing custom_prices.json.

Requirements

  • Python 3.8+
  • No external dependencies (stdlib only)

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-08 03:43 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

AdMapix

fly0pants
AdMapix 原始数据层,提供广告创意、应用、排名、下载/收入及市场元数据。返回 AdMapix API 的结构化 JSON;调用方...
★ 297 📥 142,396
data-analysis

Tavily 搜索

jacky1n7
通过 Tavily API 进行网页搜索(Brave 替代方案)。当用户要求搜索网页、查找来源或链接,且 Brave 网页搜索不可用时使用。
★ 275 📥 101,186
data-analysis

Data Analysis

ivangdavila
{"answer":"数据分析与可视化。查询数据库、生成报告、自动化电子表格,将原始数据转化为清晰可行的见解。适用于:(1) 您……"}
★ 212 📥 70,783