TypeScript SDK

The Lucidic AI TypeScript SDK provides full observability for your AI applications built with TypeScript/JavaScript. It offers automatic instrumentation for OpenAI and Anthropic, with the same powerful features as our Python SDK. It also exposes async-safe session context helpers for concurrent backends.

Installation

Install the SDK via npm:
npm install lucidicai
Or using yarn:
yarn add lucidicai

Quick Start

import * as lai from 'lucidicai';
import OpenAI from 'openai';

// Initialize with manual instrumentation (ESM-friendly)
await lai.init({
  sessionName: 'My AI Assistant',
  instrumentModules: { OpenAI },
});

// Your LLM calls are now automatically tracked!
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
const response = await client.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Hello!' }]
});

Key Features

Automatic Instrumentation

  • Automatic tracking for OpenAI and Anthropic
  • Auto event creation for every LLM call
  • Auto step creation when no active step exists
  • Flush spans on exit (even when autoEnd is disabled)

Full TypeScript Support

  • Comprehensive type definitions
  • Async/await support throughout
  • Type-safe configuration

Advanced Features

  • Multimodal support (text and images)
  • Cost tracking with built-in pricing data
  • Data masking for sensitive information
  • Mass simulations for testing at scale
  • Prompt management from the platform

TypeScript vs Python SDK

FeatureTypeScript SDKPython SDK
OpenAI Integration✅ Full support✅ Full support
Anthropic Integration✅ With streaming limitation✅ Full support
LangChain Integration✅ Available (OpenTelemetry)✅ Supported
PydanticAI Integration❌ Not applicable✅ Supported
Auto Instrumentation✅ OpenTelemetry✅ OpenTelemetry
Multimodal Support✅ Text & Images✅ Text & Images
Mass Simulations✅ Supported✅ Supported
Prompt DB✅ Supported✅ Supported
Data Masking✅ Supported✅ Supported

Important: Import Order

For automatic tracking to work, use one of these patterns:
// ESM/Next.js: import first, pass module references
import OpenAI from 'openai';
await lai.init({ instrumentModules: { OpenAI } });

// CommonJS (dynamic import):
const { default: OpenAI } = await import('openai');
await lai.init({ instrumentModules: { OpenAI } });

Next Steps