Skip to content

Billing Architecture Alignment - #3

Open
1amKhush wants to merge 6 commits into
ContextVM:feat/billingfrom
1amKhush:feat/billing
Open

Billing Architecture Alignment#3
1amKhush wants to merge 6 commits into
ContextVM:feat/billingfrom
1amKhush:feat/billing

Conversation

@1amKhush

@1amKhush 1amKhush commented Jul 27, 2026

Copy link
Copy Markdown

Summary

Addresses the billing audit in #1 by routing prepaid billing through CEP-8, fixing free-model output capping, and making the regular CLI payment-aware.

Changes

CEP-8 billing

  • Added CEP-8 resolvePrice handling:
    • Funded chat.complete calls return waivePrice().
    • Unfunded calls receive an immediate -32000 policy rejection.
    • balance.topup returns a Lightning quotePrice(sats).
  • Credits the prepaid USD ledger only after payment verification.
  • Added NWC Lightning processor configuration.

Payment-aware client and CLI

  • Wrapped MuxllClient with CEP-8 client payment middleware.
  • Fixed streamed requests waiting indefinitely when authorization fails before the stream opens.
  • Added typed client methods for reading and topping up balances.
  • Added CLI commands:
    • muxll balance
    • muxll topup --usd <amount>
  • Added manual BOLT11 invoice display and payment confirmation.
  • Added MUXLL_CLIENT_PRIVATE_KEY for maintaining the same prepaid identity across CLI invocations.
  • Added an actionable top-up hint when chat is rejected for insufficient balance.

Pricing

  • Fixed free-output models defaulting to a one-token output cap when no explicit user or model limit is provided.
  • Free models now fall back to their context window.

Tests and documentation

  • Added regression coverage for:
    • CEP-8 policy rejection.
    • Unfunded streamed requests.
    • Lightning top-up and ledger crediting.
    • Balance retrieval using the same client identity.
    • Free-model output limits.
    • Actionable CLI billing errors.
  • Documented billing, NWC, persistent client identity, balance, and top-up configuration.

Verification

  • Typecheck passes.
  • Lint passes.
  • Formatting checks pass.
  • Full test suite: 79 passed, 2 skipped, 0 failed.
  • Live Lightning smoke test completed successfully:
    • BOLT11 invoice generated.
    • Payment accepted.
    • Ledger credited.
    • Chat completed.
    • Actual usage debited from the prepaid balance.

Refs #1

Copilot AI review requested due to automatic review settings July 27, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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