MAILGENT

Mailgent

The payment + identity layer for AI agents — sellers charge per call in USDC, identities get the wallet, mail, vault, and calendar to transact.

The payment + identity layer for AI agents. Two clean paths depending on which side you're building:

  • Sellers charge per call on any HTTP endpoint or MCP tool — five lines of middleware, USDC settles on Base, signed receipt back.
  • Identities (the agent side) get a wallet, inbox, vault with TOTP, calendar, and DID in one project.

New here? Start with Introduction for the vocabulary, then pick your path below.


For Sellers

You're shipping a paid API or MCP tool. The middleware handles the x402 dance: serve a 402 challenge, verify the buyer's signed USDC authorization, settle on-chain, return an Ed25519 receipt.

1. Create a project at console.mailgent.dev → pick Sell to agents. Flip Pay → Accept on. Copy the API key (loid-...).

2. Install and wrap a handler:

npm install @mailgent/sdk express
server.ts
import express from "express";
import { Mailgent } from "@mailgent/sdk";
import { requirePayment } from "@mailgent/sdk/paywall/express";

const app = express();
app.set("trust proxy", true);

const mailgent = new Mailgent({ apiKey: process.env.MAILGENT_API_KEY! });

app.get(
  "/search",
  requirePayment({ amount: "0.05" }),
  (req, res) => res.json({ results: [/* ... */] }),
);

app.listen(3030);

Run with MAILGENT_API_KEY=loid-.... That's the whole integration.

Same shape on Hono, FastAPI, and MCP — only the middleware import changes. For frameworks without shipped middleware (Fastify, NestJS, Next.js, raw Node), call mailgent.payments.challenge and mailgent.payments.redeem from your handler directly.


For Identities

You're building an agent. It needs a wallet to pay for paid tools — plus an inbox, vault, TOTP, and calendar so it can actually operate. One Mailgent Identity project gives you all of it.

Here's an agent paying a seller's endpoint in one call:

import { Mailgent } from "@mailgent/sdk";

const mailgent = new Mailgent({ apiKey: process.env.MAILGENT_API_KEY! });

const paid = await mailgent.payments.pay({
  url: "https://seller.example.com/search",
});
if (!paid.ok) throw new Error(`pay failed: ${paid.code} — ${paid.message}`);

console.log(paid.content);  // what the seller returned
console.log(paid.txHash);   // on-chain proof on Base

payments.pay() discovers the seller's HTTP 402 challenge, checks your mandate caps, signs an EIP-3009 USDC transfer on your project's Kernel smart account on Base, retries with X-Payment, and returns the seller's content plus the on-chain txHash. Full history at mailgent.payments.activity() — no need to store anything yourself. Working end-to-end example at mailgent-dev/mailgent-pay-examples.


More

On this page