Skip to main content
By the end of this page you will know every function @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 a config object as its first argument.

Buyer functions

Also available from @rail402.dev/agent-helpers and from the subpath @rail402.dev/sdk/buyer.
maxAmount is required on every paying call. It is the spend cap, enforced on the request that is actually paid, immediately before signing. A seller cannot quote cheap and then charge above the cap. maxAmount and maxPrice are atomic-unit strings.

The Result type

Every buyer function returns a Result. Branch on ok before touching data or error.
On success, 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.
describeEndpoint takes params, not queryParams, and has no top-level description. The resource description is a separate field on the paywall route, next to extensions. See the Seller quickstart for the full route shape.
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.