The API route handler function to wrap
Payment configuration for this specific route
Pre-configured t402ResourceServer instance
OptionalpaywallConfig: PaywallConfigOptional configuration for the built-in paywall UI
Optionalpaywall: PaywallProviderOptional custom paywall provider (overrides default)
Whether to sync with the facilitator on startup (defaults to true)
A wrapped Next.js route handler
import { NextRequest, NextResponse } from "next/server";
import { withT402 } from "@t402/next";
import { t402ResourceServer } from "@t402/core/server";
import { registerExactEvmScheme } from "@t402/evm/exact/server";
const server = new t402ResourceServer(myFacilitatorClient);
registerExactEvmScheme(server, {});
const handler = async (request: NextRequest) => {
return NextResponse.json({ data: "protected content" });
};
export const GET = withT402(
handler,
{
accepts: {
scheme: "exact",
payTo: "0x123...",
price: "$0.01",
network: "eip155:84532",
},
description: "Access to protected API",
},
server,
);
Wraps a Next.js App Router API route handler with t402 payment protection.
Unlike
paymentProxywhich works as middleware,withT402wraps individual route handlers and guarantees that payment settlement only occurs after the handler returns a successful response (status < 400). This provides more precise control over when payments are settled.