TECHDEV 建立 aibill CLI,按工具呼叫追蹤智能體成本
My agent burned $31 in a week. I asked which tool ate it - so I built the receipt.
TECHDEV 建立 aibill CLI,從 Claude Code 工作階段或通用 MCP 工具呼叫 JSONL,按工具呼叫統計 token 數及估算美元費用。
I can tell you my AI bill to the cent. Ask me which tool call caused it and I used to shrug.
Last week I stared at my provider dashboard: a clean per-key total, zero line items. Which MCP tool ate the budget? Which framework surface did the agent re-read forty times? Was that "heavy" framework actually heavy for my workload? The dashboard had no answers. Hacker News had opinions - 215 points on ChatGPT/Codex limit merges, 291 on the AI cost of JavaScript frameworks. One dev.to author cut their MCP server from 15 tools to 4 by hand-counting tokens with tiktoken. All vibes. No receipts.
So I built the receipt: aibill, a small CLI that reads your real agent session transcripts and attributes tokens and estimated USD to every tool call.
What it does
Four commands, one idea: measure first, cut second, verify third.
aibill scan ~/.claude/projects/my-project/
TOOL CALLS MEAN TOK P95 TOK TOTAL TOK USD*
------------------------------------------------------------------------
mcp__doc_lookup 30 23,265 26,947 697,938 $16.55
mcp__codebase_search 24 15,427 18,889 370,241 $7.81
...
aibill scan parses Claude Code session JSONL (or a generic MCP tool-call JSONL you feed it) and prints per-tool rows - call counts, mean and p95 tokens, totals, USD - plus per-model and per-framework-surface breakdowns. aibill cut --top 3 then suggests cut candidates: duplicated calls with identical inputs, tools whose huge outputs were never referenced again, costly one-shot tools. Candidates, not autopilot - it changes nothing on its own.
Then the part I actually wanted: aibill diff --before old.jsonl --after new.jsonl measures the before/after. On the demo run: 137 calls, 1,425,208 tokens, $31.68 estimated, one doc-lookup tool eating 52% of the bill. After trimming the obvious waste: -49.0% tokens, -52.3% USD - measured on the two transcripts, not promised about your future. aibill budget --max-usd 20 exits non-zero when projected spend exceeds the cap, so the same check runs in CI.
(The GIF runs on synthetic seeded fixtures - run scan on your own transcripts for real numbers.)
The honest fine print
- USD is an estimate from public rate cards (verified 2026-11-02, sources in
src/pricing.ts), not your invoice. Discounts, caching, tiers and regional multipliers change the real number. Unknown models price at $0 and get flagged, never guessed. Bring contracted rates with--pricing-file. - Claude Code logs token usage per message, so when one message carries several tool calls the usage is split evenly and flagged as shared attribution in the report.
- aibill measures. It does not reduce tokens, rewrite prompts, or compress anything. Any "% saved" you see from
diffwas measured on the two transcripts you gave it. - It reads local transcripts only - never calls billing APIs, never touches credentials, never sends anything anywhere. Transcripts contain your proprietary code; the tool is 100% offline by design. Zero runtime dependencies, Node 20+.
Where rivals beat us
The AWS "MCP Token Cost" piece measures something aibill does not: the upfront tool-schema/context tax - 55k tokens just to describe GitHub MCP's 93 tools before a single call happens. aibill attributes per-call tokens from transcripts; it is blind to that schema tax. The two are complementary: use their number for "should this MCP server be connected at all", use aibill for "now that it is, which 3 calls are eating the bill." Provider dashboards win on authoritative totals; hand-rolled tiktoken audits win on nothing except proving the demand is real.
Try it
Install from source for now (aibill-cli isn't on npm yet - publish pending):
git clone https://github.com/techdevfun/aibill.git
cd aibill && npm install -g .
aibill scan <your-transcript.jsonl>
The point was never the $31. It's that every cost conversation about coding agents is currently vibes - headline benchmarks measured on someone else's workload, gut-feel tool cuts, surprise limit changes. A receipt won't make the bill smaller by itself. But at least now you can argue with it.
Repo: https://github.com/techdevfun/aibill - MIT, issues and redacted-transcript bug reports welcome.
來源:DEV Community · dev.to
