🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ee): license key verification (#2313)
Marc Klingena1db67580dba
diff --git a/web/src/components/LangfuseLogo.tsx b/web/src/components/LangfuseLogo.tsxindex 8e625a4a12..1be835ecf9 100644--- a/web/src/components/LangfuseLogo.tsx+++ b/web/src/components/LangfuseLogo.tsx@@ -21,6 +21,7 @@ import { ArrowUp } from "lucide-react";import { api } from "@/src/utils/api";import { Button } from "@/src/components/ui/button";import Link from "next/link";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";const VersionLabel = ({ className }: { className?: string }) => {const checkUpdate = api.public.checkUpdate.useQuery(undefined, {@@ -30,6 +31,8 @@ const VersionLabel = ({ className }: { className?: string }) => {enabled: !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION, // do not check for updates on Langfuse CloudonError: (error) => console.error("checkUpdate error", error), // do not render default error message});+ const isEeVersion =+ useIsEeEnabled() && !Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);const hasUpdate =!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION &&@@ -66,7 +69,14 @@ const VersionLabel = ({ className }: { className?: string }) => {<DropdownMenuSeparator /></>) : null}-+ {isEeVersion && (+ <>+ <DropdownMenuLabel className="font-normal italic">+ Enterprise Edition+ </DropdownMenuLabel>+ <DropdownMenuSeparator />+ </>+ )}<DropdownMenuItem asChild><Linkhref="https://github.com/langfuse/langfuse/releases"diff --git a/web/src/components/layouts/layout.tsx b/web/src/components/layouts/layout.tsxindex 6df11c145a..bf0ae78c4f 100644--- a/web/src/components/layouts/layout.tsx+++ b/web/src/components/layouts/layout.tsx@@ -32,6 +32,7 @@ import useLocalStorage from "@/src/components/useLocalStorage";import { ProjectNavigation } from "@/src/components/projectNavigation";import DOMPurify from "dompurify";import { ThemeToggle } from "@/src/features/theming/ThemeToggle";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";const signOutUser = async () => {localStorage.clear();@@ -76,6 +77,7 @@ export default function Layout(props: PropsWithChildren) {session.data?.environment.enableExperimentalFeatures ?? false;const projectId = router.query.projectId as string | undefined;+ const isEeEnabled = useIsEeEnabled();const mapNavigation = (route: Route): NavigationItem | null => {// Project-level routes@@ -91,11 +93,14 @@ export default function Layout(props: PropsWithChildren) {)return null;- // cloud only+ // check ee or cloud requirementsif (- route.cloudOnly !== undefined &&- // the feature should be available in local development- route.cloudOnly !== (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined)+ route.requires !== undefined &&+ !(+ (route.requires === "cloud" &&+ Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION)) ||+ (route.requires === "cloud-or-ee" && isEeEnabled)+ ))return null;diff --git a/web/src/components/layouts/routes.ts b/web/src/components/layouts/routes.tsindex 0cc0924d2c..b9360ba04b 100644--- a/web/src/components/layouts/routes.ts+++ b/web/src/components/layouts/routes.ts@@ -24,7 +24,7 @@ export type Route = {children?: Array<Route>; // folderbottom?: boolean; // bottom of the sidebar, only for first level routesnewTab?: boolean; // open in new tab- cloudOnly?: boolean; // only available in cloud+ requires?: "cloud" | "cloud-or-ee"; // feature requires cloud or ee};export const ROUTES: Route[] = [@@ -62,25 +62,25 @@ export const ROUTES: Route[] = [{name: "Evaluation",icon: Lightbulb,- cloudOnly: true,+ requires: "cloud",label: "Beta",children: [{name: "Templates",pathname: `/project/[projectId]/evals/templates`,- cloudOnly: true,+ requires: "cloud",rbacScope: "evalTemplate:read",},{name: "Configs",pathname: `/project/[projectId]/evals/configs`,- cloudOnly: true,+ requires: "cloud",rbacScope: "evalJob:read",},{name: "Log",pathname: `/project/[projectId]/evals/log`,- cloudOnly: true,+ requires: "cloud",rbacScope: "evalJobExecution:read",},],@@ -100,7 +100,7 @@ export const ROUTES: Route[] = [name: "Playground",pathname: "/project/[projectId]/playground",icon: TerminalIcon,- cloudOnly: true,+ requires: "cloud-or-ee",label: "Beta",},{diff --git a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsxindex 39e8b84652..b424076f79 100644--- a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx+++ b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx@@ -7,7 +7,6 @@ import { createEmptyMessage } from "@/src/components/ChatMessages/utils/createEmimport { Button } from "@/src/components/ui/button";import usePlaygroundCache from "@/src/ee/features/playground/page/hooks/usePlaygroundCache";import { type PlaygroundCache } from "@/src/ee/features/playground/page/types";-import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { PromptType } from "@/src/features/prompts/server/utils/validation";import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";@@ -19,6 +18,7 @@ import {type UIModelParams,ZodModelConfig,} from "@langfuse/shared";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";type JumpToPlaygroundButtonProps = (| {@@ -42,6 +42,7 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (const projectId = useProjectIdFromURL();const { setPlaygroundCache } = usePlaygroundCache();const [capturedState, setCapturedState] = useState<PlaygroundCache>(null);+ const isEeEnabled = useIsEeEnabled();useEffect(() => {if (props.source === "prompt") {@@ -56,7 +57,7 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (setPlaygroundCache(capturedState);};- if (!getIsCloudEnvironment()) return null;+ if (!isEeEnabled) return null;return (<Buttondiff --git a/web/src/ee/features/playground/page/components/ResetPlaygroundButton.tsx b/web/src/ee/features/playground/page/components/ResetPlaygroundButton.tsxindex 81ae74b136..24de71db5f 100644--- a/web/src/ee/features/playground/page/components/ResetPlaygroundButton.tsx+++ b/web/src/ee/features/playground/page/components/ResetPlaygroundButton.tsx@@ -3,9 +3,10 @@ import { useRouter } from "next/router";import { Button } from "@/src/components/ui/button";import usePlaygroundCache from "@/src/ee/features/playground/page/hooks/usePlaygroundCache";-import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";export const ResetPlaygroundButton: React.FC = () => {+ const isEeEnabled = useIsEeEnabled();const router = useRouter();const { setPlaygroundCache } = usePlaygroundCache();@@ -15,7 +16,9 @@ export const ResetPlaygroundButton: React.FC = () => {router.reload();};- return getIsCloudEnvironment() ? (+ if (!isEeEnabled) return null;++ return (<Buttonvariant={"outline"}title="Reset playground state"@@ -24,5 +27,5 @@ export const ResetPlaygroundButton: React.FC = () => {<ListRestartIcon className="mr-1 h-5 w-5" /><span>Reset playground</span></Button>- ) : null;+ );};diff --git a/web/src/ee/features/playground/page/components/SaveToPromptButton.tsx b/web/src/ee/features/playground/page/components/SaveToPromptButton.tsxindex 2c63229656..25f8dc7999 100644--- a/web/src/ee/features/playground/page/components/SaveToPromptButton.tsx+++ b/web/src/ee/features/playground/page/components/SaveToPromptButton.tsx@@ -19,14 +19,15 @@ import {} from "@/src/components/ui/popover";import { usePlaygroundContext } from "@/src/ee/features/playground/page/context";import usePlaygroundCache from "@/src/ee/features/playground/page/hooks/usePlaygroundCache";-import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { PromptType } from "@/src/features/prompts/server/utils/validation";import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";import { api } from "@/src/utils/api";import { cn } from "@/src/utils/tailwind";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";export const SaveToPromptButton: React.FC = () => {+ const isEeEnabled = useIsEeEnabled();const [open, setOpen] = useState(false);const [selectedPromptId, setSelectedPromptId] = useState("");const { modelParams, messages, output, promptVariables } =@@ -83,7 +84,7 @@ export const SaveToPromptButton: React.FC = () => {);};- if (!getIsCloudEnvironment()) return null;+ if (!isEeEnabled) return null;return (<Popover>diff --git a/web/src/ee/features/playground/page/hooks/usePlaygroundCache.ts b/web/src/ee/features/playground/page/hooks/usePlaygroundCache.tsindex 14ec16ccb5..e0842d5749 100644--- a/web/src/ee/features/playground/page/hooks/usePlaygroundCache.ts+++ b/web/src/ee/features/playground/page/hooks/usePlaygroundCache.ts@@ -1,13 +1,13 @@import { useEffect, useState } from "react";-import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";import { type PlaygroundCache } from "../types";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";const playgroundCacheKey = "playgroundCache";export default function usePlaygroundCache() {const [cache, setCache] = useState<PlaygroundCache>(null);-+ const isEeEnabled = useIsEeEnabled();const setPlaygroundCache = (cache: PlaygroundCache) => {sessionStorage.setItem(playgroundCacheKey, JSON.stringify(cache));};@@ -24,7 +24,7 @@ export default function usePlaygroundCache() {}, []);return {- playgroundCache: getIsCloudEnvironment() ? cache : null,- setPlaygroundCache: getIsCloudEnvironment() ? setPlaygroundCache : () => {},+ playgroundCache: isEeEnabled ? cache : null,+ setPlaygroundCache: isEeEnabled ? setPlaygroundCache : () => {},};}diff --git a/web/src/ee/features/playground/page/index.tsx b/web/src/ee/features/playground/page/index.tsxindex f4051db336..c4d3d7179f 100644--- a/web/src/ee/features/playground/page/index.tsx+++ b/web/src/ee/features/playground/page/index.tsx@@ -3,10 +3,12 @@ import { ResetPlaygroundButton } from "@/src/ee/features/playground/page/componeimport { SaveToPromptButton } from "@/src/ee/features/playground/page/components/SaveToPromptButton";import { PlaygroundProvider } from "@/src/ee/features/playground/page/context";import Playground from "@/src/ee/features/playground/page/playground";-import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";export default function PlaygroundPage() {- return getIsCloudEnvironment() ? (+ const isEeAvailable = useIsEeEnabled();+ if (!isEeAvailable) return null;+ return (<PlaygroundProvider><div className="flex h-[95vh] flex-col"><Header@@ -28,5 +30,5 @@ export default function PlaygroundPage() {</div></div></PlaygroundProvider>- ) : null;+ );}diff --git a/web/src/ee/features/playground/server/authorizeRequest.ts b/web/src/ee/features/playground/server/authorizeRequest.tsindex 2aa006bde5..cc0a6aa6dd 100644--- a/web/src/ee/features/playground/server/authorizeRequest.ts+++ b/web/src/ee/features/playground/server/authorizeRequest.ts@@ -1,9 +1,9 @@import { getServerSession } from "next-auth";-import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";import { getAuthOptions } from "@/src/server/auth";import { isProjectMemberOrAdmin } from "@/src/server/utils/checkProjectMembershipOrAdmin";import { ApiError, ForbiddenError, UnauthorizedError } from "@langfuse/shared";+import { isEeEnabled } from "@/src/ee/utils/isEeEnabled";export type AuthorizeRequestResult = {userId: string;@@ -12,8 +12,10 @@ export type AuthorizeRequestResult = {export const authorizeRequestOrThrow = async (projectId: string,): Promise<AuthorizeRequestResult> => {- if (!getIsCloudEnvironment())- throw new ApiError("This endpoint is available in Langfuse cloud only.");+ if (!isEeEnabled)+ throw new ApiError(+ "LLM Playground is not yet available in the v2 open-source version.",+ );const authOptions = await getAuthOptions();const session = await getServerSession(authOptions);diff --git a/web/src/ee/utils/getIsCloudEnvironment.ts b/web/src/ee/utils/getIsCloudEnvironment.tsdeleted file mode 100644index 0ccbecb556..0000000000--- a/web/src/ee/utils/getIsCloudEnvironment.ts+++ /dev/null@@ -1,4 +0,0 @@-import { env } from "@/src/env.mjs";--export const getIsCloudEnvironment = () =>- Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);diff --git a/web/src/ee/utils/isEeEnabled.ts b/web/src/ee/utils/isEeEnabled.tsnew file mode 100644index 0000000000..86b34528f0--- /dev/null+++ b/web/src/ee/utils/isEeEnabled.ts@@ -0,0 +1,15 @@+import { env } from "@/src/env.mjs";++/**+ * Function to determine if the enterprise edition (EE) features are enabled. Do not use in frontend code as env variables are not available in the browser.+ *+ * This hook checks two conditions:+ * 1. If Langfuse is running on Langfuse Cloud+ * 2. If EE license is provided based on the user's session+ *+ * @returns {boolean}+ */++export const isEeEnabled =+ Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) ||+ Boolean(env.LANGFUSE_EE_LICENSE_KEY);diff --git a/web/src/ee/utils/useIsEeEnabled.ts b/web/src/ee/utils/useIsEeEnabled.tsnew file mode 100644index 0000000000..30ecba754a--- /dev/null+++ b/web/src/ee/utils/useIsEeEnabled.ts@@ -0,0 +1,20 @@+import { env } from "@/src/env.mjs";+import { useSession } from "next-auth/react";++/**+ * Custom React frontend hook to determine if the enterprise edition (EE) features are enabled.+ *+ * This hook checks two conditions:+ * 1. If Langfuse is running on Langfuse Cloud+ * 2. If EE license is provided based on the user's session+ *+ * @returns {boolean}+ */++export const useIsEeEnabled: () => boolean = () => {+ const session = useSession();+ return (+ Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) ||+ Boolean(session.data?.environment.eeEnabled)+ );+};diff --git a/web/src/env.mjs b/web/src/env.mjsindex 4f774ef374..a069725c16 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -102,6 +102,8 @@ export const env = createEnv({TURNSTILE_SECRET_KEY: z.string().optional(),// DB event logENABLE_EVENT_LOG: z.enum(["true", "false"]).optional().default("true"),+ // EE License+ LANGFUSE_EE_LICENSE_KEY: z.string().optional(),},/**@@ -216,6 +218,8 @@ export const env = createEnv({NEXT_PUBLIC_CRISP_WEBSITE_ID: process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID,// db event logENABLE_EVENT_LOG: process.env.ENABLE_EVENT_LOG,+ // EE License+ LANGFUSE_EE_LICENSE_KEY: process.env.LANGFUSE_EE_LICENSE_KEY,},// Skip validation in Docker builds// DOCKER_BUILD is set in Dockerfilediff --git a/web/src/features/llm-api-key/server/router.ts b/web/src/features/llm-api-key/server/router.tsindex 8ce90256fd..d6cbb5b856 100644--- a/web/src/features/llm-api-key/server/router.ts+++ b/web/src/features/llm-api-key/server/router.ts@@ -16,6 +16,7 @@ import {supportedModels,} from "@langfuse/shared";import { encrypt } from "@langfuse/shared/encryption";+import { isEeEnabled } from "@/src/ee/utils/isEeEnabled";export function getDisplaySecretKey(secretKey: string) {return "..." + secretKey.slice(-4);@@ -26,8 +27,10 @@ export const llmApiKeyRouter = createTRPCRouter({.input(CreateLlmApiKey).mutation(async ({ input, ctx }) => {try {- if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {- throw new Error("Evals available in cloud only");+ if (!isEeEnabled) {+ throw new Error(+ "LLM API keys are only required for model-based evaluations and the playground. Both are not yet available in the v2 open-source version.",+ );}throwIfNoAccess({session: ctx.session,@@ -67,8 +70,10 @@ export const llmApiKeyRouter = createTRPCRouter({}),).mutation(async ({ input, ctx }) => {- if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {- throw new Error("Evals available in cloud only");+ if (!isEeEnabled) {+ throw new Error(+ "LLM API keys are only required for model-based evaluations and the playground. Both are not yet available in the v2 open-source version.",+ );}throwIfNoAccess({session: ctx.session,@@ -97,8 +102,10 @@ export const llmApiKeyRouter = createTRPCRouter({}),).query(async ({ input, ctx }) => {- if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {- throw new Error("Evals available in cloud only");+ if (!isEeEnabled) {+ throw new Error(+ "LLM API keys are only required for model-based evaluations and the playground. Both are not yet available in the v2 open-source version.",+ );}throwIfNoAccess({@@ -145,8 +152,10 @@ export const llmApiKeyRouter = createTRPCRouter({test: protectedProjectProcedure.input(CreateLlmApiKey).mutation(async ({ input }) => {- if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {- throw new Error("Evals available in cloud only");+ if (!isEeEnabled) {+ throw new Error(+ "LLM API keys are only required for model-based evaluations and the playground. Both are not yet available in the v2 open-source version.",+ );}try {diff --git a/web/src/features/public-api/components/LLMApiKeyList.tsx b/web/src/features/public-api/components/LLMApiKeyList.tsxindex db9791e818..d1425b61fc 100644--- a/web/src/features/public-api/components/LLMApiKeyList.tsx+++ b/web/src/features/public-api/components/LLMApiKeyList.tsx@@ -20,31 +20,32 @@ import {TableHeader,TableRow,} from "@/src/components/ui/table";-import { env } from "@/src/env.mjs";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { useHasAccess } from "@/src/features/rbac/utils/checkAccess";import { api } from "@/src/utils/api";import { DialogDescription } from "@radix-ui/react-dialog";import { CreateLLMApiKeyDialog } from "./CreateLLMApiKeyDialog";+import { useIsEeEnabled } from "@/src/ee/utils/useIsEeEnabled";export function LlmApiKeyList(props: { projectId: string }) {const hasAccess = useHasAccess({projectId: props.projectId,scope: "llmApiKeys:read",});+ const isEeEnabled = useIsEeEnabled();const apiKeys = api.llmApiKey.all.useQuery({projectId: props.projectId,},{- enabled: hasAccess && env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined,+ enabled: hasAccess && isEeEnabled,},);if (!hasAccess) return null;- if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) return null;+ if (!isEeEnabled) return null;return (<div id="llm-api-keys">diff --git a/web/src/features/telemetry/index.ts b/web/src/features/telemetry/index.tsindex dca662fc62..24fd7468f1 100644--- a/web/src/features/telemetry/index.ts+++ b/web/src/features/telemetry/index.ts@@ -15,8 +15,13 @@ export async function telemetry() {if (process.env.NODE_ENV !== "production") return;// Do not run in Lanfuse cloud, separate telemetry is usedif (process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined) return;- // Check if telemetry is not disabled- if (process.env.TELEMETRY_ENABLED === "false") return;+ // Check if telemetry is not disabled, except for EE or cloud enabled+ if (+ process.env.TELEMETRY_ENABLED === "false" &&+ process.env.LANGFUSE_EE_LICENSE_KEY === undefined &&+ process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined+ )+ return;// Do not run in CIif (process.env.CI) return;@@ -246,6 +251,8 @@ async function posthogTelemetry({datasetRunItems: countDatasetRunItems,startTimeframe: startTimeframe?.toISOString(),endTimeframe: endTimeframe.toISOString(),+ eeLicenseKey: process.env.LANGFUSE_EE_LICENSE_KEY,+ langfuseCloudRegion: process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,$set: {environment: process.env.NODE_ENV,userDomains: domains,diff --git a/web/src/server/auth.ts b/web/src/server/auth.tsindex 65d2e2b2ed..6e5ed16481 100644--- a/web/src/server/auth.ts+++ b/web/src/server/auth.ts@@ -293,6 +293,9 @@ export async function getAuthOptions(): Promise<NextAuthOptions> {env.LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES === "true",defaultTableDateTimeOffset:env.LANGFUSE_DEFAULT_TABLE_DATETIME_OFFSET,+ // Enables features that are only available under an enterprise license when self-hosting Langfuse+ // If you edit this line, you risk executing code that is not MIT licensed (self-contained in /ee folders otherwise)+ eeEnabled: env.LANGFUSE_EE_LICENSE_KEY !== undefined,},user:dbUser !== nulldiff --git a/web/types/next-auth.d.ts b/web/types/next-auth.d.tsindex aa8289c583..cc65975142 100644--- a/web/types/next-auth.d.ts+++ b/web/types/next-auth.d.ts@@ -20,6 +20,8 @@ declare module "next-auth" {enableExperimentalFeatures: boolean;disableExpensivePostgresQueries: boolean;defaultTableDateTimeOffset?: number;+ // Enables features that are only available under an enterprise license when self-hosting Langfuse+ eeEnabled: boolean;};}