Introducing the @relai-fi/x402 SDK

RelAI Team
Feb 5, 2026 · 2 min read

The RelAI SDK lets developers add pay-per-use payments to any app or API with just a few lines of code. Whether you're building with React or Node.js, it works out of the box.

Install

npm install @relai-fi/x402

Protect your API (server-side)

Add one line to any endpoint and it becomes a paid service:

import Relai from '@relai-fi/x402/server';

const relai = new Relai({ network: 'base' });

app.get('/api/data', relai.protect({
payTo: '0xYourWallet',
price: 0.01,
}), handler);

When someone calls this endpoint without paying, they get a 402 Payment Required response with the price. Once they pay, they get the data.

Use paid services (client-side)

The client SDK handles payments automatically - you just fetch like normal:

import { createX402Client } from '@relai-fi/x402/client';

const client = createX402Client({
network: 'base',
evmWallet: { address, signTypedData },
});

const response = await client.fetch('https://api.example.com/data');

If the server asks for payment, the SDK signs it with your wallet and retries - all invisible to the user.

React hook

For React apps, there's a ready-made hook:

import { useRelaiPayment } from '@relai-fi/x402/react';

const { relaiFetch, isProcessing } = useRelaiPayment({
network: 'base',
evmWallet: { address, signTypedData },
});

// Use relaiFetch instead of fetch - payments are handled automatically
const data = await relaiFetch('https://api.example.com/data');

Supported networks

  • Base - Ethereum layer 2
  • Avalanche - fast C-Chain
  • SKALE - zero gas fees
  • Solana - fast and cheap
All payments are in USDC. Gas fees are covered by RelAI on every network.
Three lines of code to monetize any API. That's the idea.