npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

langlite

v0.1.0

Published

A lightweight, type-safe TypeScript SDK for observability and tracing in LLM and AI-powered applications. Batch, export, and analyze traces, generations, spans, events, and scores with ease in Node.js or browser environments.

Downloads

17

Readme

langlite

langlite is a lightweight, type-safe TypeScript SDK for observability and tracing in LLM and AI-powered applications. It helps you batch, export, and analyze traces, generations, spans, events, and scores efficiently from both Node.js and browser environments.


Features

  • Type-safe API – Designed with strict TypeScript for maximum safety and developer experience.
  • Trace & Span Support – Instrument your application with end-to-end traces and granular spans.
  • Specialized LLM Generation Tracking – Capture prompts, completions, model info, token usage, and metadata.
  • Event & Score Logging – Add point-in-time events and qualitative feedback.
  • Batching & Non-blocking – Data is queued and sent in efficient batches, never blocking your app.
  • Isomorphic – Works seamlessly in Node.js and all modern browsers.
  • Graceful Shutdown – Ensures all queued data is sent before exit.
  • Lightweight – Minimal dependencies and fast.

Installation

npm install langlite
# or
yarn add langlite
# or
pnpm add langlite

Quick Start

import { Langlite } from 'langlite';

const client = new Langlite({
  publicKey: 'your-public-key',
  secretKey: 'your-secret-key',
  host: 'https://your-observability-api.com', // Optional, defaults to official endpoint
});

// Start a trace for an operation
const trace = client.startTrace({ name: 'user-api-request' });

// Add a generation (LLM call) to the trace
const generation = trace.addGeneration({
  name: 'summarize',
  model: 'gpt-4o',
  input: 'Summarize this text...',
  output: 'This is the summary.',
  usage: { promptTokens: 20, completionTokens: 15 },
  metadata: { temperature: 0.7 },
});

// Add a span to the trace
trace.addSpan({ name: 'db-query', metadata: { query: 'SELECT ...' } });

// Log an event
trace.logEvent({ message: 'User authenticated', timestamp: Date.now() });

// Submit a score to the generation
generation.submitScore({ value: 1, reason: 'Accurate summary' });

// Mark the trace as finished (sends to queue)
trace.finish();

// Optional: ensure all data is sent before app exit
await client.shutdown();

Example Usage

See the examples/ directory for more use cases:

  • simple-generation.ts – Basic LLM generation trace
  • chat-with-metadata.ts – Logging chat data with user/session info
  • trace-with-spans.ts – Tracing multi-step processes

API Overview

Langlite Client

| Method | Description | | -------------- | --------------------------------------- | | startTrace() | Begin a new trace for an operation | | flush() | Manually flush the event queue | | shutdown() | Flush and shutdown gracefully (on exit) |

Trace Object

| Method | Description | | ----------------- | ------------------------------------------ | | addGeneration() | Log an LLM call (prompt, output, model, …) | | addSpan() | Add a work unit (step) to the trace | | logEvent() | Add an event/breadcrumb to the trace | | submitScore() | Attach qualitative feedback to the trace | | finish() | Finalize the trace and queue for export |

Generation Object

| Method | Description | | --------------- | --------------------------------------------- | | submitScore() | Attach qualitative feedback to the generation |

Time Fields

All time fields (startTime, endTime, timestamp, etc.) must be provided as Unix timestamps.

Example usage:

const span = trace.addSpan({
  name: 'work',
  startTime: Date.now(),
  endTime: Date.now() + 500,
});

TypeScript Types

All public APIs are strictly typed. See src/types.ts for details.


Configuration

| Option | Type | Description | | --------------- | ------ | ---------------------------------------------- | | publicKey | string | (Optional) Public API key | | secretKey | string | Secret API key (required for write operations) | | host | string | API endpoint (optional, defaults to official) | | flushInterval | number | Flush queue every X ms (default: 10,000) |


Development

First time setup:

# Install dependencies
npm install

# Build all packages (required for TypeScript resolution)
npm run build

Development workflow:

  • Formatting: Uses Prettier for code style.
  • Type-checking: Uses TypeScript (tsc) for type safety.
  • Build: Uses tsup for fast, modern bundling and dual ESM/CJS output.
  • Linting: Plans to migrate to Biome for unified linting and formatting in the future.
  • Test: vitest for fast, type-safe unit tests.
# Format code
npm run format

# Type-check code
npm run lint

# Build (with tsup)
npm run build

# Test
npm run test

# Watch mode for tests
npm run dev

License

MIT


Contributing

Contributions and ideas are welcome! Please open an issue or PR.


Links