Skip to content

SDK API reference

This is the map of everything @piprail/sdk exports — grouped by the job it does, with the headline APIs marked and the advanced tiers (wire codecs, low-level exact, the driver SPI) kept clearly separate. Each group links to the page that documents it in full.

Two entry points cover the 99% case: requirePayment / createPaymentGate to get paid, and PipRailClient to pay. Everything else is built on those.

import { requirePayment, PipRailClient } from '@piprail/sdk'

The server-side surface. requirePayment is Express/Connect middleware; createPaymentGate is the same logic, framework-free.

ExportKindMarked
requirePaymentfnHeadline
createPaymentGatefnHeadline
toInvalidBodyfnDeprecated
RequirePaymentOptions, AcceptOption, ExactRailOptiontype
ChainSelector, TokenInputtype
PaymentGate, VerifyPaymentResulttype
X402InvalidBodytype
ExpressLike{Request,Response,Next,Middleware}type

See requirePayment & createPaymentGate, Defining accepts, Verifying payments, and Receipts & onPaid.

The client. One PipRailClient binds a chain + wallet and exposes the read-only trio (quoteestimateCostplanPayment) plus fetch.

ExportKindMarked
PipRailClientclassHeadline
planAcrossfnHeadline
PipRailClientOptions, WalletInput, PaymentSchemetype
PipRailQuote, PipRailCostQuote, PipRailEventtype
PaymentPlan, PayOption, PayBlocker, PayWarningtype
SessionBudget, SpendRemainingtype

See Quote, Estimate cost, planPayment(), fetch & autoRoute, Events, and Wallets by family.

The policy + ledger primitives. evaluatePolicy is the pure decision function the client and MCP both call before any spend.

ExportKindMarked
evaluatePolicyfnHeadline
PaymentPolicy, PaymentIntent, PolicyDecision, PolicyDenyCodetype
SpendRecord, SpendSummary, SpendAssetTotaltype

See Payment policy, Time envelope, evaluatePolicy(), and Spend ledger.

paymentTools(client) returns the tool set an autonomous LLM drives; the renderers and guide make a bound client legible to the model.

ExportKindMarked
paymentToolsfnHeadline
AgentTool, ToolAnnotationstype
summarizePlan, explainDecline, formatSpendReportfn
PIPRAIL_AGENT_GUIDE, agentGuideconst / fn
classifyChallengefn
ChallengeTriage, ChallengeVerdicttype

See Payment tools, The 7 tools, Renderers, Agent guide, and Challenge triage.

CHAINS is the built-in EVM mainnet registry (each preset carries its canonical token addresses); resolveChain turns a chain value into a ResolvedChain.

ExportKind
CHAINS, resolveChainconst / fn
ChainInput, ChainName, ResolvedChaintype
ChainPreset, TokenInfotype

See Chains overview and Chains & tokens.

Be found, and find others — on the open x402 indexes, with nothing PipRail-hosted. The builders are pure (emit static artifacts); the register* / searchOpenIndexes functions talk to the free public directories.

ExportKind
buildOpenApi, buildWellKnownX402, buildX402DnsTxt, buildBazaarExtension, GENERATORfn / const
searchOpenIndexes, register402Index, registerX402Scanfn
claim402IndexDomain, verify402IndexDomainfn
normalizeNetwork, getDirectoryInfo, decorateOutcome, DIRECTORY_INFOfn / const
PaymentRail, ResourceDescription, ManifestInputtype
OpenApiDocument, OpenApiOperation, WellKnownX402, X402DnsRecordtype
DiscoveryDescriptor, BazaarExtensiontype
DiscoverySource, DiscoveredRail, DiscoveredResourcetype
RegisterOutcome, RegisterInput, SearchOpenIndexesOptionstype
DirectoryInfo, ListingVisibility, DomainClaim, DomainVerificationtype
DiscoverOptions, RegisterOptionstype

See Discover & register, Open indexes, Emitters, and Domain verification.

Every thrown error is a typed PipRailError subclass with a stable .code.

ExportKind
PipRailErrorclass (base)
InsufficientFundsError, RecipientNotReadyErrorclass
WrongChainError, WrongFamilyError, UnknownTokenErrorclass
MissingDriverError, UnsupportedNetworkError, UnsupportedSchemeErrorclass
PaymentTimeoutError, ConfirmationTimeoutError, MaxRetriesExceededErrorclass
PaymentDeclinedError, InvalidEnvelopeError, NoCompatibleAcceptErrorclass
NonReplayableBodyError, SettlementErrorclass
toInsufficientFundsErrorfn
DeclineReasonCodetype

See Error model, Error hierarchy, VerifyErrorCode, and Why payments fail.

The raw envelope codecs, for building a client or server by hand. PipRailClient and createPaymentGate cover the 99% case — reach for these only when you’re hand-rolling the wire format (server: buildChallengeHeader → verify → buildReceiptHeader; client: parseChallengebuildSignatureHeaderparseReceipt).

ExportKind
pickAcceptfn
parseChallenge, parseReceipt, parseSettleResponsefn
parseSignatureHeader, parseExactPaymentHeaderfn
buildChallengeHeader, buildSignatureHeader, buildExactSignatureHeader, buildReceiptHeaderfn
HEADER_REQUIRED, HEADER_SIGNATURE, HEADER_RESPONSE, HEADER_SIGNATURE_V1, HEADER_RESPONSE_V1const
Caip2, AssetId, AddressIdtype
VerifyResult, VerifyErrorCodetype
X402AcceptEntry, X402ExactAcceptEntry, X402AnyAccept, X402Challengetype
X402PaymentSignature, X402Receipt, X402ResourceObject, SettleOutcometype
ExactAuthorizationWire, ExactPaymentPayload, ParsedExactPaymenttype

See Wire codecs and VerifyErrorCode.

The standard x402 exact scheme at the codec tier. For the high-level paths use PipRailClient({ schemes: ['exact'] }) (buyer) or createPaymentGate({ exact }) (seller) — these exports are for hand-rolled clients, v1 servers, and custom flows.

ExportKindNote
parseExactRequirements, chainIdForExactNetwork, encodeXPaymentHeaderfn
readExactDomain, eip3009Abifn / constreads/uses a token’s true on-chain EIP-712 domain
EXACT_NETWORK_SLUGS, EIP3009_TYPESconst
buildExactAuthorizationfnDeprecated — trusts the server-supplied domain
ExactAccept, ExactAuthorization, BuildExactParamstype

Advanced: exact facilitator (Mode B) — facilitator.js

Section titled “Advanced: exact facilitator (Mode B) — facilitator.js”

The Mode-B facilitator path (createPaymentGate({ exact: { settle: { facilitator } } })) delegates verify + settle to a third-party facilitator you choose. PipRail hosts nothing.

ExportKindNote
settleViaFacilitatorfnRun the two-POST verify→settle contract against a facilitator URL.
FacilitatorConfigtypeThe facilitator’s base url + optional authHeaders provider.
FacilitatorPaymentRequirementstypeThe trusted exact requirements posted to the facilitator.
SettleViaFacilitatorInputtypeFull input to settleViaFacilitator (config + payload + receipt fields).

See the exact rail (seller) page for how to wire it.

See Low-level exact, exact rail (seller), and exact (buyer).

Bring your own chain family. registerDriver adds a family that implements the PaymentDriver contract; the rest are the contract’s types.

ExportKind
registerDriverfn
PaymentDriver, ChainFamilytype
ResolvedNetwork, ResolveOptions, ResolvedToken, CostEstimatetype
WalletHandle, WalletBalance, DiscoverySigner, ConfirmInfotype
RecipientReasontype
EvmToken, SolanaToken, TonToken, StellarToken, XrplTokentype
TronToken, NearToken, SuiToken, AptosToken, AlgorandTokentype

See Driver SPI and PaymentDriver architecture.