🪢 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(ai-gateway): allow the None ingestion mode on Langfuse Cloud (#19109)
Tobias Wochinger896189c630c0
diff --git a/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts b/web/src/__tests__/server/ai-gateway-control-plane.servertest.tsindex 2cc2202266..6ae63478ae 100644--- a/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts+++ b/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts@@ -379,11 +379,11 @@ describe("AI gateway control plane", () => {).resolves.toBeNull();});- it("requires an ingestion project unless ingestion mode is NONE", async () => {+ it("requires an ingestion project unless ingestion mode is NONE, also on cloud", async () => {const { caller, org } = await prepare();const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;try {- Object.assign(env, { NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined });+ Object.assign(env, { NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: "EU" });await expect(caller.aiGateway.updateConfig({orgId: org.id,@@ -930,59 +930,6 @@ describe("AI gateway control plane", () => {expect(result.ingestion?.expires_at).toBe(ingestionClaims.exp);});- it("resolves NONE ingestion mode on self-hosted and rejects it on cloud", async () => {- configureGatewayJwtSigning();- const { caller, org, project } = await prepare();- const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;- try {- Object.assign(env, { NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined });- await caller.aiGateway.updateConfig({- orgId: org.id,- defaultIngestionProjectId: project.id,- ingestionMode: "NONE",- });- await caller.aiGateway.createConnection({- orgId: org.id,- name: "OpenAI",- provider: "OPENAI",- credential: "sk-test-openai",- });- const gatewayKey = await caller.aiGateway.createApiKey({- orgId: org.id,- metadata: {},- });-- const result = await authenticateRequest({- fastHashedSecretKey: createShaHash(gatewayKey.secretKey, env.SALT),- apiFormat: "openai.responses",- model: "gpt-4o",- });- expect(result.ingestion_mode).toBe("none");- expect(result.ingestion).toBeNull();- expect(result.attribution.project_id).toBe(project.id);-- Object.assign(env, { NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: "EU" });- await expect(- caller.aiGateway.updateConfig({- orgId: org.id,- defaultIngestionProjectId: project.id,- ingestionMode: "NONE",- }),- ).rejects.toThrow("only available on self-hosted deployments");- await expect(- caller.aiGateway.updateConfig({- orgId: org.id,- defaultIngestionProjectId: project.id,- ingestionMode: "USAGE",- }),- ).resolves.toMatchObject({ ingestionMode: "USAGE" });- } finally {- Object.assign(env, {- NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: originalCloudRegion,- });- }- });-it("routes unprefixed models by provider and rejects unknown models", async () => {configureGatewayJwtSigning();const { caller, org, project } = await prepare();diff --git a/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsx b/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsxindex 854ed2d107..138c5c57d3 100644--- a/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsx+++ b/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsx@@ -8,14 +8,9 @@ import {GatewayConfigurationView,type IngestionMode,} from "@/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView";-import { IngestionProjectSetupPlaceholder } from "@/src/features/ai-gateway/components/GatewayConfigurationPage/components/IngestionProjectSetupPlaceholder/IngestionProjectSetupPlaceholder";import { showSuccessToast } from "@/src/features/notifications";-import { useLangfuseCloudRegion } from "@/src/features/organizations";import { api, reportNonTrpcError } from "@/src/utils/api";-const CLOUD_INGESTION_MODES = ["USAGE", "FULL"] as const;-const SELF_HOSTED_INGESTION_MODES = ["NONE", "USAGE", "FULL"] as const;-type Project = {id: string;name: string;@@ -30,7 +25,6 @@ export function GatewayConfigurationPage({projects: Project[];}) {const session = useSession();- const { isLangfuseCloud } = useLangfuseCloudRegion();const configQuery = api.aiGateway.getConfig.useQuery({orgId: organizationId,});@@ -105,43 +99,13 @@ export function GatewayConfigurationPage({}}- async function handleSelectProject(projectId: string) {- try {- await saveGatewayConfig({- projectId,- ingestionMode: initialIngestionMode,- });- } catch (error) {- reportNonTrpcError(error, "ai-gateway-configuration");- }- }-- /** Cloud always captures traffic, so it needs a project; self-hosted can use `NONE`. */- const showSetupPlaceholder =- isLangfuseCloud &&- !hasActiveIngestionProject(config?.defaultIngestionProject, organizationId);- if (showSetupPlaceholder) {- return (- <IngestionProjectSetupPlaceholder- ingestionMode={initialIngestionMode}- isSaving={createProject.isPending || updateConfig.isPending}- onCreate={handleCreateProject}- projects={projects.filter((project) => !project.deletedAt)}- onSelectProject={handleSelectProject}- />- );- }-return (<GatewayConfigurationView- key={`${config?.updatedAt?.toISOString() ?? "new"}:${config?.defaultIngestionProjectId ?? "none"}:${config?.ingestionMode ?? "USAGE"}`}+ key={`${config?.updatedAt?.toISOString() ?? "new"}:${config?.defaultIngestionProjectId ?? "none"}:${initialIngestionMode}`}projects={projects}gatewayBaseUrl={gatewayBaseUrl}initialProjectId={config?.defaultIngestionProjectId ?? null}initialIngestionMode={initialIngestionMode}- availableIngestionModes={- isLangfuseCloud ? CLOUD_INGESTION_MODES : SELF_HOSTED_INGESTION_MODES- }isSaving={createProject.isPending || updateConfig.isPending}saveError={createProject.isError || updateConfig.isError}onSave={async ({ projectId, ingestionMode }) => {@@ -170,10 +134,3 @@ function ConfigurationSkeleton() {</div>);}--function hasActiveIngestionProject(- project: { orgId: string; deletedAt: Date | null } | null | undefined,- organizationId: string,-) {- return !!project && !project.deletedAt && project.orgId === organizationId;-}diff --git a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsx b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsxindex c9de3a77a6..e3face3286 100644--- a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsx+++ b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsx@@ -17,21 +17,6 @@ export const Enabled = meta.story({gatewayBaseUrl: "https://gateway.staging.langfuse.com/v1",initialProjectId: "project-production",initialIngestionMode: "USAGE",- availableIngestionModes: ["USAGE", "FULL"],- isSaving: false,- saveError: false,- onSave: fn(),- onCreateProject: fn(),- },-});--export const SelfHostedNoCapture = meta.story({- args: {- projects,- gatewayBaseUrl: "https://gateway.example.com/v1",- initialProjectId: "project-production",- initialIngestionMode: "NONE",- availableIngestionModes: ["NONE", "USAGE", "FULL"],isSaving: false,saveError: false,onSave: fn(),@@ -45,7 +30,6 @@ export const MissingProjectWarning = meta.story({gatewayBaseUrl: "https://gateway.staging.langfuse.com/v1",initialProjectId: "deleted-project",initialIngestionMode: "FULL",- availableIngestionModes: ["USAGE", "FULL"],isSaving: false,saveError: false,onSave: fn(),diff --git a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsx b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsxindex e96949c51f..f3e43ed409 100644--- a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsx+++ b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsx@@ -68,7 +68,6 @@ export function GatewayConfigurationView({gatewayBaseUrl,initialProjectId,initialIngestionMode,- availableIngestionModes,isSaving,saveError,onSave,@@ -78,7 +77,6 @@ export function GatewayConfigurationView({gatewayBaseUrl: string;initialProjectId: string | null;initialIngestionMode: IngestionMode;- availableIngestionModes: readonly IngestionMode[];isSaving: boolean;saveError: boolean;onSave: (values: {@@ -102,9 +100,6 @@ export function GatewayConfigurationView({const [ingestionMode, setIngestionMode] =useState<IngestionMode>(initialIngestionMode);const projectId = projectSelection ?? null;- const visibleIngestionModes = ingestionModes.filter((option) =>- availableIngestionModes.includes(option.value),- );const isDirty =projectId !== initialProjectId || ingestionMode !== initialIngestionMode;const isConfigured = isGatewayIngestionConfigured({@@ -200,15 +195,8 @@ export function GatewayConfigurationView({<div><CardTitle className="mb-4 text-base">Ingestion mode</CardTitle>- <div- className={cn(- "grid gap-2",- visibleIngestionModes.length > 2- ? "md:grid-cols-3"- : "md:grid-cols-2",- )}- >- {visibleIngestionModes.map((option) => {+ <div className="grid gap-2 md:grid-cols-3">+ {ingestionModes.map((option) => {const Icon = option.icon;const selected = ingestionMode === option.value;return (@@ -251,8 +239,9 @@ export function GatewayConfigurationView({<div className="flex items-center justify-end gap-3">{isConfigured ? null : (- <p className="text-muted-foreground text-xs">- Select an ingestion project to capture gateway traffic.+ <p className="text-destructive text-sm">+ Select an ingestion project, or choose None to route without+ capturing.</p>)}<Buttondiff --git a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/IngestionProjectSetupPlaceholder/IngestionProjectSetupPlaceholder.tsx b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/IngestionProjectSetupPlaceholder/IngestionProjectSetupPlaceholder.tsxdeleted file mode 100644index 790136fd54..0000000000--- a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/IngestionProjectSetupPlaceholder/IngestionProjectSetupPlaceholder.tsx+++ /dev/null@@ -1,70 +0,0 @@-import { FolderInput, Plus } from "@langfuse/icons";--import Header from "@/src/components/layouts/header";-import {- CreateIngestionProjectDialogController,- type CreateIngestionProjectDialogControllerProps,-} from "@/src/features/ai-gateway/components/GatewayConfigurationPage/components/CreateIngestionProjectDialogController/CreateIngestionProjectDialogController";-import { GatewaySetupEmptyState } from "@/src/features/ai-gateway/components/GatewaySetupEmptyState/GatewaySetupEmptyState";-import {- GATEWAY_CONFIGURATION_DESCRIPTION,- GATEWAY_CONFIGURATION_TITLE,-} from "@/src/features/ai-gateway/constants/gatewayConfig";--export type IngestionProjectSetupPlaceholderProps = Pick<- CreateIngestionProjectDialogControllerProps,- "ingestionMode" | "isSaving" | "onCreate"-> & {- projects: ReadonlyArray<{ id: string; name: string }>;- onSelectProject: (projectId: string) => void;-};--export function IngestionProjectSetupPlaceholder({- ingestionMode,- isSaving,- onCreate,- projects,- onSelectProject,-}: IngestionProjectSetupPlaceholderProps) {- return (- <div className="flex flex-col gap-6">- <div>- <Header title={GATEWAY_CONFIGURATION_TITLE} />- <p className="text-muted-foreground text-sm">- {GATEWAY_CONFIGURATION_DESCRIPTION}- </p>- </div>- <CreateIngestionProjectDialogController- ingestionMode={ingestionMode}- isSaving={isSaving}- onCreate={onCreate}- >- {({ openDialog }) => (- <GatewaySetupEmptyState- icon={FolderInput}- title="Set up an ingestion project first"- description="Gateway traffic needs a project to be recorded in. Credentials, models and API keys become available once it is set."- actions={[- {- type: "button",- label: "Create ingestion project",- icon: Plus,- onClick: openDialog,- },- {- type: "menu",- label: "Use existing project",- items: projects.map((project) => ({- id: project.id,- title: project.name,- })),- onSelect: onSelectProject,- disabled: isSaving,- },- ]}- />- )}- </CreateIngestionProjectDialogController>- </div>- );-}diff --git a/web/src/features/ai-gateway/fns/isGatewayIngestionConfigured.ts b/web/src/features/ai-gateway/fns/isGatewayIngestionConfigured.tsindex e8cf18b3ff..7293540cfa 100644--- a/web/src/features/ai-gateway/fns/isGatewayIngestionConfigured.ts+++ b/web/src/features/ai-gateway/fns/isGatewayIngestionConfigured.ts@@ -1,6 +1,6 @@import type { GatewayIngestionMode } from "@langfuse/shared";-/** Capturing ingestion modes need a project to record into; `NONE` (self-hosted only) does not. */+/** Capturing ingestion modes need a project to record into; `NONE` does not. */export function isGatewayIngestionConfigured({ingestionMode,hasActiveIngestionProject,diff --git a/web/src/features/ai-gateway/server/resolve/resolveService.servertest.ts b/web/src/features/ai-gateway/server/resolve/resolveService.servertest.tsindex fc5b442fcb..e9b1d6e77c 100644--- a/web/src/features/ai-gateway/server/resolve/resolveService.servertest.ts+++ b/web/src/features/ai-gateway/server/resolve/resolveService.servertest.ts@@ -194,39 +194,45 @@ describe("GatewayResolveService", () => {).rejects.toMatchObject({ status: 403 });});- it("resolves NONE mode without an ingestion project or signing keys", async () => {- const signingKeys = {- LANGFUSE_AI_GATEWAY_JWT_PRIVATE_KEY:- mockEnv.LANGFUSE_AI_GATEWAY_JWT_PRIVATE_KEY,- LANGFUSE_AI_GATEWAY_JWT_PUBLIC_KEY:- mockEnv.LANGFUSE_AI_GATEWAY_JWT_PUBLIC_KEY,- LANGFUSE_AI_GATEWAY_JWT_KEY_ID: mockEnv.LANGFUSE_AI_GATEWAY_JWT_KEY_ID,- };- Object.assign(mockEnv, {- LANGFUSE_AI_GATEWAY_JWT_PRIVATE_KEY: undefined,- LANGFUSE_AI_GATEWAY_JWT_PUBLIC_KEY: undefined,- LANGFUSE_AI_GATEWAY_JWT_KEY_ID: undefined,- });- try {- const service = serviceWith(() =>- Promise.resolve(row({ ingestionMode: "NONE", withoutProject: true })),- );-- await expect(- service.resolve({- fastHashedSecretKey: "hashed-secret-key",- apiFormat: "openai.responses",- }),- ).resolves.toMatchObject({- connection: { id: "connection-1", provider_model: "gpt-4o" },- attribution: { organization_id: "org-1", project_id: null },- ingestion_mode: "none",- ingestion: null,+ it.each([+ { withoutProject: true, projectId: null },+ { withoutProject: false, projectId: "project-1" },+ ])(+ "resolves NONE mode without signing keys (project: $projectId)",+ async ({ withoutProject, projectId }) => {+ const signingKeys = {+ LANGFUSE_AI_GATEWAY_JWT_PRIVATE_KEY:+ mockEnv.LANGFUSE_AI_GATEWAY_JWT_PRIVATE_KEY,+ LANGFUSE_AI_GATEWAY_JWT_PUBLIC_KEY:+ mockEnv.LANGFUSE_AI_GATEWAY_JWT_PUBLIC_KEY,+ LANGFUSE_AI_GATEWAY_JWT_KEY_ID: mockEnv.LANGFUSE_AI_GATEWAY_JWT_KEY_ID,+ };+ Object.assign(mockEnv, {+ LANGFUSE_AI_GATEWAY_JWT_PRIVATE_KEY: undefined,+ LANGFUSE_AI_GATEWAY_JWT_PUBLIC_KEY: undefined,+ LANGFUSE_AI_GATEWAY_JWT_KEY_ID: undefined,});- } finally {- Object.assign(mockEnv, signingKeys);- }- });+ try {+ const service = serviceWith(() =>+ Promise.resolve(row({ ingestionMode: "NONE", withoutProject })),+ );++ await expect(+ service.resolve({+ fastHashedSecretKey: "hashed-secret-key",+ apiFormat: "openai.responses",+ }),+ ).resolves.toMatchObject({+ connection: { id: "connection-1", provider_model: "gpt-4o" },+ attribution: { organization_id: "org-1", project_id: projectId },+ ingestion_mode: "none",+ ingestion: null,+ });+ } finally {+ Object.assign(mockEnv, signingKeys);+ }+ },+ );it("rejects an unknown or expired gateway key", async () => {const service = serviceWith(() => Promise.resolve(null));diff --git a/web/src/features/ai-gateway/server/router.ts b/web/src/features/ai-gateway/server/router.tsindex 73d793acd6..63e078e3e0 100644--- a/web/src/features/ai-gateway/server/router.ts+++ b/web/src/features/ai-gateway/server/router.ts@@ -116,14 +116,7 @@ export const aiGatewayRouter = createTRPCRouter({.input(organizationInput.extend({defaultIngestionProjectId: z.string().nullable(),- ingestionMode: z- .enum(GatewayIngestionMode)- .refine(- (mode) =>- mode !== GatewayIngestionMode.NONE ||- !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,- "Ingestion mode NONE is only available on self-hosted deployments",- ),+ ingestionMode: z.enum(GatewayIngestionMode),}),).mutation(async ({ input, ctx }) => {