mpp-x402 package adds two custom payment methods to the Machine Payments Protocol (MPP). Use them in your API or client with a compatible x402 facilitator, including Compose. You supply the token, network, recipient and wallet.
This lets music applications expose generation and listening as payable operations that other clients and agents can call. For streaming platforms, batch vouchers avoid an onchain transfer for every segment. You still implement the music operation, pricing and playback controls.
Choose the payment path
To call Rawchunks’ current APIs, use a Rawchunks session. Selecting Tempo Moderato creates a Compose session that spends OUSD; that path does not invoke these MPP extensions. To add MPP payments to your own product, use the guide below. Both client and server need these customx402 methods. Tempo’s built-in charge and session methods have different credentials. MACH and card checkout are separate integrations.
Install the extensions
From a Rawchunks source checkout, copybackend/mpp into your project at vendor/mpp. Use Node.js 22 or newer and run:
vendor/mpp/README.md contains the complete server adapters, approval code and storage requirements. The package is MIT licensed and can be used independently of Rawchunks.
Protect a metered operation
Setnetwork to a CAIP-2 identifier, asset and recipient to token and merchant addresses, and resourceUrl to your endpoint’s absolute URL. maximum is an integer string in token base units. For Moderato, the network is eip155:42431.
Use a facilitator that supports x402 v2 upto with the official EVM Permit2 proof. Check /supported and the required token/contract deployments before enabling the endpoint. Supply durable Store.AtomicStore storage as store, a stable service namespace, and your API domain as realm.
POST at resourceUrl using your framework’s Fetch API route. render is your own operation; compute its billed units on the server and keep them within maximum. Pass the request body unchanged to handle. If your facilitator needs authentication, configure its createAuthHeaders for supported, verify and settle.
Pay from your client
Supply your connected x402ClientEvmSigner as signer and the selected network’s rpcUrl. Fund the token and confirm its Permit2 allowance first; the README includes the exact allowance check and approval transaction. A Compose session approval is a separate allowance.
402 challenge, signs the authorization and checks the Payment-Receipt. Allow the credential header in CORS and expose WWW-Authenticate and Payment-Receipt for browser clients. To retain separate Bearer authentication, set header: 'Payment-Authorization' on the server handler.
Use batch payments for streaming
CopycreateBatchHandler and the matching batch client setup from vendor/mpp/README.md. The adapter registers the official BatchSettlementEvmScheme, channel storage and receiver-authorizer signer, then returns { handle, manager }. Set the endpoint price to one segment or checkpoint. Keep the same scheme instance for accepting vouchers and claiming funds.
Call the batch client’s fetch sequentially for that channel:
segments, songId and consumeSegment belong to your player. The first payment funds a channel; subsequent requests authorize cumulative vouchers. Await each receipt before requesting the next segment. Run await manager.claimAndSettle() in your server’s settlement job to claim vouchers and transfer funds to the receiver. A funded or accepted receipt alone does not confirm treasury settlement.
This supports x402-compatible continuous playback through paid segments or checkpoints. Your application controls delivery and measurement; the generic handler does not meter an indefinite open stream. Persist channel and receipt state, and reconcile uncertain settlements before charging again.
MPP custom methods · MPP challenge binding · Rawchunks session guide