TutorialQuick StartSDKGuide

"How to Monetize Your API in 5 Minutes with XPay"

"XPay Team"2 min read

How to Monetize Your API in 5 Minutes with XPay

Monetizing an API shouldn't require a billing team, legal review, and months of development. With XPay, you can start charging per request in under five minutes.

Prerequisites

  • Node.js 18+
  • A USDC wallet on Base
  • An API endpoint (any framework)

Step 1: Install XPay

npm install @xpay/sdk

Step 2: Get Your API Key

Sign up at get402.net and create an API key. You'll get a sk_xxx secret key.

Step 3: Protect Your Endpoint

Express.js

import express from 'express';
import { xpay } from '@xpay/sdk';

const app = express();

app.use(xpay.middleware());

app.get('/api/premium-data', xpay.protect('0.01'), (req, res) => {

res.json({ data: 'Your premium data here' });

});

app.listen(3000);

Next.js

import { xpay } from '@xpay/sdk';

export async function GET(request: Request) {

const payment = await xpay.verify(request, { amount: '0.01' });

if (!payment.paid) {

return Response.json(payment.error, { status: 402 });

}

return Response.json({ data: 'Premium content' });

}

Python (FastAPI)

from fastapi import FastAPI
from xpay_sdk import XPay

app = FastAPI()

xpay = XPay(api_key="sk_xxx")

@app.get("/api/premium-data")

@xpay.protect(amount="0.01")

async def get_premium_data():

return {"data": "Premium content"}

Step 4: Test It

curl -H "X-Pay: true" https://api.yoursite.com/api/premium-data

You'll get a 402 response until payment is made, then your data.

Step 5: Get Paid

Every time someone calls your endpoint, you earn USDC. Withdraw at any time — no monthly cycles, no minimums.

That's It

You just monetized your API. The whole setup took 5 minutes. Welcome to the HTTP 402 revolution.

Ready to monetize your API?

Get started with get402 in 5 minutes. One command, one SDK, one HTTP status code.