RailPayDocs

Guides

SDK & MCP

Open-source TypeScript SDK and MCP server, plus a Python SDK, agent tools and a self-hosted facilitator. All MIT licensed.

Two open-source packages wrap the API: railpay-sdk (pay for x402 resources from an agent wallet, or charge for your own API) and railpay-mcp (gives an AI agent in Claude Code, Claude Desktop or another MCP client a RailPay wallet). Both are at v0.2.0, MIT licensed, with CI on GitHub.

Not on npm yet

Install both from GitHub. The SDK's one runtime dependency is viem. It runs on Node 20+, Bun, Deno and Cloudflare Workers.

Install the SDK

bash
pnpm add https://github.com/railpayapp/railpay-sdk/releases/download/v0.2.0/railpay-sdk-0.2.0.tgz
# or: npm install https://github.com/railpayapp/railpay-sdk/releases/download/v0.2.0/railpay-sdk-0.2.0.tgz

Pay for an x402 resource

Create an agent in the app, set its policy, fund its wallet with USDG and create an agent key. withPayment answers a 402, asks RailPay to sign an EIP-3009 authorization (POST /v1/agent/pay, policy checked first) and retries once with PAYMENT-SIGNATURE.

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" });

const res = await paidFetch("https://dapp.railpay.app/x402/time");
console.log(await res.json());
console.log(readPaymentResponse(res)?.transaction); // settlement tx hash

If no accepted option is exact / eip155:4663 / USDG, the original 402 comes back unchanged. A price above maxAmount throws over_max_amount before anything is signed.

Charge for your API

createPaywall answers 402 with the requirement, checks the payment and the payer's balance on-chain, settles it through an x402 facilitator (Toll, then Primer), reads the USDG transfer back from the chain and only then calls your handler. Prices start at 0.001 USDG.

ts
import { createPaywall } from "railpay-sdk";

const paywall = createPaywall({ payTo: "0xYourWallet", price: "0.01", description: "Daily market report" });

export default {
  fetch: (request: Request) => paywall.handle(request, () => Response.json({ report: "…" })),
};

On serverless platforms or with several instances, pass a shared store whose claim() is an atomic insert-if-absent, so two instances cannot settle the same authorization at once. The full API is in the SDK README. For inference and GPU endpoints, see AI inference and GPU compute.

MCP server

ToolWhat it doesSpends
railpay_agentAgent wallet: address, USDG, ETH, spent today, policyNo
railpay_fetchHTTP request that pays a 402, returns the body and the payment with its transaction linkYes
railpay_pay_requirementSigns a payment for a 402 the agent already hasYes, once settled
railpay_sendPays another RailPay agent (agt_…)Yes
railpay_networkChain, USDG, x402 settings, facilitators, relayer status. No key neededNo

Clone both repos side by side and build them (the MCP server depends on ../railpay-sdk), then add it to Claude Code:

bash
git clone https://github.com/railpayapp/railpay-sdk.git
git clone https://github.com/railpayapp/railpay-mcp.git
cd railpay-sdk && pnpm install && pnpm build && cd ..
cd railpay-mcp && pnpm install && pnpm build

claude mcp add railpay \
  -e RAILPAY_AGENT_KEY=rp_sk_... \
  -e RAILPAY_MAX_PER_CALL=0.1 \
  -- node /absolute/path/to/railpay-mcp/dist/index.js

Three limits apply to every payment and the tightest wins: the agent policy enforced by RailPay, RAILPAY_MAX_PER_CALL (default 0.1 USDG) enforced by the MCP server before anything is signed, and an optional max_amount per call. Setup for Claude Desktop and other clients is in the MCP README.

Keep agent keys on a server

An agent key can spend from the agent wallet within its policy. Never put it in a browser bundle or a shared repo. Pause the agent or delete the key in the app to cut access at once.

More open-source packages

RepoLanguageWhat it is
railpay-pythonPythonPython SDK. An agent pays x402 APIs from its RailPay wallet, sync or async, and FastAPI or ASGI apps charge per request.
railpay-agent-toolsTypeScriptPayment tools for Vercel AI SDK, OpenAI, Claude and LangChain agents, with a per-call cap, a session budget and a host allowlist.
railpay-facilitatorTypeScriptSelf-hosted x402 facilitator. Verifies and settles USDG payments on Robinhood Chain with your own key, on Node or Cloudflare Workers.

All three are MIT licensed; install steps and releases are in each README. To settle with your own facilitator, list it in the seller's facilitators, with a public one as fallback if you like: facilitators: ["https://your-facilitator", "https://x402.t0ll.xyz"]. The seller still reads the USDG transfer back from the chain before it serves anything. RailPay's own x402 resources keep using Toll, then Primer.

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