Skip to content

feat: MPP credits/billing for ARES with a guaranteed-profit model#11

Merged
daemon-blockint-tech merged 1 commit into
mainfrom
claude/project-refinement-o9vbfy
Jul 18, 2026
Merged

feat: MPP credits/billing for ARES with a guaranteed-profit model#11
daemon-blockint-tech merged 1 commit into
mainfrom
claude/project-refinement-o9vbfy

Conversation

@daemon-blockint-tech

Copy link
Copy Markdown
Owner

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_ENABLED unset, nothing here runs, so default audits and the hermetic test suite are untouched.

The model

audit → token usage → provider $ (pricing.ts)
                     → × markup   (profit.ts, margin floored)
                     → credits    (credits.ts: system → on-demand)
                     → MPP settle overflow (mpp.ts, HTTP-402)
  • pricing.ts — per-model USD/MTok rate table (Anthropic/OpenRouter rates incl. prompt-cache multipliers and $10/1k web 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.01 by default (100 credits = $1).
  • mpp.ts — MPP protocol shapes (Challenge → Credential → Receipt) with a hermetic LocalMppClient; a real HTTP-402 client attaches behind MPP_ENDPOINT, off by default like the CUA analyzer.
  • profit.ts — the profit guarantee. The effective markup is floored at 1 + BILLING_MIN_MARGIN_PCT, credits are rounded up, and every audit is billed at least BILLING_MIN_CHARGE_CREDITS. A run can never settle below provider cost, even if BILLING_MARKUP is 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.ts wires a metering chat wrapper and prints the bill after each audit.
  • config.ts — all knobs from env (BILLING_*, MPP_*), documented in .env.example.

Verification

typecheck ✓ · lint ✓ · test ✓ (11 files, 85 tests — +34) · build ✓
npm ci (npm 10.8.2, runner version) ✓

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

  • No new runtime dependencies (reuses uuid), so the lockfile is unchanged and npm ci stays green.
  • Opt-in by design — BILLING_ENABLED defaults off; the hermetic graph/test suite runs exactly as before.

🤖 Generated with Claude Code

https://claude.ai/code/session_017ZB4NjNJZ6zWTqypbSiihy


Generated by Claude Code

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
daemon-blockint-tech marked this pull request as ready for review July 18, 2026 01:37
@daemon-blockint-tech
daemon-blockint-tech merged commit 33708a0 into main Jul 18, 2026
2 checks passed
@daemon-blockint-tech
daemon-blockint-tech deleted the claude/project-refinement-o9vbfy branch July 18, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants