TypeScript SDK for the Machine Payments Protocol
Documentation · Install · Quick Start · Examples · CLI · Payments Proxy · Protocol
Full documentation, API reference, and guides are available at mpp.dev/sdk/typescript.
npm i mppximport{Mppx,tempo}from'mppx/server'constmppx=Mppx.create({methods: [tempo({currency: '0x20c0000000000000000000000000000000000000',recipient: '0x742d35Cc6634c0532925a3b844bC9e7595F8fE00',}),],})exportasyncfunctionhandler(request: Request){constresponse=awaitmppx.charge({amount: '1'})(request)if(response.status===402)returnresponse.challengereturnresponse.withReceipt(Response.json({data: '...'}))}import{privateKeyToAccount}from'viem/accounts'import{Mppx,tempo}from'mppx/client'Mppx.create({methods: [tempo({account: privateKeyToAccount('0x...')})],})// Global fetch now handles 402 automaticallyconstres=awaitfetch('https://mpp.dev/api/ping/paid')| Example | Description |
|---|---|
| charge | Payment-gated photo generation API |
| charge-wagmi | Payment-gated charge with Wagmi + React |
| session/multi-fetch | Multiple paid requests over a single payment channel |
| session/sse | Pay-per-token LLM streaming with SSE |
| stripe | Stripe SPT charge with automatic client |
npx gitpick wevm/mppx/examples/chargemppx includes a basic CLI for making HTTP requests with automatic payment handling.
# create account - stored in keychain, autofunded on testnet
mppx account create
# make request - automatic payment handling, curl-like api
mppx example.comYou can also install globally to use the mppx CLI from anywhere:
npm i -g mppxmppx exports a Proxy server handler so that you can create or define a 402-protected payments proxy for any API.
import{openai,stripe,Proxy}from'mppx/proxy'import{Mppx,tempo}from'mppx/server'constmppx=Mppx.create({methods: [tempo()]})constproxy=Proxy.create({services: [openai({apiKey: 'sk-...',routes: {'POST /v1/chat/completions': mppx.charge({amount: '0.05'}),'POST /v1/completions': mppx.stream({amount: '0.0001'}),'GET /v1/models': mppx.free(),},}),stripe({apiKey: 'sk-...',routes: {'POST /v1/charges': mppx.charge({amount: '0.01'}),'GET /v1/customers/:id': mppx.free(),},}),],})createServer(proxy.listener)// Node.jsBun.serve(proxy)// BunDeno.serve(proxy.fetch)// Denoapp.use(proxy.listener)// Expressapp.all('*',(c)=>proxy.fetch(c.req.raw))// Honoapp.all('*',(c)=>proxy.fetch(c.request))// ElysiaexportconstGET=proxy.fetch// Next.jsexportconstPOST=proxy.fetch// Next.jsThis exposes the following routes:
| Route | Pricing |
|---|---|
POST /openai/v1/chat/completions | charge $0.005 |
POST /openai/v1/completions | stream $0.0001 per token |
GET /openai/v1/models | free |
POST /stripe/v1/charges | charge $0.01 |
GET /stripe/v1/customers/:id | free |
Built on the "Payment" HTTP Authentication Scheme. See mpp-specs for the full specification.
MIT