Skip to main content
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!,
  project: "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();

Full tutorial & reference — in progress

The full TypeScript SDK walkthrough, configuration guide, and API reference are being written as part of TRU-92. Until then, the Python tutorial is the most complete guide — the TypeScript SDK mirrors the Python API shape closely.

README

Current usage docs in the SDK repo.

Python tutorial

Mirrored API — mentally substitute snake_casecamelCase and context managers → async callbacks.

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.