@buckspay/nextjs exports two App Router route factories. They act as the BFF (Backend for
Frontend) boundary described in Facilitator and BFF: the
browser POSTs to your same-origin routes; the routes forward to the facilitator with the secret
credentials server-side.
Create
app/api/buckspay/relay/route.ts. createRelayRoute returns a (req: Request) => Promise<Response>
handler - assign it to POST as required by App Router conventions.// app/api/buckspay/relay/route.ts - SERVER-ONLY
import { createRelayRoute } from "@buckspay/nextjs";
export const POST = createRelayRoute({
facilitatorUrl: process.env.BUCKSPAY_FACILITATOR_URL!,
apiKey: process.env.BUCKSPAY_FACILITATOR_API_KEY!, // SERVER-SIDE ONLY
network: "testnet"
});
facilitatorUrlstringapiKeystringnetworkNetwork"testnet" or "mainnet"The route validates the incoming
RelayPayload with a strict Zod schema before forwarding, so
malformed requests are rejected at the BFF layer. On error it returns a coded JSON response
({ error: BuckspayErrorCode }) without leaking the upstream message.If you use social or email-based signers, create proxy routes that forward the auth body to the
facilitator’s
/auth/* endpoints while injecting the API key server-side.// app/api/buckspay/auth/social/route.ts - SERVER-ONLY
import { createSignerProxyRoute } from "@buckspay/nextjs";
export const POST = createSignerProxyRoute({ provider: "web3auth", network: "testnet" });
// app/api/buckspay/auth/email/route.ts - SERVER-ONLY
import { createSignerProxyRoute } from "@buckspay/nextjs";
export const POST = createSignerProxyRoute({ provider: "email", network: "testnet" });
createSignerProxyRoute reads BUCKSPAY_FACILITATOR_URL and BUCKSPAY_FACILITATOR_API_KEY
from the server environment by default. You can override both via the optional second argument
(CreateSignerProxyRouteDeps).In your browser (or React) code, configure the relayer without an API key - it points at your
same-origin BFF routes:
Full example
The snippet below shows all three route handlers in a single file for reference. In production, each goes in its ownroute.ts under app/.
Next
Facilitator and BFF
Why the API key must stay server-side and how the BFF slot fits the payment flow.
Web - @buckspay/react
The browser-side hooks that POST to your BFF relay route.

