API Cost Tracker for Openclaw

A comprehensive utility for tracking, analyzing, and optimizing AI API expenditures across major LLM providers to minimize unnecessary spending.

charlie-morrison
v1.0.0
Apr 30, 2026
0
708
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install cm-api-cost-tracker

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install cm-api-cost-tracker using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is API Cost Tracker?

The API Cost Tracker is a robust tool designed to provide granular visibility into your AI infrastructure spending. By parsing billing exports, usage logs, or direct API responses from providers like OpenAI, Anthropic, OpenRouter, and Google AI, it empowers developers to understand exactly where their budget is going. This utility is a core part of a professional Openclaw Skills setup, enabling teams to move beyond high-level billing summaries into detailed unit-cost analysis.

Beyond simple tracking, the tool identifies optimization opportunities by suggesting model downgrades, identifying caching potential, and highlighting prompt compression candidates. It serves as a financial audit layer for AI agents, ensuring that performance remains high while costs are kept under strict control through automated reporting and trend detection.

API Cost Tracker Use Cases

  • Monitoring daily spending across multiple LLM providers in a single dashboard.
  • Identifying the most expensive individual API requests or specific sessions.
  • Auditing token usage to find opportunities for prompt engineering optimizations.
  • Setting and tracking budget thresholds to prevent unexpected monthly billing spikes.
  • Comparing current model costs against cheaper alternatives using benchmark-based quality analysis.

How API Cost Tracker Works

  1. The script ingests usage data from a local file export, a live API call, or environment variables.
  2. It normalizes disparate data formats from various providers into a unified schema containing timestamps, models, and token counts.
  3. The engine applies the internal pricing database to calculate or verify accurate costs per request.
  4. Data is aggregated and grouped based on the requested dimension, such as by model type, time period, or specific feature tags.
  5. An optimization engine runs a comparison between current usage and potential savings from alternative models.
  6. A formatted report is generated in the user's preferred format, such as a terminal table or a Markdown document.

API Cost Tracker Setup

The API Cost Tracker requires Python 3.8 or higher and operates using only the standard library, requiring no external dependencies. To start using this with your Openclaw Skills, follow these steps:

# Analyze an OpenRouter activity export
python3 scripts/api_cost_tracker.py openrouter --file activity.json

# Analyze OpenAI usage from an environment key
export OPENAI_API_KEY='your_key_here'
python3 scripts/api_cost_tracker.py auto --days 30

API Cost Tracker Data Schema & Taxonomy

The tool normalizes all incoming provider data into a consistent internal structure to ensure accurate cross-platform analysis:

Attribute Description
timestamp The exact time the API request was initiated
model The specific model identifier (e.g., gpt-4o, claude-3-5-sonnet)
tokens_in Total number of input or prompt tokens
tokens_out Total number of output or completion tokens
cost The final calculated cost in USD based on the pricing database
metadata Optional tags for feature-based or session-based tracking

API Cost Tracker Advanced Features

  • Trend detection and anomaly flagging to alert users to unusual spending velocity.
  • Automated budget alerts that provide projected monthly overrun warnings based on current usage.
  • Model substitution analysis to simulate savings if switching to a more cost-effective provider.
  • Support for custom pricing databases to account for enterprise discounts or specific contract rates.
  • Multi-format output support including JSON and CSV for integration into larger data pipelines within Openclaw Skills workflows.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*