DEV Community

2x lazymac
2x lazymac

Posted on

How to Track Your AI API Spending in 5 Minutes

The Problem

You're using GPT-4 on one project, Claude on another, Gemini for experiments. End of month: surprise $500 bill. No idea which project burned what.

Sound familiar? Every team running multiple AI providers hits this wall.

The Solution: AI Spend Tracker API

I built a simple API that tracks every AI API call across all providers. Log usage, set budgets, forecast costs, get optimization recommendations.

Supports: OpenAI, Anthropic, Google, Mistral, DeepSeek, Meta

Quick Start (5 minutes)

Step 1: Get your API key

Grab a free key at coindany.gumroad.com/l/ai-finops-api. Free tier gives you 100 logs/day.

Step 2: Log every AI call

Add one POST after each AI API call:

curl -X POST https://api.lazy-mac.com/ai-spend/api/v1/log \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "openai",
    "model": "gpt-4o",
    "input_tokens": 500,
    "output_tokens": 200
  }'
Enter fullscreen mode Exit fullscreen mode

Or in Python:

import requests

def log_ai_call(provider, model, input_tokens, output_tokens):
    requests.post(
        "https://api.lazy-mac.com/ai-spend/api/v1/log",
        headers={"X-API-Key": "YOUR_KEY"},
        json={
            "provider": provider,
            "model": model,
            "input_tokens": input_tokens,
            "output_tokens": output_tokens
        }
    )

# After every OpenAI call:
log_ai_call("openai", "gpt-4o", 500, 200)

# After every Anthropic call:
log_ai_call("anthropic", "claude-sonnet-4", 1000, 400)
Enter fullscreen mode Exit fullscreen mode

Step 3: Check your dashboard

curl https://api.lazy-mac.com/ai-spend/api/v1/dashboard \
  -H "X-API-Key: YOUR_KEY"
Enter fullscreen mode Exit fullscreen mode

Returns spend by provider, model, day — everything you need.

Step 4: Set a budget alert

curl -X POST https://api.lazy-mac.com/ai-spend/api/v1/budget \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "monthly_limit": 500 }'
Enter fullscreen mode Exit fullscreen mode

Now you'll know before you overshoot.

Bonus: Compare model costs

Wondering if switching from GPT-4o to Claude Sonnet would save money?

curl "https://api.lazy-mac.com/ai-spend/api/v1/compare?from=gpt-4o&to=claude-sonnet-4" \
  -H "X-API-Key: YOUR_KEY"
Enter fullscreen mode Exit fullscreen mode

Instant cost comparison based on your actual usage.

MCP Support

If you're using Claude Code or Cursor, the API has a built-in MCP endpoint:

POST https://api.lazy-mac.com/ai-spend/mcp
Enter fullscreen mode Exit fullscreen mode

Add it as an MCP server and your AI coding tool can track its own costs.

Full Endpoint List

Endpoint Method Description
/api/v1/log POST Log an AI API call
/api/v1/batch-log POST Bulk import usage (Pro)
/api/v1/dashboard GET Spending dashboard
/api/v1/budget GET/POST Budget management
/api/v1/compare GET Compare model costs
/api/v1/forecast GET Forecast monthly spend
/api/v1/optimize GET Optimization tips
/api/v1/export GET Export CSV/JSON (Pro)
/api/v1/models GET All models with pricing
/mcp POST MCP endpoint

Pricing

  • Free: 100 logs/day, 1 provider
  • Pro ($29/mo): Unlimited logs, all 6 providers, budget alerts, batch import, export

Competitors like Finout charge $100+/mo. This is $29.


Links:

Would love to hear your feedback — what features would you want next?

Top comments (0)