Abstract
This document discloses, as enabling public prior art, a computer-implemented protocol for debiting a prepaid credit wallet exactly once for a metered large-language-model (LLM) turn, and for doing so without ever producing either of the two well-documented failure classes of naive metered billing: the double-debit (a retried turn charged twice) and the free turn (a completed provider call that never bills, or that records usage telemetry without a matching charge). The core mechanism is an ordering invariant executed inside one database transaction: after acquiring a row-level exclusive lock on the wallet row, the system performs the metered-usage telemetry INSERT first, guarded by a unique constraint on (accountid, sourceeventid) with an ON CONFLICT DO NOTHING. The success or failure of that INSERT — not a separate lookup, cache, or lock table — is the idempotency gate for the subsequent money movement. On conflict (a duplicate turn), no row is returned, the debit is skipped, and the caller receives { duplicate: true, billed: false }. On a fresh row, a fail-closed balance check runs; insufficient balance throws, which rolls back the telemetry INSERT together with the (never-applied) debit, guaranteeing there is no telemetry-without-charge orphan. On success the wallet is decremented, an append-only ledger row is written, and the usage row is back-linked to the ledger row in the same transaction. Three companion mechanisms complete the protocol: a worst-case pre-call guard that refuses the provider call before any spend, an estimate-on-missing-usage minimum charge so a completed turn is never free, and a structurally admin-immutable wallet (no balance-set code path exists; the markup is pinned by a database CHECK). This disclosure describes the mechanism in enough detail to enable a person of ordinary skill to build it, and thereby to bar its patenting by others.
Creative Commons License

This work is licensed under a Creative Commons Attribution 4.0 License.
Recommended Citation
Assuncao, gustavo matthew, "Usage-Row-Gated Exactly-Once Prepaid Debit Protocol for Metered LLM Turns", Technical Disclosure Commons, ()
https://www.tdcommons.org/dpubs_series/10966