@rail402.dev/sdk exports, its exact signature, and the shape it returns.
The SDK is the umbrella package described in Packages. It re-exports the buyer helpers, the seller helpers, and the error registry. Install it once:
Amounts in the SDK are atomic units passed as a string, never a number, bigint, or float. USDC has 7 decimals, so
"100000" is 0.01 USDC and "10000000" is 1.0000000. The CLI uses decimals instead: see CLI reference.The config object
Every buyer function takes aconfig object as its first argument.
Buyer functions
Also available from@rail402.dev/agent-helpers and from the subpath @rail402.dev/sdk/buyer.
The Result type
Every buyer function returns aResult. Branch on ok before touching data or error.
payAndFetch and discoverAndPay include the resource response as data.body alongside settlement information. On failure, error carries a machine-readable error code, a non-null reason, and a retryable flag.
Seller functions
Also available from@rail402.dev/seller-helpers and from the subpath @rail402.dev/sdk/seller.
The return value of
describeEndpoint is branded, so wrapping it in another discovery call is a compile error rather than a silent double-nesting.
Subpath exports
Import only the side you need.Next steps
Buyer quickstart
Discover and pay a resource with these functions.
Seller quickstart
Add discovery metadata to a paywall route.
Error registry
The codes that come back in
result.error.Packages
How the SDK relates to the building blocks.
When it fails
Every failing call returns{ ok: false, error } with a machine-readable code and a non-null reason. See Error registry and Troubleshooting.