File size: 624 Bytes
34d6b36 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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;
|