Merchant SDK

requirePayment, the hosted proxy, and metered pricing · the merchant side, in code.

Two ways to get paid by agents: drop one middleware line into your server, or let AgentPay host a paywall proxy in front of your backend.

requirePayment (self-hosted)

import { Hono } from "hono";
import { requirePayment } from "@agentpay/merchant";

const app = new Hono();

// Returns 402 to unpaid agents, verifies the receipt, then continues.
app.use("/api/*", requirePayment({ price: "$0.05" }));

app.get("/api/echo", (c) => c.json({ ok: true }));

The middleware verifies the gateway’s Ed25519 signature locally (no round trip) and tracks consumed receipt ids so a receipt can’t be replayed.

Hosted proxy (no code)

Register a service in the merchant portal and point it at your backend. Agents call https://<gateway>/m/<org>/<service>; AgentPay returns the 402, takes the payment, and forwards the request to your backend. You read the request like normal.

Metered pricing

Charge per token, per second, or per unit. Authorize a maximum hold, do the work, then settle the exact usage.

app.use("/v1/chat", requirePayment({
  meter: { unit: "1K tokens", price: "$0.002" },
  maxAuthorize: "$5.00",
}));

// After the work, report usage; AgentPay settles the exact amount.
c.header("X-AgentPay-Units", String(tokensUsed));

Payouts

Earned balances settle to Stripe Connect (bank) or USDC on Base, netted on a schedule. Set your destination and watch sales by service and by agent in the merchant portal.