KEYS OFF-CHAIN
Contracts never see a key, a prompt, or a completion. Single mode: keys live in the seller's own relay. Shared mode (live): sealed inside a platform TEE relay (see policy). The escrow holds USDC — nothing else.
x402 / agentic payment rails · trust-minimized API supply
Idle official-plan quota, sold by the call. KIMI / MOONSHOT FIRST
In plain words: paying for a Kimi plan you never fully burn through? Sell the leftover quota by the call — buyers pay per request, you keep the plan.
Sellers rent out the spare quota of their official LLM subscription plans — a relay holds their own platform key and forwards only to the provider's official endpoint. Buyers lock a few cents of USDC on-chain and pay per request. An immutable escrow holds the funds, settlement is priced on relay-reported usage in three tiers, and every call comes back with an EIP-712 receipt anyone can verify. Seller keys stay off-chain; the escrow holds only USDC. Custody modes, receipt limits & refund rules → policy.
live values — read from the Registry contract; relays probed via /health
$ tokenshare deposit --amount 0.50
tx 0x9f2e…a1c4 confirmed · balance 500000
$ tokenshare lock --seller 0x7A3f…9c2E --max 0.05
paymentId 42 · locked 50000 · ttl 600s
$ tokenshare call "summarize block 0x1f3a…" --model kimi-for-coding
relay: isValid(42) → true · forwarding to api.moonshot.cn
POST /v1/chat/completions → 200 OK · 1.24s
usage cached_in 12000 · in 26400 · out 2140
settle actual 45552 · diff 4448 → buyer balance
receipt EIP-712 ✓ verified · upstream api.moonshot.cn · kimi-for-coding
illustrative trace · amounts are USDC native units (6 decimals)
Preview of the configured sellers (config.js) — Registry.getListing() live: endpoint, models, per-model three-tier pricing, active flag. Pick a model chip to see its tier prices. Relay dots probe each listing's /health live from your browser.
Historical Escrow v3.1 proof: a full deposit → lock → per-call capture → settle round, executed on Monad testnet against Escrow v3.1 0x157C…71aD5 ↗ — every link below opens the real transaction. The current Escrow v3.2 0xe4D5…514c ↗ adds an opt-in settle delegate — now authorized by both live shared-mode sellers (the TEE relay's signer); see policy.
domain TokenShare Relay v1 · chainId 10143
paymentId 1 · usage cached 0 · in 24 · out 88
actual 312 units ($0.000312) · model kimi-for-coding
upstream api.kimi.com · seller 0x38c2…8Dd6
sig 0xd955…1c2c ✓ verified — recovers to the seller address
One call, five transitions. Funds move only through the escrow; the relay never touches money and the contract never touches keys.
deposit()
Buyer funds an escrow balance in USDC. One deposit backs many calls.
lock(seller, maxAmount, ttl)
Reserves up to maxAmount for one seller and returns a fresh paymentId — default ttl 600s.
isValid(paymentId)
Relay checks the lock on-chain before forwarding. An invalid proof gets a 402 — zero cost, never upstreamed.
settle(paymentId, actual)
Usage priced in three tiers; the seller settles actual ≤ max and the difference returns to the buyer.
refund(paymentId)
No settle before the deadline → anyone releases the lock. The un-captured remainder returns to the buyer.
$ cast send $USDC "approve(address,uint256)" $ESCROW 500000
$ cast send $ESCROW "deposit(uint256)" 500000 --rpc $MONAD_RPC
$ cast send $ESCROW "lock(address,uint256,uint256)" $SELLER 50000 600
# relay: Escrow.isValid(paymentId, seller=self, minAmount=est) — false → 402, no forward
# relay: forward to api.moonshot.cn with seller's own official-plan key · usage from response
# pricing: 12000×cached + 26400×in + 2140×out = 45552 units = 0.045552 USDC
$ cast send $ESCROW "settle(uint256,uint256)" $PID 45552 # seller only
# buyer diff 4448 → balances[buyer] · X-Receipt: EIP-712 {paymentId, usage, actual, seller, upstreamHost, model}
Four states, five transitions, no admin path. Hover a state to trace its edges.
deposit()→ Depositedlock(seller, maxAmount, ttl=600)→ Locked · emits paymentIdsettle(paymentId, actual)→ Settled · seller only · diff → buyer balancerefund(paymentId)→ Refunded · after deadline, anyone can triggerwithdraw()→ idle · unencumbered balance outThe things the protocol refuses to do are the features.
Contracts never see a key, a prompt, or a completion. Single mode: keys live in the seller's own relay. Shared mode (live): sealed inside a platform TEE relay (see policy). The escrow holds USDC — nothing else.
Every request is gated by an on-chain isValid(paymentId) check. Unpaid calls get a 402 and cost the seller nothing. Payment proof comes first, inference second.
The relay boots only against the provider's official host allowlist (api.moonshot.cn/.ai, api.openai.com) and rejects models whose prefix doesn't match the host — no lookalike endpoints, no poisoned models. Every receipt records upstreamHost + model.
No proxies, no admin keys, no upgrade path. Chain-agnostic by config, delivered on MONAD TESTNET · 10143 with immutable contracts — what you read is what you get.
Shared mode runs one multi-seller relay inside a Phala TDX enclave: seller keys enroll encrypted and stay sealed inside; buyers receive scoped credentials, never the raw key. The Console VERIFY step checks the live relay against a pinned deployment identity — a verifiable boundary, not a blank cheque. Isolation shrinks operator access without erasing it; pin checks are not full hardware quote verification; a signed receipt attests the bill, not what the model answered.