import { LangfuseClient } from "@langfuse/client"; // Ensure this is never imported on the client if (typeof window !== "undefined") { throw new Error("`langfuse` must only be used on the server side."); } declare global { // eslint-disable-next-line no-var var __langfuse__: LangfuseClient | undefined; } export const langfuse = globalThis.__langfuse__ ?? new LangfuseClient({ publicKey: process.env.LANGFUSE_PUBLIC_KEY, secretKey: process.env.LANGFUSE_SECRET_KEY, baseUrl: process.env.LANGFUSE_BASE_URL || "https://cloud.langfuse.com", }); if (!globalThis.__langfuse__) globalThis.__langfuse__ = langfuse;