Observability

Langfuse + Meridian

Auto-instrument your OpenAI client with Langfuse in one line. Every completion, token count, latency, and cost is traced automatically — no manual span creation required.

lib/langfuse.ts
// lib/langfuse.ts
import { Langfuse } from 'langfuse';
import OpenAI from 'openai';

const langfuse = new Langfuse({
  publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
  secretKey: process.env.LANGFUSE_SECRET_KEY!,
  baseUrl: process.env.LANGFUSE_HOST ?? 'https://cloud.langfuse.com',
});

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });

// Wrap the client — all calls auto-traced
export const ai = langfuse.wrapOpenAI(openai, {
  generationName: 'meridian-chat',
  metadata: { service: 'meridian' },
});

// Usage in a route handler:
// const completion = await ai.chat.completions.create({
//   model: 'gpt-4o',
//   messages: [{ role: 'user', content: input }],
// });

One-liner

Wrap your OpenAI client once. Every call is traced with zero boilerplate.

📊

Full visibility

Tokens, latency, cost, and model per request — all in the Langfuse dashboard.

🔗

Traces + Sessions

Group requests by user session. Debug slow chains and spot regressions instantly.