> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sleetpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> @sleetpay/sdk: a typed, dependency-free client for Node, Bun, Deno and the edge.

`@sleetpay/sdk` is a typed, dependency-free client. It uses `fetch` and Web Crypto, so it runs on Node 18+, Bun, Deno and edge runtimes.

```bash theme={null}
npm install @sleetpay/sdk
```

```ts theme={null}
import { SleetPay } from "@sleetpay/sdk";

const sleetpay = new SleetPay({ apiKey: process.env.SLEETPAY_API_KEY }); // server-side only
```

| Option | Default | Notes |
| - | - | - |
| `apiKey` | none | Not needed for `licenses.*` |
| `baseUrl` | `https://app.sleetpay.com` | Set for a self-hosted deployment |
| `maxRetries` | `2` | Retries 429 for every method; 502, 503, 504 and network errors for GETs |
| `timeoutMs` | `30000` | Per request |
| `fetch` | global `fetch` | Inject your own |

## Resources

| Namespace | Methods |
| - | - |
| `checkouts` | `create`, `get` |
| `products` | `list`, `iterate` |
| `customers` | `create`, `get`, `getByExternalId`, `list`, `iterate`, `state`, `stateByExternalId` |
| `orders` | `list`, `iterate` |
| `subscriptions` | `list`, `iterate`, `get`, `cancelAtPeriodEnd`, `pause`, `resume`, `changeSeats`, `revoke` |
| `seats` | `assign`, `revoke`, `list` |
| `customerSessions` | `create` |
| `events` | `ingest` |
| `meters` | `list` |
| `credits` | `balance`, `transfer` |
| `licenseKeys` | `list` |
| `licenses` | `validate`, `activate`, `deactivate` (no API key) |

For an endpoint not wrapped yet: `sleetpay.request("GET", "/api/v1/...", { query })`.

## Pagination

```ts theme={null}
for await (const order of sleetpay.orders.iterate({ customerId })) console.log(order.id);
```

## Webhooks

```ts theme={null}
import { constructEvent, verifyWebhook } from "@sleetpay/sdk";

const event = await constructEvent(secret, rawBody, req.headers); // verify + parse, or throw
const ok = await verifyWebhook(secret, rawBody, req.headers);      // boolean
```

`req.headers` can be a Fetch `Headers` or a Node headers object. Pass the raw body.

## Errors

```ts theme={null}
import { SleetPayError } from "@sleetpay/sdk";

try {
  await sleetpay.checkouts.create({ productId });
} catch (e) {
  if (e instanceof SleetPayError && e.isRateLimited) console.log("retry after", e.retryAfter);
  else throw e;
}
```

## Migrating from `@sleet/sdk`

`Sleet` -> `SleetPay`, `SleetError` -> `SleetPayError`, `baseUrl` is now optional, and `verifyWebhook(secret, body, headers)` takes the headers object directly.

Source and changelog: [github.com/sleetpay/sleetpay-sdk](https://github.com/sleetpay/sleetpay-sdk/tree/main/packages/typescript).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.