# Setup

Install `@addresszen/sdk` and create a client with your API key. The SDK runs in browsers and Node.js 22 or later and uses the runtime's native `fetch`.

**npm**

```bash
npm install @addresszen/sdk
```

**pnpm**

```bash
pnpm add @addresszen/sdk
```

**Bun**

```bash
bun add @addresszen/sdk
```

client.tsts

```ts
import { createZenClient } from "@addresszen/sdk";

const client = createZenClient({ apiKey: "ak_test" });
```

## Client options

| Option      | Type           | Purpose                                                                                   |
| ----------- | -------------- | ----------------------------------------------------------------------------------------- |
| `apiKey`    | `string`       | API key, sent as `api_key`. Needed for every operation except key operations              |
| `userToken` | `string`       | Management Key for account operations. Keep it on your server                             |
| `baseUrl`   | `string`       | Defaults to `https://api.addresszen.com/v1`                                               |
| `fetch`     | `typeof fetch` | Custom fetch implementation for tests or request handling                                 |
| `headers`   | `HeadersInit`  | Headers sent with every request, such as `User-Agent`. Per-call `headers` take precedence |
| `timeoutMs` | `number`       | Milliseconds before each request rejects with `TimeoutError`. No timeout by default       |

## Request timeout

Set `timeoutMs` on the client. A request that runs longer rejects with a `DOMException` named `TimeoutError`, as described in [error handling](/docs/sdks/typescript/errors.md#timeout-or-cancellation). A per-call `signal` can still cancel the request sooner.

timeout.tsts

```ts
const client = createZenClient({ apiKey: "ak_test", timeoutMs: 30_000 });
```

To time out a single call, pass `signal: AbortSignal.timeout(5_000)` to the operation instead.

## Default headers

Pass `headers` to the client to send them with every request, for example a `User-Agent` that identifies your app. Headers passed to an operation take precedence. Browsers may drop a custom `User-Agent`, so set it on server-side clients.

headers.tsts

```ts
const client = createZenClient({
  apiKey: "ak_test",
  headers: { "User-Agent": "my-app/1.0" },
});
```

## Management Key

Set `userToken` to a Management Key only to call the account operations that need it: key details, usage and logs, licensees and configs. Each [operation page](/docs/sdks/typescript/endpoints.md) says whether it needs one. A Management Key controls your account, so keep it on your server and never use it in a client that runs in the browser. The SDK sends it in the `Authorization` header, and only to operations that accept it.

A client used only for key operations needs no `apiKey`:

management.tsts

```ts
const client = createZenClient({ userToken: process.env.MANAGEMENT_KEY });
```

## Dependencies

The root package has no runtime dependencies. Install `@tanstack/react-query` or `@tanstack/preact-query` only when using the matching [adapter](/docs/sdks/typescript/react.md#tanstack-query).

## Module formats

TypeScript consumers can use either NodeNext or bundler module resolution. CommonJS consumers can use `require("@addresszen/sdk")`. Use ESM imports for tree-shaking.
