Integrations

Build HTTP 402 machine-to-machine payments with the MPP protocol across TypeScript, Python, and Rust SDKs.

What it does

MPP is an open protocol co-authored by Tempo and Stripe that standardizes HTTP 402 for machine-to-machine payments using three header-based primitives: a Challenge in `WWW-Authenticate: Payment`, a Credential in `Authorization: Payment`, and a Receipt in `Payment-Receipt`. The mppx TypeScript SDK ships middleware for Hono, Express, Next.js, and Elysia; pympp covers Python with FastAPI; mpp covers Rust. It supports Tempo stablecoins, Stripe cards, Lightning Bitcoin, EVM, Solana, Stellar, and other rails, with charge, session, and subscription intents for one-time, metered, and recurring billing.

When to use it

  • Charge per request on a paid HTTP API or endpoint
  • Bill LLM or SSE streaming output through a pay-as-you-go session channel
  • Gate upstream OpenAI, Anthropic, or Stripe services behind MPP via the payments proxy
  • Add payment to MCP tool calls or agent pipelines

The skill document

MPP - Machine Payments Protocol

MPP is an open protocol (co-authored by Tempo and Stripe) that standardizes HTTP 402 Payment Required for machine-to-machine payments. Clients pay in the same HTTP request - no accounts, API keys, or checkout flows needed.

The core protocol spec is submitted to the IETF as the Payment HTTP Authentication Scheme.

Code in this skill uses placeholder token names (, ); the real addresses live in the Tempo documentation and references/tempo-method.md.

Core Architecture

Three primitives power every MPP payment:

  1. Challenge - server-issued payment requirement (in WWW-Authenticate: Payment header)
  2. Credential - client-submitted payment proof (in Authorization: Payment header)
  3. Receipt - server confirmation of successful payment (in Payment-Receipt header)

Payment Methods & Intents

MPP is payment-method agnostic. Each method defines its own settlement rail:

MethodRailSDK PackageStatus
TempoTIP-20 stablecoins on Tempo chainmppx (built-in)Production
StripeCards/wallets (SPT) + on-chain crypto depositmppx (built-in)Production
EVMEIP-3009 stablecoin authorizations (x402-exact compatible)mppx (built-in)Production
LightningBitcoin over Lightning Network@buildonspark/lightning-mpp-sdkProduction
StellarSEP-41 tokens on Stellar, charge + channel@stellar/mppProduction (channel wire spec still being drafted - subject to change)
SolanaSolana-native charge + session (SOL, SPL, Token-2022)@solana/mppProduction
MonadMonad charge (ERC-3009, settlement modes)@monad-crypto/mppProduction
NEAR IntentsCross-chain charge via 1Click deposit addresses@defuse-protocol/nearintents-mpp-sdkProduction (not trustless - routes through a settlement backend, advertised as methodDetails.settlementBackend: "near-intents" for per-method risk policy)
RedotPayRedotPay balance (rdt) or stablecoin proof, charge only@redotpay/mppProduction
CardEncrypted network tokens (Visa)mpp-cardProduction
CustomAny railMethod.from() + Method.toClient/toServerExtensible

Per-method deep dives: references/tempo-method.md, references/stripe-method.md, references/lightning-method.md, references/custom-methods.md.

IntentPatternBest For
chargeOne-time payment per requestAPI calls, content access, fixed-price endpoints
sessionPay-as-you-go over payment channelsLLM streaming, metered billing, high-frequency APIs
subscriptionRecurring access via an authorized key (Tempo) - see references/subscriptions.mdPlans/tiers where access is separated from per-request billing

Quick Start: Server (TypeScript)

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

const mppx = Mppx.create({
  methods: [tempo({
    currency: '', // pathUSD testnet
    recipient: '0xYourAddress',
  })],
})

export async function handler(request: Request) {
  const result = await mppx.charge({ amount: '0.01' })(request)
  if (result.status === 402) return result.challenge
  return result.withReceipt(Response.json({ data: '...' }))
}

Install: npm install mppx viem (mppx 0.8.15 requires viem >= 2.54.0).

Validate the finished server end-to-end with npx mppx validate http://localhost:3000.

Quick Start: Client (TypeScript)

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

// Polyfills globalThis.fetch to handle 402 automatically
Mppx.create({
  methods: [tempo({ account: privateKeyToAccount('0x...') })],
})

const res = await fetch('https://api.example.com/paid')
// Payment happens transparently when server returns 402

In browsers, mppx 0.6.0 changed the default: polyfilled fetch only sends Accept-Payment to same-origin endpoints, so cross-origin paid APIs need acceptPaymentPolicy ('always' / { origins: [...] }). Client fetch retries incremental challenges up to maxPaymentRetries (default 3). For non-global alternatives (Fetch.from/polyfill/restore, Mppx.restore()), see references/typescript-sdk.md.

Quick Start: Server (Python)

from fastapi import FastAPI
from mpp import Credential, Receipt
from mpp.server import Mpp
from mpp.methods.tempo import tempo, ChargeIntent

app = FastAPI()
server = Mpp.create(method=tempo(
    currency="",
    recipient="0xYourAddress", intents={"charge": ChargeIntent()},
))

@app.get("/resource")
@server.pay(amount="0.50")
async def get_resource(request, credential: Credential, receipt: Receipt):
    return {"data": "paid content", "payer": credential.source}

Install: pip install "pympp[tempo]". See references/python-sdk.md for full patterns.

Quick Start: Server (Rust)

Install: cargo add mpp --features tempo,server. See references/rust-sdk.md for full patterns.

Framework Middleware (TypeScript)

Each framework has its own import (mppx/nextjs, mppx/hono, mppx/express, mppx/elysia):

// Next.js
import { Mppx, tempo } from 'mppx/nextjs'
const mppx = Mppx.create({ methods: [tempo({ currency: '', recipient: '0x...' })] })
export const GET = mppx.charge({ amount: '0.1' })(() => Response.json({ data: '...' }))

// Hono
import { Mppx, tempo } from 'mppx/hono'
app.get('/resource', mppx.charge({ amount: '0.1' }), (c) => c.json({ data: '...' }))

See references/typescript-sdk.md for Express and Elysia examples.

Sessions: Pay-as-You-Go Streaming

Sessions open a payment channel once, then use off-chain vouchers for each request - no blockchain transaction per request. Sub-100ms latency, near-zero per-request fees.

Sessions v2 (default since mppx 0.7.0): tempo.session() is the TIP-1034 precompile channel flow; the earlier escrow-contract implementation is Sessions v1, still available as the deprecated tempo.sessionLegacy. A v2-expecting client rejects a v1 session and falls back to the charge path, so keep client and server on matching flows. Two client APIs: tempo.session({ account, maxDeposit }) registers the method with Mppx.create() (transparent 402 handling via fetch), while tempo.session.manager({ account, maxDeposit }) returns a managed client for direct lifecycle control (.sse(), .close()).

// Server - session endpoint with automatic settlement
const mppx = Mppx.create({
  methods: [tempo.session({
    currency: '', recipient: '0x...',
    store: Store.redis(redis),
    settlementSchedule: { amount: '1.00', intervalMs: 300_000 },
    bootstrap: true, // let returning clients recover their channel on this route
  })],
})
const result = await mppx.session({ amount: '0.001', unitType: 'token' })(request)
if (result.status === 402) return result.challenge
return result.withReceipt(Response.json({ data: '...' }))
// Server - SSE streaming with per-word billing
export const GET = mppx.session({ amount: '0.001', unitType: 'word' })(
  async () => async function* (stream) {
    for (const word of ['hello', 'world']) {
      await stream.charge()
      yield word
    }
  }
)

// Client - session with auto-managed channel
Mppx.create({ methods: [tempo({ account, maxDeposit: '1' })] })
const res = await fetch('http://localhost:3000/api/resource')
// 1st request: opens channel on-chain; 2nd+: off-chain vouchers

Sessions also stream over WebSocket via Ws.serve(). See references/sessions.md for the full lifecycle, settlement, stores, SSE and WebSocket patterns, and channel recovery.

Multi-Method Support

Accept Tempo stablecoins, Stripe cards, and Lightning Bitcoin on a single endpoint:

const mppx = Mppx.create({
  methods: [
    tempo({ currency: '', recipient: '0x...' }),
    stripe.charge({ client: new Stripe(key), networkId: 'profile_...', paymentMethodTypes: ['card'] }),
    spark.charge({ mnemonic: process.env.MNEMONIC! }),
  ],
})

Use Mppx.compose() to present multiple methods in a single 402 response with per-route pricing. Apply the same branch at the challenge site and the verification site, or the 402 advertises fewer options than the server accepts. See references/typescript-sdk.md.

Setting html: true on a payment method config renders a browser-friendly payment page when a 402 endpoint is visited in a browser, with theming, multi-method compose tabs, and Solana wallet support. Service workers handle credential submission, then the page reloads with the paid response.

Customize via mppx/html exports (Config, Text, Theme), and build a custom method's payment link with Html.init(methodName).

Zero-Dollar Auth (Proof Credentials)

Authenticate agent identity without payment. Clients sign an EIP-712 proof over the challenge ID instead of creating a transaction - no gas burned, no funds transferred.

// Server - zero-dollar charge, with a store for replay protection
const mppx = Mppx.create({
  methods: [tempo.charge({ currency: '', recipient: '0x...', store })],
})
const result = await mppx.charge({ amount: '0' })(request)

Since mppx 0.8.0 these proofs are bound to the payer wallet: the EIP-712 Proof typed data (exposed as tempo.Proof) carries an account field at domain version 3, so a proof signed for one account no longer verifies against another.

Use cases: identity verification, long-running job polling, paid unlock with free subsequent access, multi-step agent pipelines. See mpp.dev/advanced/identity.

Payments Proxy

Gate existing APIs behind MPP payments:

// import { openai, Proxy } from 'mppx/proxy' - a service inside Proxy.create({ services: [...] })
openai({
  apiKey: process.env.OPENAI_API_KEY,
  routes: {
    'POST /v1/chat/completions': mppx.charge({ amount: '0.05' }),
    'GET /v1/models': true, // literal `true` marks a free route
  },
})

Built-in presets openai(), anthropic(), stripe(), plus custom() for any upstream. See references/discovery-and-proxy.md for Proxy.create(), the discovery endpoints it serves, and the discovery() helper for non-proxy servers.

MCP Transport

MCP tool calls can require payment using JSON-RPC error code -32042 (servers may also issue -32043):

// Server - import tempo from mppx/server, NOT mppx/tempo
import { McpServer } from 'mppx/mcp/server'
import { tempo } from 'mppx/server'
const server = McpServer.wrap(baseServer, { methods: [tempo.charge({ /* ... */ })], secretKey })

// Client - payment-aware MCP client (import tempo from mppx/client)
import { McpClient } from 'mppx/mcp/client'
import { tempo } from 'mppx/client'
const mcp = McpClient.wrap(client, { methods: [tempo({ account })] })
const result = await mcp.callTool({ name: 'premium_tool', arguments: {} })

MCP-over-HTTP challenges settle in the same payment-aware fetch, and transports are pluggable via Transport.from/http/mcp/mcpSdk on both sides. See references/transports.md.

Privy Server Wallets

createViemAccount from @privy-io/node/viem (needs @privy-io/node >= 0.20.0) returns a viem Account backed by a Privy server wallet, so it drops into tempo({ account }) wherever a local account would go.

Server-side signing works with app-owned server wallets; user-owned embedded wallets require authorization keys or key quorums. See references/typescript-sdk.md for the full setup and the manual toAccount() construction.

Testing & CLI

# Create an account (stored in keychain), then fund it on testnet
npx mppx account create
npx mppx account fund --network testnet

# Make a paid request
npx mppx http://localhost:3000/resource

# Parse a challenge without signing it
npx mppx sign --dry-run --challenge ''

# Validate a server implementation end-to-end
npx mppx validate http://localhost:3000

The CLI also covers init, sessions (list/view/close), discover, services, mcp add, and skills add. Config comes from MPPX_CONFIG or an explicit --config - there is no auto-discovery from the working directory. Full reference: references/cli.md.

SDK Packages

LanguagePackageInstall
TypeScriptmppxnpm install mppx
Pythonpympppip install "pympp[tempo]"
Rustmppcargo add mpp --features tempo,client,server
Rubympp-rb (official, by Stripe)see repo for gem name
Gompp-go (official, by Tempo)go get github.com/tempoxyz/mpp-go
Elixirmpp (community)hex.pm/packages/mpp
Swiftmpp-swift (community)see repo

Capability notes, checked against SDK source rather than the docs matrices (upstream publishes two that disagree):

  • Session intent: TypeScript and Rust only.
  • Proof Credentials (zero-dollar auth): TypeScript, Rust, and Ruby. Not pympp - the Python Tempo method implements only hash and transaction payload types.
  • Stripe, MCP, and event handling: TypeScript, Python, Rust, Ruby. Not the official mpp-go, which ships client/server/charge/fee-sponsorship/proof with net/http, Gin, Echo, and Chi middleware. A separate community Go mppx (cp0x) also exists.

Go and Ruby have first-class SDK doc pages at mpp.dev/sdk/go and mpp.dev/sdk/ruby.

Always import Mppx and tempo from the subpath matching your context (mppx/server, mppx/client, or the framework subpath). Note: Mppx and tempo are NOT exported from mppx/tempo - that subpath only exports Session and Ws. The authoritative subpath table is in references/typescript-sdk.md.

Key Concepts

  • Challenge/Credential/Receipt: The three protocol primitives. Challenge IDs are HMAC-SHA256 bound to prevent tampering. See references/protocol-spec.md
  • Split payments: One charge across multiple recipients in a single transaction (1-10 splits, per-split memos, expectedRecipients). See references/tempo-method.md
  • Fee sponsorship: Server pays gas on behalf of clients, capped by maxInFlightReservations / maxInFlightTotalFee
  • Relays: Delegate credential validation and broadcast to Tempo API or a compatible relay via tempo.charge({ relay })
  • Push/pull modes: Client broadcasts the transaction (push) or the server does (pull)
  • Client chain pinning: tempo.charge({ expectedChainId }) rejects challenges for the wrong Tempo network
  • Reusable client channels: pass a channelStore to persist and reuse payer session channels across processes
  • x402 interop: evm.charge({ x402: { facilitator } }) serves native MPP and x402 "exact" challenges from one route; the client prefers Payment-auth challenges
  • Custom methods: Implement any payment rail with Method.from(). See references/custom-methods.md

Payment Hooks

Attach logging, metrics, or tracing without touching the handler. Register on the object returned by Mppx.create(); each registration returns an unsubscribe function.

  • Server (mppx/server): onChallengeCreated, onPaymentSuccess, onPaymentFailed, onSessionSettlement, on('*')
  • Client (mppx/client): onChallengeReceived, onCredentialCreated, onPaymentResponse, onPaymentFailed

Server handlers are awaited inline on the request path - keep them fast. onPaymentFailed is the practical way to see the real error behind an opaque 402. See references/typescript-sdk.md and mpp.dev/advanced/payment-hooks.

Managing Agent Spend

Bound an agent's payment authority with Tempo access keys - delegated signing keys with built-in spend controls, their own expiry, and a revocation path.

import { Expiry } from 'accounts'
import { numberToHex, parseUnits } from 'viem'
import { Scopes } from 'viem/tempo'

const accessKey = {
  expiry: Expiry.days(7),
  limits: [{ token: usdc, limit: numberToHex(parseUnits('10', 6)), period: 86_400 }], // 10 USDC/day
  scopes: [Scopes.tip20(usdc).transfer({ recipients: [recipientAddress] })],
}
// Authorize: provider.request({ method: 'wallet_connect', params: [{ capabilities: { authorizeAccessKey: accessKey } }] })

Mppx.create({
  methods: [tempo({
    account: provider.getAccount(),
    ...provider.getMppxParameters({ accessKey: accessKeyAddress }),
  })],
})

Spend limits are hex-encoded - pass numberToHex(parseUnits(...)), not a raw bigint. Separate keys per app/tool/deployment keep delegated runtimes isolated. See mpp.dev/guides/managing-agent-spend and Tempo access keys.

Production Gotchas

The failure modes that cost the most time. Full detail in references/production-gotchas.md:

  • Tempo has no native gas token. Set feeToken or call setUserToken, or transactions fail with gas_limit: 0. "Fund with ETH" errors mean "fund with the stablecoin fee token"
  • Sessions do not settle themselves. Configure settlementSchedule or run your own tempo.settle() / tempo.settleBatch() sweep, paired with a close policy for idle channels - otherwise revenue accrues as unredeemed vouchers and channels stay open holding payer deposits
  • Charge settles before your handler runs. Use validateCredential then broadcastCredential when payment should depend on the work succeeding. Challenges expire after 5 minutes by default
  • Never use Store.memory() in production. Lost channel state means deposits stay reserved indefinitely
  • Set realm explicitly. Env vars outrank the per-request hostname, and Kubernetes HOSTNAME rotates every deploy, breaking mppscan attribution
  • Session voucher, close, and topUp credentials are bodyless POSTs, so a body validator running before mppx.session() rejects them with a spurious 400. Clone the request before reading its body, or mppx sees an empty one and returns 402
  • Large 402 headers overflow nginx's 4k default buffer and surface as 502

References

FileContent
references/protocol-spec.mdChallenge/Credential/Receipt, status codes, security
references/typescript-sdk.mdmppx: server, client, middleware, transports, stores
references/cli.mdmppx CLI: requests, validate, sign, accounts, config
references/production-gotchas.mdField-tested failure modes and their fixes
references/sessions.mdChannels, vouchers, settlement, SSE/WS, recovery
references/subscriptions.mdSubscription intent: activation, renewal, cancellation
references/tempo-method.mdTempo: fees, relays, push/pull, splits, sessions
references/stripe-method.mdStripe: SPT fiat flow, crypto deposit, Elements
references/discovery-and-proxy.mdProxy services, discovery documents, registries
references/transports.mdHTTP, MCP, and WebSocket transport bindings
references/python-sdk.mdpympp: @server.pay, async client, charge intent
references/rust-sdk.mdmpp Rust: server/client, features, sessions
references/lightning-method.mdLightning: BOLT11 charge, bearer sessions, Spark
references/custom-methods.mdMethod.from, toClient, toServer patterns

Official Resources

Questions people ask

What does the protocol do on the wire?
Servers issue payment requirements in a `WWW-Authenticate: Payment` header, clients submit payment proof in `Authorization: Payment`, and servers return a `Payment-Receipt` confirming settlement, all within the same HTTP request with no accounts or API keys required.
Which payment rails and SDKs are supported?
Tempo stablecoins, Stripe cards and crypto deposit, and Lightning Bitcoin ship built into mppx; EVM, Stellar, Solana, Monad, NEAR Intents, RedotPay, and Card (Visa network tokens) are available as separate packages. SDKs include `mppx` (TypeScript with Hono/Express/Next.js/Elysia middleware), `pympp` (Python with FastAPI), and `mpp` (Rust).
What is the difference between charge, session, and subscription?
Charge is a one-time payment per request for fixed-price endpoints. Session opens an off-chain payment channel with sub-100ms latency for metered, high-frequency flows like LLM streaming. Subscription grants recurring access through a Tempo-authorized key, separating access from per-request billing.

Related skills

Machine Payment Endpoint Preflight: Inspect one public HTTPS endpoint without credentials or payment. Validate the URL, make one bounded GET request, and report whether its HTTP 402 x402 or MPP payment offers are parseable and internally consistent. Return protocols, prices, currencies, networks, recipients, expiries, conflicts, and a safe next action. Never sign, pay, or broadcast a transaction. Use when an agent needs to run this published AgentPMT workflow with 2 linked tool skills, workflow.

1 installs

Build paid APIs, paywalls, and AI agent payments using the HTTP 402 protocol with on-chain settlement.

28 installs1 stars

Safely inspect Stripe payments, customers, invoices, and subscriptions

21 installs

Generate and consume native HTTP 402 ("Payment Required") API paywalls on SynapticChain for machine-to-machine micropayments.