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
fetch). You can also inject
your own fetch implementation through the constructor.
Quick start
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 settles402 Payment Required responses using Coinbase’s x402 packages and retries the
call with the resulting proof. Your code just awaits the result.
Alternative auth modes
For dashboard-managed access, pass a connect token or an explicit authorization header instead of a private key:x-payment proof from your own payer flow, you can attach
it directly with the xPayment option.
Constructor options
| Option | Purpose |
|---|---|
baseUrl | Gateway base URL. Defaults to https://gateway.apiosk.com. |
privateKey | Base wallet key for automatic x402 settlement. |
connectToken | Dashboard connect token for managed-wallet access. |
authorization | Explicit Authorization header value. |
xPayment | A pre-built x-payment proof to attach as-is. |
connectHeaderName | Override the connect-token header name. Defaults to x-apiosk-connect-token. |
headers | Extra headers merged into every request. |
fetch | Custom fetch implementation (for non-global-fetch runtimes). |
API surface
| Method | Maps to |
|---|---|
listApis(params) | GET /v1/apis — search and paginate listings. |
getApi(slug) | GET /v1/apis/:slug — inspect one listing. |
getMetadata(slug) | GET /:slug/metadata — agent-native metadata. |
execute(slug, input, options) | POST /:slug/execute — default operation. |
executeOperation(slug, operation, input, options) | POST /:slug/execute with an explicit operation. |
passthrough(slug, path, options) | /:slug/*path — provider-specific shape. |
Errors
The SDK throws typed errors so callers can branch on payment state:| Error | When |
|---|---|
ApioskError | Base error class for all SDK failures. |
ApioskHttpError | Any non-2xx gateway response. Carries the response context. |
ApioskPaymentRequiredError | A 402 that could not be settled automatically. |
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.
Related packages
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 appsapiosk(Python) — server-side intent creation, webhook verification, and status polling
Related links
- Consumer guide: /guides/consumers
- Execute contract: /guides/execute
- Payment options: /guides/payment-options
- Errors and retries: /guides/errors-and-retries