Skip to main content

Install

npm install @foldset/nextjs

Setup

1

Get your API key

Copy your API key from the Foldset dashboard.
2

Add the environment variable

Add your API key to .env.local:
FOLDSET_API_KEY=your_api_key
3

Create the proxy file

Create proxy.ts in the root of your project (Next.js 15+):
proxy.ts
import { createFoldsetProxy } from "@foldset/nextjs";

const foldsetProxy = createFoldsetProxy({
  apiKey: process.env.FOLDSET_API_KEY!,
});

export default foldsetProxy;
In Next.js 14 and earlier, name this file middleware.ts instead of proxy.ts.
4

Configure routes

Head to the routes page to choose which paths to protect and set prices.

How it works

The Foldset proxy runs on every incoming request to your Next.js app:
  1. Checks the request path against your configured restrictions
  2. If no payment is required, the request passes through normally
  3. If payment is required and no valid x402 payment header is present, returns a 402 Payment Required response with payment instructions
  4. If a valid payment is attached, the request passes through and settlement completes after your route handler responds

MCP server protection

If your Next.js app hosts an MCP server (Streamable HTTP), Foldset can gate individual tool calls and resource reads. Configure MCP restrictions in the dashboard by specifying the endpoint path, method, and tool or resource name. Discovery methods like tools/list pass through for free with payment metadata attached.

Update your robots.txt

Once Foldset is active, you want AI agents visiting your site so they can pay for access. If your robots.txt blocks AI crawlers, remove those rules. Foldset handles gating at the payment layer.
# Remove rules like these:
User-agent: GPTBot
Disallow: /

User-agent: ClaudeBot
Disallow: /