feat: MPP credits/billing for ARES with a guaranteed-profit model#11
Merged
Merged
Conversation
Monetize ARES audits. A new src/billing/ subsystem meters each audit's LLM token usage, prices it, marks it up, and charges it in credits against a two-tier account — settling pay-as-you-go overflow via the Machine Payments Protocol (mpp.dev, HTTP-402). Fully opt-in: with BILLING_ENABLED unset nothing runs, so default audits and the hermetic test suite are unaffected. - pricing.ts: per-model USD/MTok rate table (Anthropic/OpenRouter rates incl. prompt-cache multipliers and web-search cost) + cost computation. Normalizes OpenRouter ids (anthropic/claude-3.5-sonnet, dot versions) to canonical keys. - credits.ts: two-tier ledger — prepaid "system credits" drawn first, then pay-as-you-go "on-demand" overflow (optionally capped); full audit trail. - mpp.ts: Machine Payments Protocol shapes (Challenge/Credential/Receipt) and a hermetic LocalMppClient; a real HTTP-402 client attaches via MPP_ENDPOINT. - profit.ts: guarantees profit — effective markup floored at 1 + minMarginPct, credits rounded up, and a minimum per-audit charge, so a run can never settle below provider cost. Reports cost/revenue/profit/margin. - meter.ts + usage.ts: accumulate token usage from LangChain responses and settle a run; index.ts wires a metering chat wrapper and prints the bill. - config.ts: all knobs from env (BILLING_*, MPP_*), documented in .env.example. Tests: +34 (51 -> 85) across pricing, credits, profit, and an end-to-end meter/MPP settlement. Verified end-to-end against the live graph: usage is metered across the run and settled at a positive margin (e.g. $0.1044 cost -> $0.14 revenue, 25.4% margin). typecheck, lint, build, and npm ci (npm 10.8.2) all green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZB4NjNJZ6zWTqypbSiihy
daemon-blockint-tech
marked this pull request as ready for review
July 18, 2026 01:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Turn ARES into a paid service: meter each audit's LLM usage, charge it in credits, and guarantee a profit on every run. Settlement of pay-as-you-go usage uses the Machine Payments Protocol (MPP) — the HTTP-402 machine-to-machine payment standard. Fully opt-in: with
BILLING_ENABLEDunset, nothing here runs, so default audits and the hermetic test suite are untouched.The model
pricing.ts— per-model USD/MTok rate table (Anthropic/OpenRouter rates incl. prompt-cache multipliers and$10/1kweb search), plus cost computation. Normalizes OpenRouter ids (anthropic/claude-3.5-sonnet, dotted versions) to canonical keys.credits.ts— two-tier ledger: prepaid system credits drawn first, then pay-as-you-go on-demand overflow (optionally capped), with a full audit trail.1 credit = $0.01by default (100 credits = $1).mpp.ts— MPP protocol shapes (Challenge → Credential → Receipt) with a hermeticLocalMppClient; a real HTTP-402 client attaches behindMPP_ENDPOINT, off by default like the CUA analyzer.profit.ts— the profit guarantee. The effective markup is floored at1 + BILLING_MIN_MARGIN_PCT, credits are rounded up, and every audit is billed at leastBILLING_MIN_CHARGE_CREDITS. A run can never settle below provider cost, even ifBILLING_MARKUPis misconfigured below 1. Each settlement reports cost / revenue / profit / margin.meter.ts+usage.ts— accumulate token usage from LangChain responses and settle a run;index.tswires a metering chat wrapper and prints the bill after each audit.config.ts— all knobs from env (BILLING_*,MPP_*), documented in.env.example.Verification
Verified end-to-end against the live audit graph: usage was metered across the run and settled at a positive margin — $0.1044 provider cost → $0.14 revenue → $0.0356 profit (25.4% gross margin) — drawn from prepaid credits, with on-demand overflow settling through MPP in the on-demand test. The margin-floor, minimum-charge, and below-cost-markup cases are all covered by tests.
Notes
uuid), so the lockfile is unchanged andnpm cistays green.BILLING_ENABLEDdefaults off; the hermetic graph/test suite runs exactly as before.🤖 Generated with Claude Code
https://claude.ai/code/session_017ZB4NjNJZ6zWTqypbSiihy
Generated by Claude Code