RelAI SDK Now Supports WebSocket Relay - Here’s How to Use It

RelAI Team
Feb 20, 2026 · 2 min read
RelAI SDK Now Supports WebSocket Relay - Here’s How to Use It

Starting now, RelAI SDK includes built-in WebSocket relay transport for x402 payments.

That means you can keep the same client.fetch(...) integration, but unlock faster real-time paid flows for interactive apps and AI agents. And yes - HTTP fallback is still available when needed.

This is one of the biggest transport UX upgrades in the SDK so far, and adoption is literally a small config change.

In this post, you get copy-paste examples for:

  1. Minimal SDK setup
  2. Standard relay calls
  3. WebSocket relay transport
  4. Whitelabel URL support
  5. React hook usage

1) Install

npm install @relai-fi/x402

2) Create client once

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

const client = createX402Client({
wallets: {
// Solana wallet (required for Solana payments)
solana: {
publicKey: solanaWallet.publicKey,
signTransaction: solanaWallet.signTransaction,
},
// EVM wallet (required for EVM payments)
evm: {
address: evmWallet.address,
signTypedData: evmWallet.signTypedData,
},
},
facilitatorUrl: 'https://facilitator.x402.fi',
relayWs: {
enabled: true,
// Optional explicit relay WS endpoint
wsUrl: 'wss://api.relai.fi/api/ws/relay',
},
verbose: true,
});

3) Basic paid relay call

Use your normal relay HTTP URL. The SDK handles 402 automatically.

const response = await client.fetch(
  'https://api.relai.fi/relay/1765103787374/projects?page=1',
  { method: 'GET' }
);

const data = await response.json();
console.log(data);

4) WebSocket relay transport (same fetch API)

You still call client.fetch(...). With relayWs.enabled=true, SDK can run the preflight + paid retry flow over WS.

const client = createX402Client({
  wallets,
  relayWs: {
    enabled: true,
    wsUrl: 'wss://api.relai.fi/api/ws/relay',
    fallbackToHttp: true,
  },
});

const response = await client.fetch(
'https://api.relai.fi/relay/1765103787374/v1/chat/completions',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [{ role: 'user', content: 'Hello from WS transport' }],
}),
}
);

5) Whitelabel URL example

RelAI SDK also supports whitelabel URLs directly.

const response = await client.fetch('https://myapi.x402.fi/projects?page=1', {
  method: 'GET',
});

const data = await response.json();

This allows buyers to use branded hostnames while keeping the same payment flow.

6) React hook example (useRelaiPayment)

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

export function PayButton() {
const { fetch, isLoading, transactionUrl } = useRelaiPayment({
wallets: {
solana: solanaWallet,
evm: evmWallet,
},
relayWs: {
enabled: true,
wsUrl: 'wss://api.relai.fi/api/ws/relay',
},
});

const onClick = async () => {
const res = await fetch('https://myapi.x402.fi/projects?page=1', {
method: 'GET',
});
console.log(await res.json());
};

return (

);
}

8) Quick production tips

  • Keep a single SDK client instance per session.
  • Enable verbose: true while integrating, then disable in production.
  • Do not hardcode private keys or secrets in frontend code.
  • Keep HTTP fallback enabled unless you explicitly want WS-only behavior.
If you are new to the payment model, start with the x402 overview and the RelAI documentation hub.
RelAI SDK gives you one fetch interface for both HTTP and WebSocket x402 flows, including whitelabel relay URLs.

Understand x402 before you implement

This guide uses payment primitives from the x402 standard. Read the protocol overview for a complete flow, terminology, and integration FAQ.