ai-cost-analyzer

v1.1.4
io.github.vpatser1/ai-cost-analyzer Checked 4 days ago Published 4 months ago

Analyze LLM API costs: token waste detection, caching savings estimates, model comparison

An MCP (Model Context Protocol) server that helps developers understand and reduce their AI API costs. Stop wasting 30-40% of your token budget on unused tool definitions, redundant context, and cache misses. License keys are emailed instantly after checkout. Activate via the LICENSE_KEY environment variable. More info: aivp-mcp.vercel.app No install step needed — run straight from npm:

Summary extracted from the README.

AI Cost Analyzer

An MCP (Model Context Protocol) server that helps developers understand and reduce their AI API costs. Stop wasting 30-40% of your token budget on unused tool definitions, redundant context, and cache misses.

Features

  • Usage Analysis -- Break down API costs by model, detect token waste, and track spending trends
  • Savings Estimation -- Get dollar-amount projections for prompt caching, model routing, and context pruning
  • Prompt Optimization -- Automatically detect and remove redundant content, verbose phrasing, and duplicate instructions
  • Model Comparison -- Compare cost/quality tradeoffs across Claude, GPT-4o, and Gemini for any task
  • Live Pricing -- Current pricing data for all major LLM APIs in one place

Pricing

Plan Price
Free trial $0 3 calls total (shared across all tools), no credit card — just run it
Indie $29/mo Buy →
Team $99/mo Buy →
Enterprise $299/mo Buy →

License keys are emailed instantly after checkout. Activate via the LICENSE_KEY environment variable. More info: aivp-mcp.vercel.app

Installation

No install step needed — run straight from npm:

npx -y ai-cost-analyzer

Or install globally:

npm install -g ai-cost-analyzer

Configure with Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "ai-cost-analyzer": {
      "command": "npx",
      "args": ["-y", "ai-cost-analyzer"],
      "env": { "LICENSE_KEY": "<your license key — omit for free trial>" }
    }
  }
}

Configure with Claude Code

claude mcp add ai-cost-analyzer -- npx -y ai-cost-analyzer

Run with SSE transport

# Start the SSE server (default port 3000)
npx -y ai-cost-analyzer --sse

# Or specify a custom port
PORT=8080 npx -y ai-cost-analyzer --sse

Tools

analyze_usage

Accepts API usage data and returns detailed cost analysis.

Input:

{
  "usage_data": [
    {
      "model": "claude-sonnet",
      "input_tokens": 15000,
      "output_tokens": 3000,
      "cached_tokens": 5000,
      "timestamp": "2026-03-15T10:30:00Z",
      "tool_definitions": 12,
      "system_prompt_tokens": 3500
    },
    {
      "model": "claude-opus",
      "input_tokens": 8000,
      "output_tokens": 4000,
      "timestamp": "2026-03-15T11:00:00Z"
    }
  ]
}

Output includes:

  • Total cost breakdown by model
  • Average cost per request
  • Token waste estimation (unused tool definitions, oversized system prompts)
  • Daily and weekly trend analysis

estimate_savings

Estimates monthly savings from optimization strategies.

Input:

{
  "usage_data": [
    {
      "model": "claude-sonnet",
      "input_tokens": 12000,
      "output_tokens": 2500,
      "cached_tokens": 0,
      "timestamp": "2026-03-15T10:00:00Z",
      "tool_definitions": 15
    }
  ],
  "monthly_multiplier": 30
}

Output includes:

  • Current vs. optimized monthly cost
  • Savings from prompt caching (up to 90% on cached tokens)
  • Savings from model routing (use cheaper models for simple tasks)
  • Savings from context pruning (remove unused tool definitions)
  • Actionable recommendations

optimize_prompt

Analyzes and optimizes a system prompt and tool definitions.

Input:

{
  "system_prompt": "You are a helpful assistant. Please make sure to always respond in a professional manner. It is important to note that you should be concise. You are a helpful assistant that responds professionally.",
  "tool_definitions": [
    "{\"name\": \"search\", \"description\": \"Search the web for information\"}",
    "{\"name\": \"calculator\", \"description\": \"Perform mathematical calculations\"}"
  ],
  "requests_per_month": 50000,
  "model": "claude-sonnet"
}

Output includes:

  • Token count before and after optimization
  • Optimized system prompt with redundant content removed
  • Estimated monthly cost reduction
  • Specific recommendations (enable caching, split tool groups, etc.)

compare_models

Compares models for a given task with cost/quality tradeoff analysis.

Input:

{
  "task_description": "Classify customer support tickets into categories",
  "estimated_input_tokens": 800,
  "estimated_output_tokens": 50
}

Output includes:

  • Cost per request for each model
  • Cost per 1,000 requests
  • Monthly projection at 10K requests
  • Quality tier classification
  • Task-specific model recommendation

get_pricing

Returns current LLM API pricing. No input required.

Output includes:

Model Input/1M Output/1M Cached Input/1M
Claude Opus $15.00 $75.00 $1.50
Claude Sonnet $3.00 $15.00 $0.30
Claude Haiku $0.25 $1.25 $0.025
GPT-4o $2.50 $10.00 $1.25
GPT-4o Mini $0.15 $0.60 $0.075
Gemini 2.0 Flash $0.10 $0.40 $0.025

Pricing

Plan Price Includes
Indie $29/month 1 seat, all tools, email support
Team $99/month 5 seats, all tools, priority support, shared dashboards
Enterprise $299/month Unlimited seats, all tools, dedicated support, SSO, custom integrations

All plans include unlimited tool calls and full access to pricing data updates.

Development

# Watch mode for development
npm run dev

# Build for production
npm run build

# Run with stdio transport
npm start

# Run with SSE transport
npm run start:sse

Architecture

src/
  index.ts              Main server entry point, tool registration, transport setup
  types.ts              Shared TypeScript types and interfaces
  tools/
    analyze.ts          analyze_usage: cost breakdown, waste detection, trends
    savings.ts          estimate_savings: caching, routing, pruning projections
    optimize.ts         optimize_prompt: prompt analysis and optimization
    compare.ts          compare_models: cross-model cost/quality comparison
    pricing.ts          get_pricing: pricing data and cost computation helpers

License

MIT