Skip to content

feat(ledger): operator-authed POST /.admin/tokens/debit - #9

Merged
huhn511 merged 2 commits into
mainfrom
feat/ledger-debit-endpoint
Jun 20, 2026
Merged

feat(ledger): operator-authed POST /.admin/tokens/debit#9
huhn511 merged 2 commits into
mainfrom
feat/ledger-debit-endpoint

Conversation

@huhn511

Copy link
Copy Markdown
Contributor

What

Adds POST /.admin/tokens/debit — the metering counterpart of mint. Operator-authed; debits a WebID's MIND balance and returns 402 insufficient_balance when out of MIND. Thin wrapper over the existing debit trait primitive (same shape as admin_mint).

Why

mind-node has no external LLM-proxy endpoint — metering only happens internally for pod scripts (Pod.llm). The Builder/Slides Next apps can't use that path, so they meter via explicit debit: check balance (GET /.admin/tokens?owner=), then debit by WebID after each LLM call. mint already covers the signup grant. This is the unblocker for the free-LLM onboarding allotment (Builder + Slides).

Tested

  • End-to-end against a live server: mint 100 → debit 30 → debit 70 → 402 on empty → 401 without operator token → 400 on amount 0. Hash-chained history correct.
  • cargo test -p solidrs-ledger 20/20 pass; clippy + rustfmt clean.
  • docs/openapi.json regenerated; drift gate (scripts/gen-openapi.sh --check) green.

🤖 Generated with Claude Code

Adds the metering counterpart of mint: an operator-authed endpoint that
debits a WebID's MIND balance, returning 402 insufficient_balance when the
owner is out of MIND. Wraps the existing `debit` trait primitive (balance
check + append-only debit entry) — the same shape as admin_mint.
External LLM chokepoints (Slides' /api/generate, the Builder git bridge)
spend a user's free allotment on their behalf with the operator token,
rather than requiring a user-signed transfer. The 402 is their signal to
fall back to the user's own key.
Regenerates docs/openapi.json (drift gate).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Review follow-up — keep the lib.rs route inventory in sync with the new endpoint.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@huhn511
huhn511 merged commit 4ae25e6 into mainJun 20, 2026
6 of 8 checks passed
@huhn511
huhn511 deleted the feat/ledger-debit-endpoint branch June 20, 2026 17:08
@mind-release-botmind-release-botBot mentioned this pull request Jun 20, 2026
Sign up for freeto 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.

1 participant

@huhn511