Monetize Your API in 5 Minutes with x402 and RelAI

web3luka
Mar 1, 2026 · 4 min read
Monetize Your API in 5 Minutes with x402 and RelAI

You have an API. Maybe it's a wrapper around an LLM. Maybe it's a data endpoint, an inference service, or a custom tool you built for your own agents. It works. People want to use it.

But charging for it is a different problem entirely.

You need a billing system. Or a Stripe integration. Or an API key management layer. Or a subscription tier. And suddenly what started as a weekend project has a month of infrastructure work attached to it.

There is a simpler path.

This post walks through turning any HTTP API into a pay-per-call service using RelAI and the x402 protocol — in about five minutes, with three HTTP requests.


What You Need

  • An API with a public URL (any language, any framework)
  • A crypto wallet address to receive payments (Solana or EVM)
  • A RelAI account — or just a service key via the Management API
That's it. No SDK required on your server. No changes to your existing code.

How It Works

RelAI acts as a proxy in front of your API. When someone calls your endpoint through RelAI:

  1. RelAI returns an HTTP 402 Payment Required response with a payment challenge
  2. The caller pays in USDC or other supported tokens (on Solana, Base, SKALE Base, Avalanche, or other supported networks)
  3. RelAI verifies the payment on-chain and forwards the request to your server
  4. Your server responds normally — it never sees the payment logic
Your API stays exactly as it is. RelAI handles everything else.

Step 1: Get a Service Key

If you already have a RelAI account, go to relai.fi/dashboard/api-keys and create a key there.

If you want to do it programmatically:

curl -X POST https://api.relai.fi/v1/keys \
  -H "Authorization: Bearer YOUR_JWT" \
  -H "Content-Type: application/json" \
  -d '{ "label": "my-api-key" }'

Save the returned sk_live_... key. You'll use it for all management calls.


Step 2: Register Your API

One request to register your API with RelAI:

curl -X POST https://api.relai.fi/v1/apis \
  -H "X-Service-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Inference API",
    "baseUrl": "https://your-api.example.com",
    "network": "base",
    "merchantWallet": "0xYourWalletAddress",
    "endpoints": [
      { "path": "/v1/predict", "method": "post", "usdPrice": 0.05 }
    ]
  }'

This tells RelAI:

  • Where your API lives (baseUrl)
  • Which wallet receives the payments (merchantWallet)
  • Which endpoint to monetise and at what price
The response includes your apiId. Your API is now live — immediately usable via the RelAI relay, visible in the public marketplace once reviewed.

Step 3: Call Your API Through RelAI

Your monetised endpoint is now available at:

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

Any x402-aware client can call it and pay automatically. For example, using the RelAI SDK:

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

const client = createX402Client({
wallet: yourWallet,
network: 'base',
})

const response = await client.fetch(
'https://api.relai.fi/relay/YOUR_API_ID/v1/predict',
{
method: 'POST',
body: JSON.stringify({ input: 'Hello world' }),
}
)

The SDK handles the payment challenge, signs the transaction, and retries the request automatically. Your server receives a normal HTTP request with no payment logic to handle.


Setting Prices

You can set a different price per endpoint:

curl -X PUT https://api.relai.fi/v1/apis/{apiId}/pricing \
  -H "X-Service-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "endpoints": [
      { "path": "/v1/predict-fast",  "method": "post", "usdPrice": 0.02 },
      { "path": "/v1/predict-large", "method": "post", "usdPrice": 0.15 },
      { "path": "/v1/embed",         "method": "post", "usdPrice": 0.001 }
    ]
  }'

Prices are in USD. Conversion to USDC happens automatically at the time of payment. You can update pricing at any time — no downtime, no redeployment.


Checking Revenue

curl https://api.relai.fi/v1/apis/{apiId}/stats \
  -H "X-Service-Key: sk_live_..."

Returns total calls, total revenue in USD, and per-endpoint breakdowns for the last 7, 30, or 90 days.


Supported Networks

Your callers can pay on whichever network they prefer:

NetworkTokenNotes
SolanaUSDCFastest, lowest fees
BaseUSDCEVM, low fees
SKALE BaseUSDC, USDT, EURC, and moreGas-free for users
AvalancheUSDCGas sponsored by RelAI
PolygonUSDC
EthereumUSDC
Set "network": "solana", "base", "skale-base", etc. when registering your API. You can support multiple networks by updating the pricing configuration.

For AI Agents

If your API is consumed by AI agents rather than humans, the x402 protocol is a natural fit. Agents can pay autonomously — no human needs to approve each transaction.

Agents can also bootstrap their own RelAI credentials without any human login, using a wallet signature flow:

import requests, base58
from solders.keypair import Keypair

kp = Keypair()
BASE = "https://api.relai.fi/mcp/management/bootstrap/agent"

msg = requests.post(BASE, json={"publicKey": str(kp.pubkey())}).json()["message"]
sig = base58.b58encode(bytes(kp.sign_message(msg.encode()))).decode()

result = requests.post(BASE, json={
"publicKey": str(kp.pubkey()),
"signature": sig,
"message": msg,
"label": "my-agent",
}).json()

service_key = result["key"] # sk_live_...

From there, the agent can register APIs, update pricing, and monitor revenue — all programmatically, with no human in the loop.


What Happens After You Register

Your API is immediately usable through the RelAI relay. Within typically 24–48 hours, the RelAI team reviews and approves it for the public marketplace, making it discoverable to other developers and agents.

The marketplace is indexed by AI agents via /.well-known/ai-plugin.json, /llms.txt, and /openapi.json — so your API can be discovered automatically by agents browsing for tools to use.


The Full Picture in Three Steps

Register your API:

POST /v1/apis   →   apiId

Set your price:

PUT /v1/apis/{apiId}/pricing   →   live immediately

Check revenue:

GET /v1/apis/{apiId}/stats   →   calls, USD earned

That's it.


Start at relai.fi/dashboard or read the full Management API documentation.

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.