---
title: "Install and initialize"
description: "Install the TypeScript SDK and create a server-side client."
---

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

# Install and initialize

Keep the SDK and API key in trusted server code. Do not put an API key in browser or mobile code.

## Install the package

```sh
npm install @affinity-health/sdk
pnpm add @affinity-health/sdk
yarn add @affinity-health/sdk
bun add @affinity-health/sdk
```

These examples use SDK `1.15.0` and its `Affinity` client.

The SDK supports Bun, Node.js 20 or later, AWS Lambda, and standard worker runtimes.

## Create the client

Read the API key from the process environment. Create one client and reuse it.

```typescript
import { Affinity } from "@affinity-health/sdk";

const apiKey = process.env.AFFINITY_API_KEY;
if (!apiKey) throw new Error("Set AFFINITY_API_KEY");

export const affinity = new Affinity(apiKey);
```

Use an `sk_test_...` key during development. Test mode accepts only synthetic clinical data.

## Confirm access

Read the API key access before you make other requests.

```typescript
const access = await affinity.apiKeys.getAccess();

if (access.livemode) {
  throw new Error("Use a Test API key for this procedure");
}
```

The response identifies the current mode and permitted operations.

## Next step

[Configure the client](/guides/reference/sdks/typescript-configuration) or [make your first resource request](/guides/reference/sdks/typescript-requests).

Source: https://docs-staging.affinityrx.com/guides/reference/sdks/typescript-setup/index.mdx
