# Express
Source: https://docs.foldset.com/frameworks/express
Add Foldset payment gating to your Express application
## Install
```bash npm theme={null}
npm install @foldset/express
```
```bash yarn theme={null}
yarn add @foldset/express
```
```bash pnpm theme={null}
pnpm add @foldset/express
```
## Setup
Copy your API key from the [Foldset dashboard](https://foldset.com/dashboard/api-keys).
The SDK reads your API key from the `FOLDSET_API_KEY` environment variable.
**Local development:** add it to a `.env` file and load it with [dotenv](https://www.npmjs.com/package/dotenv) (or your preferred env loader). Make sure `.env` is in your `.gitignore`:
```
FOLDSET_API_KEY=sk_live_...
```
**Production:** set it in your hosting provider's environment variable settings (e.g. Railway, Render, AWS). Never commit API keys to your repository.
```typescript theme={null}
import express from "express";
import { foldset } from "@foldset/express";
const app = express();
// Add Foldset middleware before your routes
app.use(foldset({
apiKey: process.env.FOLDSET_API_KEY!,
}));
// Your routes
app.get("/api/data", (req, res) => {
res.json({ message: "This content is protected" });
});
app.listen(3000);
```
The middleware must be added **before** your route handlers. It will intercept requests that match your configured rules.
Head to the [rules page](https://foldset.com/dashboard/rules) to choose which paths to protect and set prices.
## How it works
The Foldset middleware runs on every incoming request:
1. Checks the request path against your configured rules
2. If no payment is required, calls `next()` and your route handler runs 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, calls `next()` and settles the payment after your route handler responds
### MCP server protection
If your Express app hosts an MCP server (Streamable HTTP), Foldset can gate individual tool calls and resource reads. Configure MCP rules 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: /
```
# FastAPI
Source: https://docs.foldset.com/frameworks/fastapi
Add Foldset payment gating to your FastAPI application
## Install
```bash pip theme={null}
pip install foldset-fastapi
```
```bash uv theme={null}
uv add foldset-fastapi
```
```bash poetry theme={null}
poetry add foldset-fastapi
```
## Setup
Copy your API key from the [Foldset dashboard](https://foldset.com/dashboard/api-keys).
The SDK reads your API key from the `FOLDSET_API_KEY` environment variable.
**Local development:** add it to a `.env` file and load it with [python-dotenv](https://pypi.org/project/python-dotenv/) or your preferred env loader. Make sure `.env` is in your `.gitignore`:
```
FOLDSET_API_KEY=sk_live_...
```
**Production:** set it in your hosting provider's environment variable settings (e.g. Railway, Render, AWS). Never commit API keys to your repository.
```python theme={null}
import os
from fastapi import FastAPI
from foldset_fastapi import FoldsetMiddleware, FoldsetOptions
app = FastAPI()
# Add Foldset middleware
app.add_middleware(
FoldsetMiddleware,
options=FoldsetOptions(api_key=os.environ.get("FOLDSET_API_KEY", "")),
)
# Your routes
@app.get("/api/data")
async def get_data():
return {"message": "This content is protected"}
```
The middleware must be added **before** your route handlers are registered. It will intercept requests that match your configured rules.
Head to the [rules page](https://foldset.com/dashboard/rules) to choose which paths to protect and set prices.
## How it works
The Foldset middleware runs on every incoming request:
1. Checks the request path against your configured rules
2. If no payment is required, the request passes through to your route handler
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 FastAPI app hosts an MCP server (Streamable HTTP), Foldset can gate individual tool calls and resource reads. Configure MCP rules 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: /
```
# Flask
Source: https://docs.foldset.com/frameworks/flask
Add Foldset payment gating to your Flask application
## Install
```bash pip theme={null}
pip install foldset-flask
```
```bash uv theme={null}
uv add foldset-flask
```
```bash poetry theme={null}
poetry add foldset-flask
```
## Setup
Copy your API key from the [Foldset dashboard](https://foldset.com/dashboard/api-keys).
The SDK reads your API key from the `FOLDSET_API_KEY` environment variable.
**Local development:** add it to a `.env` file and load it with [python-dotenv](https://pypi.org/project/python-dotenv/) or your preferred env loader. Make sure `.env` is in your `.gitignore`:
```
FOLDSET_API_KEY=sk_live_...
```
**Production:** set it in your hosting provider's environment variable settings (e.g. Railway, Render, AWS). Never commit API keys to your repository.
```python theme={null}
import os
from flask import Flask
from foldset_flask import foldset, FoldsetOptions
app = Flask(__name__)
# Add Foldset middleware
foldset(FoldsetOptions(api_key=os.environ.get("FOLDSET_API_KEY", ""))).init_app(app)
# Your routes
@app.route("/api/data")
def get_data():
return {"message": "This content is protected"}
```
The middleware must be initialized **before** your first request is served. It will intercept requests that match your configured rules.
Head to the [rules page](https://foldset.com/dashboard/rules) to choose which paths to protect and set prices.
## How it works
The Foldset middleware runs on every incoming request:
1. Checks the request path against your configured rules
2. If no payment is required, your route handler runs 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, your route handler runs and settlement completes after the response is sent
### MCP server protection
If your Flask app hosts an MCP server (Streamable HTTP), Foldset can gate individual tool calls and resource reads. Configure MCP rules 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: /
```
# Hono
Source: https://docs.foldset.com/frameworks/hono
Add Foldset payment gating to your Hono application
## Install
```bash npm theme={null}
npm install @foldset/hono
```
```bash yarn theme={null}
yarn add @foldset/hono
```
```bash pnpm theme={null}
pnpm add @foldset/hono
```
## Setup
Copy your API key from the [Foldset dashboard](https://foldset.com/dashboard/api-keys).
The SDK reads your API key from the `FOLDSET_API_KEY` environment variable.
**Local development:** add it to a `.env` file and load it with your runtime's env support (Bun and Node 22+ load `.env` automatically, or use [dotenv](https://www.npmjs.com/package/dotenv)). Make sure `.env` is in your `.gitignore`:
```
FOLDSET_API_KEY=sk_live_...
```
**Production:** set it in your hosting provider's environment variable settings (e.g. Cloudflare Workers secrets, Vercel, AWS). Never commit API keys to your repository.
```typescript theme={null}
import { Hono } from "hono";
import { foldset } from "@foldset/hono";
const app = new Hono();
// Add Foldset middleware before your routes
app.use(foldset({
apiKey: process.env.FOLDSET_API_KEY!,
}));
// Your routes
app.get("/api/data", (c) => {
return c.json({ message: "This content is protected" });
});
export default app;
```
The middleware must be added **before** your route handlers. It will intercept requests that match your configured rules.
Head to the [rules page](https://foldset.com/dashboard/rules) to choose which paths to protect and set prices.
## How it works
The Foldset middleware runs on every incoming request:
1. Checks the request path against your configured rules
2. If no payment is required, calls `next()` and your route handler runs 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, calls `next()` and settles the payment after your route handler responds
### MCP server protection
If your Hono app hosts an MCP server (Streamable HTTP), Foldset can gate individual tool calls and resource reads. Configure MCP rules 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: /
```
# Next.js
Source: https://docs.foldset.com/frameworks/nextjs
Add Foldset payment gating to your Next.js application
## Install
```bash npm theme={null}
npm install @foldset/nextjs
```
```bash yarn theme={null}
yarn add @foldset/nextjs
```
```bash pnpm theme={null}
pnpm add @foldset/nextjs
```
## Setup
Copy your API key from the [Foldset dashboard](https://foldset.com/dashboard/api-keys).
The SDK reads your API key from the `FOLDSET_API_KEY` environment variable.
**Local development:** add it to `.env.local` (gitignored by default in Next.js):
```
FOLDSET_API_KEY=sk_live_...
```
**Production:** set it in your hosting provider's environment variable settings (e.g. Vercel, AWS, Railway). Never commit API keys to your repository.
Do not use `.env` for secrets. `.env` is often committed to git. Use `.env.local` for local development and your hosting provider's secrets management for production.
Create `middleware.ts` in the root of your project:
```typescript middleware.ts theme={null}
import { foldset } from "@foldset/nextjs";
export default foldset({
apiKey: process.env.FOLDSET_API_KEY!,
});
```
If you need to compose Foldset with your own middleware logic, use `withFoldset`. Your function only runs if payment is satisfied:
```typescript middleware.ts theme={null}
import { withFoldset } from "@foldset/nextjs";
import { NextResponse, type NextRequest } from "next/server";
export default withFoldset(
{ apiKey: process.env.FOLDSET_API_KEY! },
async function middleware(request: NextRequest) {
// Your own logic here (auth, redirects, headers, etc.)
return NextResponse.next();
}
);
```
Next.js 16 renames `middleware.ts` to `proxy.ts` and the exported function to `proxy`. If you're on Next.js 16 or later, name the file `proxy.ts` instead.
Head to the [rules page](https://foldset.com/dashboard/rules) to choose which paths to protect and set prices.
## How it works
The Foldset middleware runs on every incoming request to your Next.js app:
1. Checks the request path against your configured rules
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 rules 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: /
```
# Other Languages
Source: https://docs.foldset.com/frameworks/other
SDKs for Go, Rust, and more
We're currently beta testing SDKs for additional languages and frameworks:
* **Go**
* **Rust**
* **Ruby** (Rails, Rack)
* **Java** (Spring)
These should be finalized in the next few weeks. If you'd like early access, email [beta@foldset.com](mailto:beta@foldset.com).
# Introduction
Source: https://docs.foldset.com/introduction
Monetize your APIs and MCP tools with x402 micropayments
Foldset makes it easy to monetize your APIs and MCP tools using [x402](https://x402.org), the open protocol for HTTP micropayments. Integrate our SDK into your product and start earning from every request.
## How it works
1. **Sign up** at [foldset.com](https://foldset.com)
2. **Check your robots.txt**: Foldset automatically scans your `robots.txt` for rules that block AI crawlers (GPTBot, ClaudeBot, etc.). If bots are blocked, you'll see exactly which ones and the offending rules so you can update your `robots.txt` and start earning.
3. **Integrate** our SDK into your app
4. **Configure** which API endpoints or MCP tools to protect and set prices in the dashboard
5. **Earn** per request and withdraw to your bank account
## What can you protect?
* **APIs**: REST endpoints, data feeds, search APIs
* **MCP servers**: individual tool calls and resource reads on your Model Context Protocol servers
## Pick your integration
### Frameworks
Install a package and add a few lines of code to your app.
Add Foldset middleware to your Next.js app.
Add Foldset middleware to your Express app.
Add Foldset middleware to your Hono app.
Add Foldset middleware to your FastAPI app.
Add Foldset middleware to your Flask app.
Go, Rust, and more. Currently in beta.