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

# TypeScript SDK configuration

> Every option you can pass to the TruLayer constructor.

## Options

| Option          | Type                          | Default                   | Description                                           |
| --------------- | ----------------------------- | ------------------------- | ----------------------------------------------------- |
| `apiKey`        | `string`                      | required                  | TruLayer API key (`tl_...`)                           |
| `projectName`   | `string`                      | required                  | Human-readable project name                           |
| `projectId`     | `string`                      | —                         | Deprecated alias for `projectName`. Removed in 0.3.x. |
| `environment`   | `string`                      | `"production"`            | Filter label                                          |
| `endpoint`      | `string`                      | `https://api.trulayer.ai` | Override for self-hosted                              |
| `batchSize`     | `number`                      | `50`                      | Spans per flush                                       |
| `flushInterval` | `number`                      | `2000`                    | ms between flushes                                    |
| `timeout`       | `number`                      | `5000`                    | HTTP timeout (ms)                                     |
| `sampleRate`    | `number \| () => boolean`     | `1.0`                     | Fraction of traces to send                            |
| `redact`        | `(value: unknown) => unknown` | `undefined`               | Redact inputs/outputs before ingest                   |
| `relayUrl`      | `string`                      | `undefined`               | Server-side relay URL for browser builds              |
| `debug`         | `boolean`                     | `false`                   | Log payloads locally                                  |

## Example — production

```typescript theme={null}
import { TruLayer } from "@trulayer/sdk";

export const tl = new TruLayer({
  apiKey: process.env.TRULAYER_API_KEY!,
  projectName: "prod",
  environment: "production",
  batchSize: 50,
  flushInterval: 2000,
  redact: (value) => {
    if (typeof value !== "string") return value;
    return value
      .replace(/\b[\w.+-]+@[\w.-]+\.\w{2,}\b/gi, "[email]")
      .replace(/\b\d{13,16}\b/g, "[cc]");
  },
});
```

## Example — offline/test

```typescript theme={null}
const tl = new TruLayer({
  apiKey: "tl_local",
  projectName: "test",
  debug: true,
});
```

Or mock server:

```typescript theme={null}
const tl = new TruLayer({
  apiKey: "tl_local",
  projectName: "test",
  endpoint: "http://localhost:4010",
});
```

## Sampling

Static fraction:

```typescript theme={null}
new TruLayer({ ..., sampleRate: 0.1 }); // 10%
```

Dynamic (evaluated per trace):

```typescript theme={null}
new TruLayer({
  ...,
  sampleRate: () => Math.random() < 0.1,
});
```

Sampling is applied at trace creation — a sampled trace always includes every one of its spans.

## Flush & shutdown

```typescript theme={null}
await tl.flush();     // ship buffered traces, resolve when done
await tl.shutdown();  // flush + stop background work
```

Call `flush()` before returning a response in serverless/Edge functions. Call `shutdown()` on `SIGTERM` in long-lived servers.
