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

# Usage patterns

> Practical Barekey SDK and CLI patterns for shared clients, local development, production auth, and type-safe workflows.

## Shared server client

Create one shared server client module:

```ts theme={null}
import { BarekeyClient } from "@barekey/sdk/server";

export const barekey = new BarekeyClient();
```

This works especially well when:

* `barekey.json` is committed
* developers use `barekey auth login`
* production sets `BAREKEY_ACCESS_TOKEN`

## Production auth pattern

Use a real deployment secret:

```bash theme={null}
BAREKEY_ACCESS_TOKEN=bk_at_...
```

Then:

```ts theme={null}
const client = new BarekeyClient({
  organization: "acme",
  project: "api",
  environment: "production",
});
```

This avoids depending on a local CLI session in production.

## Local developer pattern

Commit `barekey.json` and have every developer run:

```bash theme={null}
barekey auth login
barekey typegen
```

That gives you:

* CLI commands without repeating flags
* SDK reads without manually wiring tokens
* generated types in the local editor

## Pull-file pattern

If a tool only understands dotenv files:

```bash theme={null}
barekey env pull --out .env.local
```

Re-run it whenever upstream values change.

## Batch-read pattern

Read a group of startup values together:

```ts theme={null}
const [databaseUrl, redisUrl, stripeKey] = await barekey.get([
  "DATABASE_URL",
  "REDIS_URL",
  "STRIPE_SECRET_KEY",
] as const);
```

## Experiment pattern

Use deterministic `ab_roll` reads:

```ts theme={null}
const variant = await barekey.get("CHECKOUT_FLOW", {
  seed: user.id,
  key: "checkout-v2",
});
```

## Public-variable pattern

Use the public client for browser-safe reads:

```ts theme={null}
import { PublicBarekeyClient } from "@barekey/sdk/public";

const publicBarekey = new PublicBarekeyClient({
  organization: "acme",
  project: "web",
  environment: "production",
});
```
