Skip to main content

JavaScript SDK

@apiosk/sdk is the official JavaScript client for the Apiosk gateway. It wraps discovery, the 402 Payment Required loop, and execution behind a small typed client so application code does not have to assemble the raw HTTP flow by hand. Use it when your software runs in a Node backend and you want gateway calls, typed payment errors, and optional automatic on-chain settlement in one package.

Install

Requires Node 20 or newer (the SDK uses the global fetch). You can also inject your own fetch implementation through the constructor.

Quick start

Discovery calls (listApis, getApi, getMetadata) are public and need no credentials. execute only needs credentials when the route is paid.

Auto-pay with x402

If you provide a Base wallet private key, the client automatically settles 402 Payment Required responses using Coinbase’s x402 packages and retries the call with the resulting proof. Your code just awaits the result.
The private key stays in your process and signs payments locally, it is never sent to the gateway.
Paid routes now offer multiple settlement networks in their 402 (see Multi-chain Settlement), but every 402 always includes a Base entry, so a Base private key keeps working unchanged: the client settles against the Base entry.

Alternative auth modes

For managed access, pass a connect token or an explicit authorization header instead of a private key:
Connect tokens are still mintable and existing managed (custodial) wallets still settle calls, but creating a new managed wallet is currently unavailable: that path returns custodial_wallet_creation_unavailable because the legacy dashboard service behind wallet key derivation was retired. Use a private key you control, or a wallet that already exists.
If you already have an x-payment proof from your own payer flow, you can attach it directly with the xPayment option.

Constructor options

API surface

Errors

The SDK throws typed errors so callers can branch on payment state: ApioskPaymentRequiredError includes the parsed 402 body, so a caller that is not using the built-in EVM flow can inspect the accepted payment rails and attach its own proof.
The gateway client is intentionally separate from the merchant checkout UI:
  • @apiosk/checkout-core: shared checkout schema and intent helpers
  • @apiosk/checkout-web: plain HTML and custom-element checkout
  • @apiosk/checkout-react: React and Next.js apps
  • @apiosk/checkout-vue: Vue apps
  • apiosk (Python), server-side intent creation, webhook verification, and status polling