RailPayDocs

Guides

Pay for AI inference and GPU compute

Agents pay per call for model and GPU APIs in USDG. Providers charge per call, with no accounts or cards.

An AI agent that calls a model, runs an embedding batch or rents GPU time has to pay for it per call, without a person's card on file. Over x402 it can: the API answers 402 with a price, the agent's RailPay wallet signs a USDG payment for exactly that price, and the API serves the result once the payment has settled on Robinhood Chain. The same SDK lets you charge for your own inference or GPU endpoint.

What RailPay does here

RailPay moves the payment. It does not run GPUs or models, it has no compute partners and it publishes no compute prices. Hosts and prices in the examples below are placeholders.

  • Live: agents pay any x402 API (AI inference, GPU compute, data) in USDG from an agent wallet, inside the agent's policy.
  • Live: inference APIs, GPU clouds and model hosts charge per call with createPaywall from railpay-sdk, or with Paywalls in the app.
  • Live: each payment is read back from the chain before the response is served.
  • Planned: metered per-second or streaming billing for long GPU jobs, and compute-specific budgets (per provider, model or job).

How a paid call works

  1. The agent calls the endpoint. Without a payment it answers 402 with the price in USDG and the provider's wallet (PAYMENT-REQUIRED).
  2. RailPay checks the agent's policy. If the call passes, the agent wallet signs an EIP-3009 authorization for exactly that price to that wallet. Nothing is sent on-chain yet.
  3. The agent retries with PAYMENT-SIGNATURE. The provider verifies it, has an x402 facilitator settle it (the facilitator pays the gas), reads the USDG transfer back from the chain, then runs the work and answers with the transaction in PAYMENT-RESPONSE.

The provider needs no API keys, customer accounts or card processing to get paid: each call carries its own payment, and the USDG goes from the agent's wallet straight to the provider's. The price is fixed before the work runs (the x402 exact scheme), so it has to cover the most a call can cost. The protocol in full is in x402 payments.

Agent side: pay for compute

Create an agent in the app, fund its wallet with USDG (x402 payments need no ETH), set its policy and create an agent key. Then wrap fetch with withPayment from railpay-sdk. maxAmount is a second limit on top of the policy: a call priced above it throws over_max_amount before anything is signed.

ts
import { RailPay, withPayment, readPaymentResponse } from "railpay-sdk";

const railpay = new RailPay({ apiKey: process.env.RAILPAY_AGENT_KEY });
const paidFetch = withPayment(railpay, { maxAmount: "0.05" });

// Any x402 endpoint that takes exact / eip155:4663 / USDG. Placeholder host.
const res = await paidFetch("https://inference.example.com/v1/generate", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ prompt: "Summarise this filing", max_tokens: 512 }),
});
console.log(await res.json());
console.log(readPaymentResponse(res)?.transaction); // settlement tx hash

The request body is kept and sent again on the paid retry. If the endpoint offers no exact / eip155:4663 / USDG option, the original 402 comes back unchanged and nothing is paid.

From an MCP client

An agent in Claude Code, Claude Desktop or another MCP client can do the same through railpay-mcp. railpay_fetch takes a URL, method, body and headers, pays the 402 and returns the response body with the payment and its transaction link. RAILPAY_MAX_PER_CALL (default 0.1 USDG) caps each call before anything is signed, and the tool's max_amount can only lower it. Setup is in SDK & MCP.

Provider side: charge per call

If you run an inference API, a GPU cloud or a model host, wrap the endpoint with createPaywall. It answers 402 with your price; checks the authorization, its nonce and the payer's USDG balance on-chain; has an x402 facilitator settle it (Toll, then Primer, which pay the gas); reads the exact USDG transfer back from the transaction receipt; and only then calls your handler. A facilitator's word alone is never trusted. Prices start at 0.001 USDG.

Cloudflare Worker (any Fetch API runtime works)
import { createPaywall } from "railpay-sdk";

type Input = { prompt?: unknown; max_tokens?: unknown };
const MAX_TOKENS = 1024; // the price below has to cover a call this long

const paywall = createPaywall({
  payTo: "0xYourWallet",
  price: "0.01", // USDG per call. A placeholder: set your own
  description: "Text generation, up to 1,024 output tokens",
});

export default {
  async fetch(request: Request) {
    // Check the input before asking for money: a bad request gets 400, not 402.
    const input = (await request.json().catch(() => null)) as Input | null;
    const prompt = input?.prompt;
    if (typeof prompt !== "string" || !prompt) {
      return Response.json({ error: "prompt_required" }, { status: 400 });
    }
    const asked = Math.floor(Number(input?.max_tokens));
    const maxTokens = asked >= 1 ? Math.min(asked, MAX_TOKENS) : MAX_TOKENS;

    return paywall.handle(request, async () => {
      // runModel is yours: your model server or GPU backend
      const output = await runModel(prompt, { maxTokens });
      return Response.json({ output });
    });
  },
};

Validate the request before the paywall, so a malformed call is refused with a 400 instead of being charged for nothing. Do the work inside the handler: handle calls it only once the USDG transfer is on-chain. If settlement is still confirming, the caller gets 402 settlement_pending, and its retry with the same payment is served once.

Price the worst case

The x402 exact scheme charges one fixed amount before the work runs, and there is no refund or top-up step. So bound what one call can cost you, then price that bound: clamp max_tokens on the server (and input length, image size or steps, whatever drives your cost) and reject requests above your limits. A short call pays the same as a long one. If the spread is wide, offer a few endpoints, each with its own paywall, limit and price. Metered billing is Planned.

GPU jobs: quote, pay, run

When the cost depends on the job (a fine-tune, a batch, a long render), split it into two calls: a free quote that prices the job from its spec, then a paid run at exactly the quoted price. Keep the quote on your server under an id, so the job cannot change after it is priced. Each payment starts the job once; the same authorization cannot be used twice.

Provider (Hono)
import { Hono } from "hono";
import { createPaywall, memoryStore } from "railpay-sdk";

const app = new Hono();
const PAY_TO = "0xYourWallet";
// One store for every paywall below. On several instances, pass a shared one.
const store = memoryStore();

// priceFor, quotes and startJob are yours:
// your pricing, a key-value store and your GPU scheduler.

// 1. Free quote: price the job and keep the spec with it.
app.post("/quote", async (c) => {
  const spec = await c.req.json();
  const price = priceFor(spec); // a USDG decimal string, with your own ceiling
  const id = crypto.randomUUID();
  // Keep it longer than a payment takes: authorizations last up to 5 minutes.
  await quotes.put(id, { spec, price });
  return c.json({ id, price, run: `/jobs/${id}` });
});

// 2. Paid run: the 402 asks for exactly the quoted price.
//    The job starts only after the payment has settled.
app.post("/jobs/:id", async (c) => {
  const q = await quotes.get(c.req.param("id"));
  if (!q) return c.json({ error: "unknown_quote" }, 404);
  const paywall = createPaywall({ payTo: PAY_TO, price: q.price, store });
  return paywall.handle(c.req.raw, async () => {
    const job = await startJob(q.spec);
    return c.json({ job }, 202);
  });
});

The agent reads the quote, decides, then pays for the run with its paying fetch. Both maxAmount and the agent's per_request_max have to allow the quoted price.

Agent
const GPU = "https://gpu.example.com"; // placeholder host
const quote = await (await fetch(`${GPU}/quote`, {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify(spec),
})).json();

const paidFetch = withPayment(railpay, { maxAmount: budgetPerJob });
const run = await paidFetch(new URL(quote.run, GPU), { method: "POST" });

Facilitator limits

Toll, the first default facilitator, settles 0.001 to 100 USDG per payment. Facilitators are third-party services with their own limits: check them before you send volume, or pass your own list with facilitators.

More than one instance

By default createPaywall remembers payments in memory (memoryStore(), one process). A settled authorization's nonce is spent on-chain, so a replay sent to another instance is refused anyway; the gap is two instances settling the same authorization at the same moment. On serverless platforms or with several replicas, pass a shared store whose claim() is an atomic insert-if-absent: a database row with a unique key, Redis SET NX or a Durable Object. If you create a paywall per quote, give all of them the same store.

No code: Paywalls in the app

Paywalls in the app sell one fixed piece of text per request, paid to your wallet. That suits a static result, a dataset sample or a first test of your pricing. To run a model per call, wrap your own endpoint with createPaywall.

Policy for agents that buy compute

FieldSet it to
allowed_hostsThe inference and GPU hosts the agent may pay, checked against the resource URL of each 402. Empty means any host, so a link planted in a prompt could be paid within the caps.
allowed_pay_toThe providers' wallets. The agent signs for a named payee, so this pins exactly where the money can go; a host alone can name any payTo.
per_request_maxThe most one call or one job may cost. For quoted GPU jobs, the largest job you would let the agent start unattended.
daily_capThe most the agent may spend per UTC day across all providers, signed but unsettled payments included. A loop that keeps calling a model stops here.
pausedOne switch that blocks every payment, for when a run goes wrong.

Every attempt shows on the agent page as pending, paid (with its transaction) or blocked (with the reason), so you can see what the agent spent on compute and where. Keep only what the agent needs in its wallet: it is a hot wallet run by RailPay. The full policy is in AI agents.

Planned

  • Metered billing for long GPU jobs: per-second or streaming payments instead of one price up front. Part of utility 11, recurring and streaming payments.
  • Compute budgets: limits per provider, model or job, on top of the agent's daily cap.

Neither is built and there are no dates. Until then, use per-call prices and the quote, pay, run pattern above.

RailPay settles in USDG on Robinhood Chain (chain id 4663). Sends and invoice payments are signed in your own wallet and go straight to the recipient. Agent wallets are hot wallets run by RailPay. Fees, yield, cards, ramps and other chains are planned.

© 2026 RailPay. The RailPay token ($RPAY) is live on Pons (Robinhood Chain). Trust only the contract address posted on the Token page and railpay.app.

Website