MPP

Pay-per-use AgentMail with Stripe’s Machine Payments Protocol

Getting started

MPP (Machine Payments Protocol) is Stripe’s open protocol that enables machine-to-machine payments. By integrating MPP with AgentMail, your agents can pay for API usage directly without managing API keys or subscriptions.

Base URLs

To authenticate with MPP instead of an API key, you must use the MPP-specific base URLs below. These replace the default AgentMail base URLs and route requests through the MPP payment layer.

ProtocolURL
HTTPmpp.api.agentmail.to
WebSocketmpp.ws.agentmail.to

Prerequisites

  • A crypto wallet with funds (EVM-compatible wallet)
  • Node.js installed

Install dependencies

$npm install agentmail mppx viem

Quickstart

1import { privateKeyToAccount } from "viem/accounts";
2import { Mppx, tempo } from "mppx/client";
3
4import { AgentMailClient } from "agentmail";
5
6
7// setup MPP client
8
9const PRIVATE_KEY = "0x...";
10
11const account = privateKeyToAccount(PRIVATE_KEY);
12
13export const mppx = Mppx.create({ methods: [tempo({ account })] });
14
15
16// setup AgentMail client
17
18export const client = new AgentMailClient({ mppx });
19
20
21// create inbox
22
23const inboxRes = await client.inboxes.create({
24 username: `mpp-${Date.now()}`,
25});
26console.log("Created inbox: ", inboxRes.inboxId);
27
28
29// subscribe to inbox
30
31const socket = await client.websockets.connect();
32console.log("Connected to websocket");
33
34socket.on("message", async (event) => {
35 if (event.type === "subscribed") {
36 console.log("Subscribed to", event.inboxIds);
37 } else if (event.type === "event" && event.eventType === "message.received") {
38 console.log("Received message from: ", event.message.from);
39 }
40});
41
42socket.sendSubscribe({
43 type: "subscribe",
44 inboxIds: [inboxRes.inboxId],
45});

How it works

When you pass an mppx client to AgentMailClient, the SDK automatically handles payment negotiation for each API request. The MPP client signs payments using your wallet, enabling your agent to pay per request seamlessly.

This means your agent can use the full AgentMail API (inboxes, messages, threads, attachments) without needing a traditional API key. Payment happens per-request via Stripe’s Machine Payments Protocol.

Resources