# mppx

Latest version **0.10.1** (published 2026-09-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install mppx
pnpm add mppx
yarn add mppx
bun add mppx
```

Provides the command `mppx`.

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.10.1 |
| Published | 2026-09-15 |
| First published | 2026-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 4.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 173 |
| Maintainers | awkweb, jmoxey, brendan_j_ryan |

## Links

- npm: https://www.npmjs.com/package/mppx
- Repository: https://github.com/wevm/mppx
- Homepage: https://github.com/wevm/mppx#readme
- Issues: https://github.com/wevm/mppx/issues
- npm.io page: https://npm.io/package/mppx

## Dependencies (5)

- [ox](https://npm.io/package/ox.md) 0.14.33
- [zod](https://npm.io/package/zod.md) ^4.4.3
- [@stripe/stripe-js](https://npm.io/package/@stripe/stripe-js.md) 9.13.0
- [eventsource-parser](https://npm.io/package/eventsource-parser.md) 3.1.1
- [structured-headers](https://npm.io/package/structured-headers.md) 2.0.3

## Recent versions

- 0.10.1 (latest) — 2026-09-15
- 0.0.0-main-20260917162003 (main) — 2026-09-17
- 0.0.0-main-20260916185212 — 2026-09-16
- 0.0.0-main-20260915213256 — 2026-09-15
- 0.10.0 — 2026-09-15
- 0.0.0-main-20260914191442 — 2026-09-14
- 0.0.0-main-20260914184241 — 2026-09-14
- 0.0.0-main-20260914162044 — 2026-09-14
- 0.0.0-main-20260911134810 — 2026-09-11
- 0.0.0-main-20260910213138 — 2026-09-10
- 0.9.3 — 2026-09-10
- 0.0.0-main-20260909172717 — 2026-09-09
- 0.0.0-main-20260909170241 — 2026-09-09
- 0.0.0-main-20260909165034 — 2026-09-09
- 0.0.0-main-20260909163515 — 2026-09-09
- … 197 more at https://npm.io/package/mppx/versions

## README

<picture>
  <source media="(prefers-color-scheme: dark)" srcset=".github/logo-dark.svg">
  <source media="(prefers-color-scheme: light)" srcset=".github/logo-light.svg">
  <img alt="mppx" src=".github/logo-light.svg" width="100%" height="100px">
</picture>

<p></p>

<p align="center"><b>TypeScript SDK for the <a href="https://mpp.dev">Machine Payments Protocol</a></b></p>

<p align="center">
  <a href="https://mpp.dev/sdk/typescript">Documentation</a> · <a href="#install">Install</a> · <a href="#quick-start">Quick Start</a> · <a href="#examples">Examples</a> · <a href="#cli">CLI</a> · <a href="#payments-proxy">Payments Proxy</a> · <a href="https://github.com/tempoxyz/mpp-specs">Protocol</a>
</p>

<p align="center">
  <a href="https://www.npmjs.com/package/mppx">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/mppx?colorA=21262d&colorB=21262d&style=flat">
      <img src="https://img.shields.io/npm/v/mppx?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="Version">
    </picture>
  </a>
  <a href="https://github.com/wevm/mppx/blob/main/LICENSE">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/l/mppx?colorA=21262d&colorB=21262d&style=flat">
      <img src="https://img.shields.io/npm/l/mppx?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="MIT License">
    </picture>
  </a>
</p>

---

## Documentation

Full documentation, API reference, and guides are available at **[mpp.dev/sdk/typescript](https://mpp.dev/sdk/typescript)**.

Contributors changing Tempo sessions should read the [session design](./src/tempo/session/README.md) before altering credential, recovery, accounting, or transport behavior.

## Install

```bash
npm i mppx
```

## Quick Start

### Server

```ts
import { Mppx, tempo } from 'mppx/server'

const mppx = Mppx.create({
  methods: [
    tempo({
      currency: '0x20c0000000000000000000000000000000000000',
      recipient: '0x742d35Cc6634c0532925a3b844bC9e7595F8fE00',
    }),
  ],
  secretKey: process.env.MPP_SECRET_KEY!,
})

export async function handler(request: Request) {
  const response = await mppx.charge({ amount: '1' })(request)

  if (response.status === 402) return response.challenge

  return response.withReceipt(Response.json({ data: '...' }))
}
```

Generate `MPP_SECRET_KEY` with at least 32 bytes, for example: `openssl rand -base64 32`.

### Client

```ts
import { privateKeyToAccount } from 'viem/accounts'
import { Mppx, tempo } from 'mppx/client'

Mppx.create({
  methods: [tempo({ account: privateKeyToAccount('0x...') })],
})

// Global fetch now handles 402 automatically
const res = await fetch('https://mpp.dev/api/ping/paid')
```

## Examples

| Example                                                | Description                                          |
| ------------------------------------------------------ | ---------------------------------------------------- |
| [charge](./examples/charge/)                           | Payment-gated photo generation API                   |
| [charge-wagmi](./examples/charge-wagmi/)               | Payment-gated charge with Wagmi + React              |
| [session/multi-fetch](./examples/session/multi-fetch/) | Multiple paid requests over a single payment channel |
| [session/sse](./examples/session/sse/)                 | Pay-per-token LLM streaming with SSE                 |
| [stripe](./examples/stripe/)                           | Stripe SPT charge with automatic client              |

```bash
npx gitpick wevm/mppx/examples/charge
```

## CLI

`mppx` includes a basic CLI for making HTTP requests with automatic payment handling. Tempo
session channels are retained and reused automatically until you close them.

```bash
# create account - stored in keychain, autofunded on testnet
mppx account create

# make request - automatic payment handling, curl-like api
mppx example.com

# pay an x402 offer on a server that advertises both protocols
mppx example.com --protocol x402

# open another session instead of reusing the preferred channel
mppx example.com --session new

# inspect and close retained sessions
mppx sessions list
mppx sessions view <channel-id>
mppx sessions close <channel-id>
mppx sessions close --all --yes

# explicitly trust a custom session escrow advertised by the server
mppx example.com -M allowCustomEscrow=true
```

`--session auto` is the default. Pass `new` to open another channel or a channel ID to select one
explicitly.

Tempo session clients accept only the canonical escrow contract by default. A server may advertise
its configured custom escrow in the payment challenge, but the client rejects it unless
`-M allowCustomEscrow=true` is supplied. This opt-in trusts the server-selected address; clients
that do not support custom escrows should leave it unset. See the
[session escrow trust documentation](./src/tempo/session/README.md#escrow-configuration-and-trust).

`--protocol auto` is the default: MPP is preferred when available, and x402 is used otherwise.
Pass `mpp` or `x402` to require one protocol. x402 payments use the same EVM account as EVM
charges, so `MPPX_PRIVATE_KEY` or a stored account works for both.

Payment extensions can enforce policy or prepare funds after challenge selection and confirmation,
immediately before credential creation:

```ts
import { defineConfig, Extension } from 'mppx/cli'

export default defineConfig({
  extensions: [
    Extension.from({
      async preparePayment({ challenge }) {
        await prepareFunds(challenge)
      },
    }),
  ],
})
```

Extensions run in configuration order. Throwing rejects the payment before Mppx signs it.

You can also install globally to use the `mppx` CLI from anywhere:

```bash
npm i -g mppx
```

## Payments Proxy

`mppx` exports a `Proxy` server handler so that you can create or define a 402-protected payments proxy for any API.

```ts
import { openai, stripe, Proxy } from 'mppx/proxy'
import { Mppx, tempo } from 'mppx/server'

const mppx = Mppx.create({
  methods: [tempo()],
  secretKey: process.env.MPP_SECRET_KEY!,
})

const proxy = Proxy.create({
  services: [
    openai({
      apiKey: 'sk-...',
      routes: {
        'POST /v1/chat/completions': mppx.charge({ amount: '0.05' }),
        'POST /v1/completions': mppx.tempo.session({
          amount: '0.0001',
          unitType: 'token',
        }),
        'GET /v1/models': true,
      },
    }),
    stripe({
      apiKey: 'sk-...',
      routes: {
        'POST /v1/charges': mppx.charge({ amount: '0.01' }),
        'GET /v1/customers/:id': true,
      },
    }),
  ],
})

createServer(proxy.listener) // Node.js
Bun.serve(proxy) // Bun
Deno.serve(proxy.fetch) // Deno
app.use(proxy.listener) // Express
app.all('*', (c) => proxy.fetch(c.req.raw)) // Hono
app.all('*', (c) => proxy.fetch(c.request)) // Elysia
export const GET = proxy.fetch // Next.js
export const POST = proxy.fetch // Next.js
```

This exposes the following routes:

| Route                              | Pricing                       |
| ---------------------------------- | ----------------------------- |
| `POST /openai/v1/chat/completions` | charge **$0.005**             |
| `POST /openai/v1/completions`      | session **$0.0001 per token** |
| `GET /openai/v1/models`            | free                          |
| `POST /stripe/v1/charges`          | charge **$0.01**              |
| `GET /stripe/v1/customers/:id`     | free                          |

## Protocol

Built on the ["Payment" HTTP Authentication Scheme](https://datatracker.ietf.org/doc/draft-ryan-httpauth-payment/). See [mpp-specs](https://github.com/tempoxyz/mpp-specs) for the full specification.

## License

MIT

---
_Source: https://npm.io/package/mppx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
