Back to Documentation

SDK Documentation

Monetize Any API in Under 60 Seconds

RelayAI SDK transforms any API endpoint into a revenue-generating service with x402 micropayments. Add payment gates to your APIs with a single line of code.

One-Line Integration

Add payment middleware to any endpoint instantly

Instant Settlements

Payments clear in seconds via PayAI facilitator

Developer Focused

TypeScript SDK with comprehensive tooling

5-Minute Setup

Create your first monetized API endpoint

1. Install Package

npm install relai-sdk

2. Add Wallet Provider

Install a Solana wallet like Phantom or Solflare to handle payments

// Install Phantom: https://phantom.app/
WalletProvider.jsx
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react'
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui'
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets'
import { clusterApiUrl } from '@solana/web3.js'
import { useMemo } from 'react'

export function WalletProviderComponent({ children }) {
  const network = WalletAdapterNetwork.Mainnet
  const endpoint = useMemo(() => clusterApiUrl(network), [network])

  const wallets = useMemo(() => [
    new PhantomWalletAdapter(),
    new SolflareWalletAdapter(),
  ], [network])

  return (
    <ConnectionProvider endpoint={endpoint}>
      <WalletProvider wallets={wallets} autoConnect>
        <WalletModalProvider>
          {children}
        </WalletModalProvider>
      </WalletProvider>
    </ConnectionProvider>
  )
}

4. Use the Client SDK

client.js
import { RelaiClient } from 'relai-sdk/client'

{/* Initialize client with wallet */}
const client = new RelaiClient({
  baseUrl: 'https://relai.fi',
  wallet: {
    address: publicKey.toString(),
    signTransaction: signTransaction,
  },
  network: 'solana',
  maxPaymentAmount: BigInt(10000000),
});

{/* Call paid API */}
const api = client.useApi('your-api-id');
try {
  const response = await api.call({
    path: '/api/endpoint',
    method: 'GET',
    body: { param: 'value' },
  });
  // Process your API data here
} catch (error) {
  // Handle payment or API errors
}

5. Test Your Integration

Run your client code and watch payments happen automatically

Why Choose RelayAI SDK

Built for developers who want to monetize APIs without the complexity

Zero Infrastructure

No need to manage payment processors or blockchain nodes

Instant Payouts

Funds settle directly to your wallet in seconds

TypeScript Ready

Full type safety and excellent developer experience

Framework Agnostic

Works with Express, Next.js, NestJS, and any Node.js framework

Ready to Get Started?

Join the revolution in API monetization

Ready to monetize your API? Get started with RelayAI SDK today.