For agents: pay per request
- Pay any x402 API (AI inference, GPU compute, data) in USDG from the agent wallet.
- The policy is checked before anything is signed: per-request max, daily cap, allowed hosts and allowed recipients.
- No ETH needed for x402 payments: the provider or its facilitator pays the gas.
- Every attempt is logged, including the ones the policy blocked.
import { RailPay, withPayment } from "railpay-sdk";
const railpay = new RailPay({ apiKey: process.env.RAILPAY_AGENT_KEY });
const paidFetch = withPayment(railpay, { maxAmount: "0.05" });
// The 402 is answered from the agent wallet, inside its policy.
// POST bodies are kept and sent again on the retry.
const res = await paidFetch("https://inference.example.com/v1/generate", {
method: "POST",
body: JSON.stringify({ prompt: "Summarize this filing" }),
});