Langfuse is the open-source LLM engineering platform: tracing & evaluation for LLM and agent applications, prompt management, datasets & experiments, and evaluation (scores). This package provides the LangfuseClient β prompt management (langfuse.prompt), datasets (langfuse.dataset), experiments (langfuse.experiment), scores (langfuse.score), media (langfuse.media), and the full generated REST API client (langfuse.api). Tracing is intentionally separate: use @langfuse/tracing + @langfuse/otel for that.
This is the current SDK generation (@langfuse/* scoped packages). The unscoped langfuse npm package is the legacy v3 SDK β for new integrations use the @langfuse/* packages. Migration guides: v3 β v4, v4 β v5.
npm install @langfuse/client
LANGFUSE_PUBLIC_KEY="pk-lf-..."
LANGFUSE_SECRET_KEY="sk-lf-..."
LANGFUSE_BASE_URL="https://cloud.langfuse.com" # πͺπΊ EU region. πΊπΈ US: https://us.cloud.langfuse.com
import { LangfuseClient } from "@langfuse/client";
const langfuse = new LangfuseClient(); // reads env vars
// Prompt management
const prompt = await langfuse.prompt.get("my-prompt");
const compiled = prompt.compile({ topic: "chickens" });
// Scores (evaluation / user feedback)
langfuse.score.create({ traceId: "trace-id", name: "quality", value: 0.9 });
await langfuse.flush(); // flush queued scores (tracing spans flush separately)
// Datasets & experiments
const dataset = await langfuse.dataset.get("my-dataset");
const result = await dataset.runExperiment({
name: "My experiment",
task: async ({ input }) => myModel.generate(input),
evaluators: [
async ({ output, expectedOutput }) => ({
name: "exact_match",
value: output === expectedOutput ? 1 : 0,
}),
],
});
console.log(await result.format());
// Full REST API
const trace = await langfuse.api.trace.get("trace-id");
| Package | NPM | Description | Environments |
|---|---|---|---|
| @langfuse/tracing | OpenTelemetry-based tracing instrumentation | Node.js 20+ | |
| @langfuse/otel | LangfuseSpanProcessor to export OpenTelemetry spans to Langfuse |
Node.js 20+ | |
| @langfuse/client | Prompt management, datasets, experiments, scores, full REST API | Universal JS | |
| @langfuse/openai | observeOpenAI wrapper for tracing the OpenAI SDK |
Universal JS | |
| @langfuse/langchain | CallbackHandler for LangChain / LangGraph tracing |
Universal JS | |
| @langfuse/vercel-ai-sdk | Telemetry integration for Vercel AI SDK v7 | Universal JS | |
| @langfuse/browser | Browser score ingestion with public-key auth | Browser | |
| @langfuse/core | Shared core: generated API client, logger, utilities | Universal JS |