MPP payments
The Machine Payments Protocol (MPP) enables crypto-native, per-request payments on the Tempo blockchain. MPP is an additive payment method alongside Stripe — you choose which to use on each request.How it works
MPP uses an HTTP 402 challenge/response flow:- You send a request to the gateway.
- The server returns
402 Payment Requiredwith a challenge containing the price, token, and recipient. - You sign a Tempo transaction matching the challenge.
- You retry the request with the signed transaction as a credential in the
Authorizationheader. - The server verifies the payment on-chain and returns the response with a
Payment-Receiptheader.
Supported networks
Set
TEMPO_TESTNET=true in your environment to use the testnet during development.Plugin pricing
Each plugin has a fixed per-request price in USD, settled in pathUSD on Tempo.Payment credential
After receiving a 402 challenge, build and sign a credential to send with your retry:Authorization header format
Credential structure
402 challenge structure
When a payment is required, the server responds with:Challenge fields
Verification
The server verifies your credential by checking:- The transaction is hex-encoded and starts with the
0x76type marker. - The recipient address matches the expected recipient.
- The token address matches the expected currency (pathUSD).
- The amount matches the plugin price (within a 0.0001 tolerance).
- The nonce matches the original challenge nonce.
Receipt
On success, the server returns:- A
Payment-Receiptresponse header containing the transaction hash. - The
payment.receiptfield in the JSON response body.
Client usage
UsemppFetch to handle the full 402 flow automatically:
mppFetch options
mppFetch result
Check MPP support
You can check whether an endpoint supports MPP payments:OPTIONS request and checks for a WWW-Authenticate: Payment header.
Sessions
Payment sessions provide off-chain, per-call billing without an on-chain transaction for every request. This reduces latency to sub-100ms per call while still settling on-chain periodically.How sessions work
- Open a session — deposit pathUSD (minimum 100.00) into escrow via
POST /api/wallet/sessions. - Make gateway calls — include
X-Session-IdandX-Wallet-Addressheaders on your gateway requests withX-Payment-Method: session. The gateway auto-debits your session balance using off-chain vouchers — no 402 round-trip needed. - Automatic settlement — when accumulated vouchers reach $5.00 or after one hour, the server batches them into a single on-chain transaction.
- Close the session — call
DELETE /api/wallet/sessions?sessionId=ses_...to settle any remaining vouchers and return unused funds.
Session configuration
Session states
Session initialization
When opening a session, you must provide a viemAccount to the tempo.session() call. If no account is provided, the SDK throws immediately with a descriptive error message and an example fix. This prevents cryptic errors during channel close.
Redis store for session state
By default, session state is stored in memory. For production deployments where you need persistence across restarts or across multiple server instances, use theStore.redis() adapter. It works with standard Redis clients including ioredis, node-redis, and Valkey.
BigInt serialization automatically, so session voucher amounts are stored and retrieved without data loss.
When to use sessions vs. per-request MPP
- Sessions are ideal for high-frequency agent calls where sub-100ms billing latency matters (e.g., chat, real-time orchestration).
- Per-request MPP (the standard 402 flow) is better for infrequent or large-value calls where on-chain settlement per request is acceptable.
Troubleshooting
402 response with no MPP challenge
402 response with no MPP challenge
The plugin may not have a configured price. Only plugins listed in the pricing table above support MPP payments.
Credential verification failed
Credential verification failed
- Ensure the
challengeNoncematches the nonce from the 402 response. - Verify the transaction amount matches the challenge amount exactly.
- Check that you are using the correct network (mainnet vs. testnet).
Transaction type error
Transaction type error
The transaction hex must begin with
0x76 (the Tempo transaction type marker). Ensure your signing implementation includes this prefix.