IntegrationUpdated 2026-11-20

Agent payments for Express

The paygate middleware turns an Express route into a paid route. A request without a payment gets HTTP 402 with the price. An agent pays and repeats the request. Then your handler runs as normal.

There is no subscription system, no API-key flow and no invoice. Each request pays for itself.

Install and gate a route

Create a merchant account at paygate.arispay.app. It gives you a merchant id. Pass it to the SDK once.

server.ts
import express from "express";
import { paygate } from "paygate/express";

const app = express();
const pw = paygate({ merchantId: process.env.PAYGATE_MERCHANT_ID });

// 2 cents per request.
app.get("/api/search", pw({ priceCents: 2 }), (req, res) => {
  res.json({ results: ["…"] });
});

// A price that depends on the request, in euro.
app.post(
  "/api/analyse",
  pw({ priceCents: (req) => (req.body.deep ? 50 : 10), currency: "EUR" }),
  (req, res) => res.json({ ok: true }),
);

app.listen(3000);

What the middleware does on each request

A request without a payment gets HTTP 402 with the price. The agent asks Arispay to authorize the payment and repeats the request. Arispay settles the payment before your handler runs. The response carries an X-Paygate-Receipt header.

On the buyer side, an AI agent pays your endpoint with `npx payagent pay <url>` or the payagent SDK. The agent pays from an Arispay wallet that a person topped up by card.

Scaffold a new seller

`paygate init` writes a small Express project with one paid route.

One command
npx paygate init --framework express --merchant-id <your-merchant-id> \
  --route /api/search --price 2 --yes

Pricing guidance

  • Prices are integer cents. The minimum is 1 cent per request. Set the price from your cost per call plus a margin.
  • Stateless endpoints work best: one request, one result, one payment.
  • You can change `priceCents` at any deploy. An agent reads the price from the 402 on every request.

FAQ

Which currencies can I price in?
EUR, GBP and USD. The default is USD. Set `currency` on the route.
Does the middleware need a body parser before it?
Put the body parser before paygate when the price reads `req.body`.

Is your service agent-ready?

Run the free readiness scan — it inspects your live endpoint's discoverability, machine-readable contracts, and payment support, then tells you the highest-impact fix.

Express Middleware — Charge AI Agents Per Request | Arispay