Developers
Build on RailPay.SDK, MCP server and API.
Charge for your API per request, let an agent pay for others, or wire invoices into your product. The SDKs, MCP server, agent tools and facilitator are open source and MIT licensed.
agent.ts · withPayment
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 hashFrom the railpay-sdk and railpay-mcp READMEs. Hosts and keys are placeholders.
Docs
Start where you are.Every guide, one click away.
- QuickstartFrom sign-up to a paid invoice in a few minutes.
- API referenceAuthentication, keys and every endpoint the API serves.
- x402 paymentsx402 v2, exact scheme, EIP-3009 on USDG. Request, sign, retry, settled.
- SDK and MCPInstall the SDK, pay a 402, charge for your API, add the MCP server.
- AI agentsAgent wallets, policies, events and what an agent key can do.
- ErrorsEvery error code and what to do about it.
railpay-sdk
Pay a 402, or send one.One TypeScript package.
withPayment answers a 402 from an agent wallet and retries once. createPaywall answers 402 with your price, settles through an x402 facilitator and reads the transfer back from the chain before your handler runs.
pnpm add https://github.com/railpayapp/railpay-sdk/releases/download/v0.3.0/railpay-sdk-0.3.0.tgzNot on npm yet
Keep agent keys on a server
agent.ts · withPayment
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 hashrailpay-mcp
A wallet for your AI agent.In Claude Code or any MCP client.
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, and an optional max_amount per call.
| Tool | ToolWhat it does | Spends |
|---|---|---|
| railpay_agent | railpay_agentThe agent wallet: address, USDG balance, ETH, spent today, policy. | No |
| railpay_fetch | railpay_fetchHTTP request that pays a 402 automatically, then returns the body and the payment with its transaction link. | Yes |
| railpay_pay_requirement | railpay_pay_requirementSigns a payment for a 402 the agent already has and returns the PAYMENT-SIGNATURE header to retry with. | Yes |
| railpay_send | railpay_sendPays another RailPay agent (agt_…). | Yes |
| railpay_network | railpay_networkPublic facts: chain, USDG, x402 settings, facilitators, relayer status. No key needed. | No |
Clone both repos side by side
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 buildREST API
Plain HTTP and JSON.Two kinds of key.
Base URL https://dapp.railpay.app. Request bodies take USDG as decimal strings; amounts in responses are integers in base units (1 USDG = 1,000,000).
Account keyrp_sk_…
Everything for the owning account: invoices, transfers, paywalls, agents and their policies, and agent withdrawals to the owner's wallet. Created on the Developers page in the app.
Agent keyrp_sk_…
Returned when you create an agent. Only the agent endpoints (pay, send, me), always inside the agent's policy. Cannot touch the owner account or withdraw.
Send keys as Authorization: Bearer rp_sk_…. Keys are shown once; RailPay stores only a SHA-256 hash.
POST /v1/invoices
curl -X POST https://dapp.railpay.app/v1/invoices \
-H "Authorization: Bearer $RAILPAY_KEY" \
-H "Content-Type: application/json" \
-d '{ "amount": "120", "memo": "Design work" }'Open source
Read the code.MIT licensed, on GitHub.
TypeScript and Python SDKs, an MCP server, agent tools for AI frameworks and a self-hosted x402 facilitator, under the railpayapp organization on GitHub.
- railpayapp /railpay-sdkTypeScript SDK. Pay for x402 resources from an agent wallet, or charge for your own API in USDG.TypeScriptMIT licenseView on GitHub
- railpayapp /railpay-pythonPython SDK. Agents pay x402 APIs in USDG, sync or async, and FastAPI apps charge per request.PythonMIT licenseView on GitHub
- railpayapp /railpay-mcpMCP server that gives an AI agent a RailPay wallet, inside the limits you set.TypeScriptMIT licenseView on GitHub
- railpayapp /railpay-agent-toolsPayment tools for Vercel AI SDK, OpenAI, Claude and LangChain agents, with a per-call cap, a session budget and a host allowlist.TypeScriptMIT licenseView on GitHub
- railpayapp /railpay-facilitatorSelf-hosted x402 facilitator. Verify and settle USDG payments on Robinhood Chain with your own key, on Node or Cloudflare Workers.TypeScriptMIT licenseView on GitHub
Ship a paid endpoint today.Or give an agent a wallet.
Settled in USDG on Robinhood Chain. Every payment is its own transaction, open on the explorer.