Access Paid in Work
An HTTP API or MCP server charges per call in work: a 402 with a Z-bit price, paid with bound notes.
Summary
A service, an HTTP API or an MCP server, charges for a call in work instead of with an account or an API key. It states a price as a Z-bit. The caller pays with Sharenotes bound to the service's origin and current epoch.
Notes can be mined ahead of time, by the caller or a provider, so paying is instant. Each note is spendable once, at one origin, for two of the service's epochs.
API buildersMCP server authorsAI agentscallers
Kinds and tags
| Kind | Name | How |
|---|---|---|
| 27235 | HTTP Auth (NIP-98) | keyed mode only: sent in the Sharenote-Auth header, signed by the notes' identity |
Overview
| Step | Who | Does |
|---|---|---|
| 1. Price | service | answers an unpaid call with 402 Payment Required and its price |
| 2. Mine | caller or provider | mines notes bound to the service, ahead of time |
| 3. Pay | caller | repeats the call with notes worth at least the price |
| 4. Serve | service | checks the notes, records them as spent, serves |
Notes go straight to the service in a header. They need not be published to relays. Without keyed, a note is a bearer payment: whoever presents it first spends it. So never publish an unkeyed note before spending it.
The price header
A 402 carries Sharenote-Price: one price per accepted algorithm, separated by ,; fields key=value separated by ;.
| Field | Required | Value |
|---|---|---|
g | yes | an accepted algorithm |
z | yes | the price, a Z-bit |
epoch | yes | the epoch to mine for, below 2^32 |
until | yes | unix time the epoch ends |
period | yes | epoch length in seconds, at least 1 |
max | yes | most notes per call, at least 16 |
size | no | largest record in bytes, default 256; at least 2048 for an -aux price |
keyed | no | 1: calls must carry a caller proof |
session | no | seconds of access one payment buys |
Service fields are identical in every price. Refusals carry Sharenote-Error: count, size, proof, binding, algorithm, duplicate, spent, amount, caller or session.
Paying
A payment note's binding is exactly 36 bytes:
binding = SHA-256(origin) ‖ epoch (4 bytes, big-endian)
The origin is serialized as in RFC 6454: lowercase scheme and host, default port omitted, for example https://api.example. Only https URLs with a domain-name host are payable; the host is normalized to an IDNA A-label. The caller takes the origin from the URL that returned the 402, never from the response. The service uses its configured public origin, never the Host header.
The caller sends its notes in one Sharenote header: lowercase hex records separated by ,, all in one algorithm. Their values add by SNP-01, compared by weight.
Service checks
Checks run in order and stop at the first failure. Checks 1 to 9 hash no work.
| # | Check | Refusal |
|---|---|---|
| 1 | at most max notes | count |
| 2 | each at most 2 · size hex characters | size |
| 3 | lowercase hex; SNP-01 record checks 1 to 4 | proof |
| 4 | binding is SHA-256(origin) and the current or previous epoch | binding |
| 5 | one algorithm, and it is priced | algorithm |
| 6 | no record twice in the call | duplicate |
| 7 | none in the spent-set (keyed by SHA-256 of the record) | spent |
| 8 | total weight ≥ w(T(z)) | amount |
| 9 | if keyed: one identity and a valid Sharenote-Auth | caller |
| 10 | each note's work passes, heaviest first | proof |
On success the service records all notes as spent atomically, then serves. A forged payment costs the service one work hash. Overpayment is not refunded.
Epochs, keyed mode and sessions
Epochs. Epoch e runs from E0 + e · period to until = E0 + (e+1) · period. A service accepts notes for its current and previous epoch only, so its spent-set covers two epochs. The epoch never decreases. After losing spent entries, a service refuses payments until its epoch reaches h + 2. All acceptors at one origin share one spent-set.
Keyed mode. With keyed=1, all notes share one identity and the call carries Sharenote-Auth: a base64 NIP-98 kind:27235 event signed by that identity, whose u is the origin plus the request target and which has one ["sharenote", <SHA-256 of the records>] tag. Copied notes become useless.
Sessions. With session=<seconds>, a payment returns Sharenote-Session: <token>, which covers every charged call for that long. The token is a bearer secret.
MCP
Over HTTP, an MCP server uses the same headers. The 402 body is a JSON-RPC error, and the client retries the same request with Sharenote.
Over stdio, the server runs on the caller's machine, so it forwards notes to a backend that runs the service checks for its own HTTPS origin. The client binds notes to the backend origin in its own configuration, never one the server reports. Without a configured origin, or on a mismatch, it must not pay.
{"code": 402, "message": "Payment Required",
"data": {"origin": "https://api.example",
"prices": [{"g": "sha256d", "z": "20z00", "epoch": 7,
"until": 1731003600, "period": 3600, "max": 16}]}}
The client retries with params._meta.sharenote, an array of hex records. Keyed mode and sessions are HTTP-only.
Worked example
A service at https://api.example charges 12z00 in sha256d, epoch 7, not keyed:
Sharenote-Price: g=sha256d;z=12z00;epoch=7;until=1731003600;period=3600;max=16
Its payment binding is SHA-256("https://api.example") ‖ 00000007:
e91cdb47052c095bd090354d5fe4d27c857def7e585248d963ca1d895232f667 00000007
Alice's provider has mined three notes credited to her with that binding, without her key: one 12z00 and two 11z00.
| Call | Answer |
|---|---|
| no payment | 402, the price |
the 12z00 note | served |
| the same note again | 402, spent, no work hash |
both 11z00 notes (2^11 + 2^11 = 2^12) | served |
a fresh 11z00 alone | 402, amount |
| the same note twice in one header | 402, duplicate |
| a note mined for another origin | 402, binding |
| a note for epoch 7, once the epoch is 9 | 402, binding |
Try it
Pay an API with work
A 402 round trip: price, mine, pay, get served, and replay to see 'spent'.
Buy work
Order notes from a mining provider when your device can't mine.
Mint a note
Mine a real sha256d note in your browser and inspect every byte of its SN4U record.
Rendered from soprinter/snps/SNP-09.md. The full text has every rule; this page condenses it.
