design draft

57. Metering and receipts

Status: unimplemented — design draft. This chapter is a plan for the owner to edit. It ships no code yet, and paths marked planned do not exist.

Premise

Paid calls happen. This chapter counts them in a way nobody has to take on trust: every paid call writes a signed receipt, and the totals can be recomputed by anyone.

Draft

An author who is paid "for all paid usage" has one question: how do I know the count is right? On a closed platform you can't know. Here the count is built from receipts.

A receipt is a signed record of one paid call. It names the release that was called, by hash. It gives the price, the time, and the split of the price among the people owed. It carries proof of the payment. It does not carry what the call was about. Your request and the result stay private.

A meter turns receipts into totals: per release, per author, per day. The meter is a plain program over public records, so an author can run it and get the same total we do. Episode 37 asks for this at the start: a flow of funds with public accounting.

Three cases need rules. A call that fails after payment is refunded or not charged, and the receipt says which. A plugin that calls another paid plugin produces a chain of receipts, and each author is owed for their link. And our own use is marked: calls made by us, by our agents and by tests are excluded from the numbers that describe real use, though authors are still paid for them if they were paid calls.

Receipts are also what the reputation of chapter 60 reads. Paid use is evidence that people found a member worth money, and it is costly to fake.

What we build

A plan for what this chapter ships once the draft is approved:

  • A receipt record for every paid call: release hash, price, split and payment proof, with no private content.
  • A meter that computes totals from receipts, shipped so that authors can run it themselves.
  • Rules for failed calls, chained calls and our own use.

It builds on what exists today:

On the protocol (chapter 65):

RecordSchemaCarriageToday
Receipt for a callopenagents.receipt.v1 ExecutionReceipt (spec 16.3)HTTP: the X-Receipt header or a response field; Nostr: inside kinds 3204 and 3201Spec sketch; no .proto file
Proof of paymentopenagents.payment.v1 PaymentReceipt, PaymentEvidence (spec 26.5)With the receiptSpec sketch; no .proto file
Totalsopenagents.ledger.v1 Entry, Statement (spec 26.6)HTTPSpec sketch; no .proto file

The chapter's check

  • Source: pay/receipt-policy.coax and pay/call-meter.coax, run on a case of four paid calls to a fake x402 service with recorded answers: a plain call, a call that fails after payment, a plugin that calls another paid plugin, and a test call of our own.
  • Trace: under the controlled clock, the five receipts and the meter's totals per release, per author and per day. Each receipt prints the release hash, the price in millisats, the split and the payment proof, and no request text. The failed call's receipt reads refunded. Our test call is left out of the use totals and kept in the author totals.
  • Refusal: a receipt whose split does not add up to its price, or whose signature does not verify, is not counted. The meter prints the receipt's ID and refused: split does not equal price or refused: bad signature, and the totals do not change.
  • Independent check: the totals, worked out by hand from the five receipts and written in the case file, and a second meter of a few dozen lines, written from spec 26.6 alone, that sums the same receipts and prints the same totals.

Shipped paths: `pay/receipt-policy.coax` (#14060, canonical JCS openagents.capability.receipt.v1 codec and public call meter, exercised in `openagents/examples/capability-economy-e2e.coax`).

Planned paths: pay/call-meter.coax, beside the speech meter in `pay/voice-meter.coax`.

Sources

Open questions for the owner

  1. How public is the ledger: every receipt, or totals per release with receipts shown only to the author and the payer?