> ## 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

> The @trulayer/sdk npm package — zero runtime dependencies, works anywhere Node.js fetch does.

The TypeScript SDK (`@trulayer/sdk` on npm) has zero runtime dependencies and works in Node.js 18+, Vercel Edge, Cloudflare Workers, and Bun. A browser build is available but we recommend relaying through your server for API-key safety.

## Install

```bash theme={null}
npm install @trulayer/sdk
# or
pnpm add @trulayer/sdk
```

## Minimal usage

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

const tl = new TruLayer({
  apiKey: process.env.TRULAYER_API_KEY!,
  projectName: "my-app",
});

const openai = instrumentOpenAI(new OpenAI(), tl);

await tl.trace("answer_question", async (trace) => {
  trace.setInput({ question });
  const response = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: question }],
  });
  trace.setOutput(response.choices[0].message.content);
});

await tl.flush();
```

## Next steps

<CardGroup cols={2}>
  <Card title="Tutorial" icon="graduation-cap" href="/sdks/typescript/tutorial">
    End-to-end walkthrough — instrument a RAG pipeline with traces, spans, and evals.
  </Card>

  <Card title="Reference" icon="book" href="/sdks/typescript/reference">
    Full type signatures for every exported symbol.
  </Card>

  <Card title="Testing helpers" icon="flask" href="/sdks/typescript/testing">
    In-memory sender and fluent assertions for unit tests.
  </Card>

  <Card title="Failure behavior" icon="shield" href="/sdks/typescript/fail-mode">
    Default drop+warn semantics and the opt-in block mode.
  </Card>
</CardGroup>

## Runtime support

| Runtime            | Supported             | Notes                                                |
| ------------------ | --------------------- | ---------------------------------------------------- |
| Node.js 18+        | Yes                   | Uses native `fetch`                                  |
| Vercel Edge        | Yes                   |                                                      |
| Cloudflare Workers | Yes                   |                                                      |
| Bun                | Yes                   |                                                      |
| Deno               | Yes                   | Import from `npm:@trulayer/sdk`                      |
| Browser            | Yes (not recommended) | Exposes your API key — relay via your server instead |

## Build output

The package ships both ESM (`index.mjs`) and CJS (`index.js`) entry points, plus `.d.ts` types. Imports work identically in modern toolchains.
