RelAI WebSocket Relay for x402 - What API Providers Need to Know

web3luka
Feb 18, 2026 · 3 min read
RelAI WebSocket Relay for x402 - What API Providers Need to Know

RelAI now supports x402 payment flows over WebSocket. If you publish APIs on RelAI, this unlocks lower-latency transport for buyers and agents, while keeping your existing provider integration unchanged.

The short version: buyers can use a shared WS gateway, but providers still expose normal HTTP APIs.

Why add WebSocket transport to x402?

HTTP x402 works great and remains fully supported. WebSocket adds a second transport optimized for interactive and high-frequency usage.

Main benefits

  • Lower overhead per request - fewer TCP/TLS handshakes with persistent sockets
  • Lower latency - especially when making many paid calls in sequence
  • Better fit for agents - one live connection can handle many request/reply cycles
  • Backward compatibility - HTTP fallback remains available
For consumers this means smoother paid API sessions. For providers it means more traffic opportunities without additional payment logic work.

The key model: shared WS endpoint + per-API relay URL

On RelAI, each published API has an HTTP relay URL:

https://api.relai.fi/relay/{apiId}/...

WebSocket uses one shared endpoint:

wss://api.relai.fi/api/ws/relay

The buyer sends method relay.call and specifies which API to target (apiId) and which route to call (path).

What providers need to implement

In most cases: nothing new.

If your API already works with RelAI HTTP relay, you do not need to run a dedicated WebSocket server. RelAI's WS relay forwards calls into the same HTTP relay and x402 middleware stack used today.

That means:

  • same pricing config,
  • same facilitator flow,
  • same settlement behavior,
  • same endpoint business logic.
WS is an access transport, not a provider-side protocol rewrite.

How the 402 payment handshake works over WS

The flow remains identical to HTTP x402 semantics:

  1. Buyer sends relay.call without payment payload.
  2. RelAI responds with error code 402 and paymentRequired details.
  3. Buyer signs payment payload with wallet.
  4. Buyer retries relay.call with top-level payment.
  5. On success, buyer gets result and optional paymentResponse (settlement data).
This preserves the same economic guarantees while reducing transport friction.

Example WS request envelope

{
  "id": "req-42",
  "method": "relay.call",
  "params": {
    "apiId": "1769629274857",
    "path": "/v1/chat/completions?model=gpt-4o-mini",
    "requestMethod": "POST",
    "requestHeaders": {
      "Content-Type": "application/json",
      "Accept": "application/json"
    },
    "requestBody": {
      "messages": [{ "role": "user", "content": "Hello" }]
    }
  }
}

For buyers and agent builders

If you consume many paid endpoints in one session:

  • keep a persistent WS connection,
  • correlate responses by id,
  • set request-level timeouts,
  • fall back to HTTP when WS is unavailable.
RelAI frontend hooks already support this transport strategy via feature flags.

Operational guidance for providers

Even though providers do not run WS infrastructure in this model, you should still:

  • monitor settlement hashes (paymentResponse.transaction) for observability,
  • keep endpoint responses deterministic and fast,
  • ensure relay targets are stable under bursty agent traffic,
  • document your endpoint rate limits clearly for buyers.

Final takeaway

RelAI's WebSocket relay gives buyers and autonomous agents a faster path for x402 payments, while preserving the provider experience you already have today.

No new provider-side WS server. No separate payment stack. Just an additional transport that improves throughput and UX for paid API consumption.

Need protocol context first? Read the x402 overview and the RelAI documentation hub.


If your API is already monetized through RelAI HTTP relay, you're already compatible with WS relay consumption.

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.