Skip to main content

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.

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

npm install @trulayer/sdk
# or
pnpm add @trulayer/sdk

Minimal usage

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

Tutorial

End-to-end walkthrough — instrument a RAG pipeline with traces, spans, and evals.

Reference

Full type signatures for every exported symbol.

Testing helpers

In-memory sender and fluent assertions for unit tests.

Failure behavior

Default drop+warn semantics and the opt-in block mode.

Runtime support

RuntimeSupportedNotes
Node.js 18+YesUses native fetch
Vercel EdgeYes
Cloudflare WorkersYes
BunYes
DenoYesImport from npm:@trulayer/sdk
BrowserYes (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.