Skip to main content
Glama
README.md
# AgentBill — Local-First AI Billing Forensics, Auto-Fix & Agency PDF Invoicing (MIT)

> **Live Local-First Web Workstation (Zero Server Upload):** https://ttthkim-hue.github.io/agentbill/
> **License:** 100% Free, Non-Commercial MIT Open-Source (`LICENSE`)

**AgentBill** is an offline, zero-server-upload toolkit (**Installable CLI + Stdio MCP Server + Local-First Web Workstation**) for developers, startups, and AI automation agencies. Drop raw **OpenAI, Anthropic, Google Gemini, or AWS Bedrock CSV / JSON / JSONL / PDF billing statements** to:

1. **Forensically Isolate Runaway Spend Spikes** — Robust Modified Z-Score (MAD) anomaly detection + token rate-card reconciliation across 25+ major models without needing a proxy installed beforehand.
2. **Generate Vector Dispute Evidence Pack PDFs** — 1-click multi-page vector PDF (`pdf-lib`) containing an embedded daily spend anomaly chart, isolated incident table, rate-card delta reconciliation, and a ready-to-submit provider billing support ticket letter.
3. **Generate Drop-In Preventive Auto-Fix Code** — Calibrated directly to your normal daily baseline: `agentbill-guard.ts` (hourly USD circuit-breaker & smart model router), `litellm-guard.yaml`, and an importable `n8n-circuit-breaker.json` Code Node.
4. **Split Multi-Client Agency Usage into Client-Ready PDF Invoices** — Automatically group spend by `client`/`project`/`api_key`, apply custom markup `%`, monthly retainer, tax, and currency (`USD`/`KRW`/`EUR`), hide or show raw API costs, and batch-export vector client invoice PDFs.

## Quick Start (CLI)

```bash
npm install
npm run build:cli

# 1. Audit any CSV, JSON, JSONL, or PDF billing statement & export Dispute PDF + drop-in fix configs
node bin/agentbill.mjs audit ./openai-usage.csv \
  --dispute-pdf ./dispute-pack.pdf \
  --fix-dir ./fixes

# 2. Split agency CSV across clients & generate individual vector Invoice PDFs
node bin/agentbill.mjs invoice ./agency-nov.csv \
  --margin 100 --retainer 250 --out-dir ./invoices

# 3. CI/CD budget anomaly gate (exits code 2 if anomaly detected)
node bin/agentbill.mjs audit ./daily-usage.csv --fail-on-anomaly --json
```

## MCP Server (Claude Code · Cursor · Antigravity · Codex)

```json
{
  "mcpServers": {
    "agentbill": {
      "command": "node",
      "args": ["path/to/agentbill/bin/agentbill.mjs", "mcp"]
    }
  }
}
```

Exposed MCP tools:
- `agentbill_audit_file`
- `agentbill_generate_dispute_pdf`
- `agentbill_generate_client_invoices`
- `agentbill_generate_fix_configs`

## Non-Commercial MIT Open-Source Notice
AgentBill is 100% free, MIT-licensed open-source software with zero telemetry, zero server uploads, zero payment walls, and zero ads.