🪢 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
fix(billing): raise default spend alert thresholds above plan base fees (#18768)
Steffen Reuther1cf619711ba6
diff --git a/web/src/__tests__/server/createDefaultSpendAlerts.servertest.ts b/web/src/__tests__/server/createDefaultSpendAlerts.servertest.tsindex b357c926d9..5d7aea0b57 100644--- a/web/src/__tests__/server/createDefaultSpendAlerts.servertest.ts+++ b/web/src/__tests__/server/createDefaultSpendAlerts.servertest.ts@@ -68,9 +68,8 @@ describe("createDefaultSpendAlerts", () => {orderBy: { threshold: "asc" },});- expect(alerts).toHaveLength(2);- expect(alerts[0].threshold.toNumber()).toBe(2000);- expect(alerts[1].threshold.toNumber()).toBe(4000);+ // The plan threshold already exceeds the universal one, which is skipped+ expect(alerts.map((alert) => alert.threshold.toNumber())).toEqual([5000]);});it("skips creation if org already has alerts", async () => {@@ -126,13 +125,13 @@ describe("createDefaultSpendAlerts", () => {*/describe("ClickHouse-billed organizations", () => {it.each([- ["LANGFUSE_CORE", 200],- ["LANGFUSE_PRO", 1000],- ["LANGFUSE_PRO_TEAMS", 1000],- ["LANGFUSE_ENTERPRISE", 2000],+ ["LANGFUSE_CORE", [200, 4000]],+ ["LANGFUSE_PRO", [1000, 4000]],+ ["LANGFUSE_PRO_TEAMS", [1500, 4000]],+ ["LANGFUSE_ENTERPRISE", [5000]],] as const)(- "creates the plan threshold plus the universal one for %s",- async (planCode, expectedThreshold) => {+ "creates the default thresholds for %s",+ async (planCode, expectedThresholds) => {const { orgId } = await createOrgProjectAndApiKey();await createDefaultSpendAlerts({@@ -147,7 +146,7 @@ describe("createDefaultSpendAlerts", () => {});expect(alerts.map((alert) => alert.threshold.toNumber())).toEqual(- [...new Set([expectedThreshold, 4000])].sort((a, b) => a - b),+ expectedThresholds,);},);diff --git a/web/src/__tests__/server/unit/chbWebhookHandler.servertest.ts b/web/src/__tests__/server/unit/chbWebhookHandler.servertest.tsindex 81acbd111c..d7b4787373 100644--- a/web/src/__tests__/server/unit/chbWebhookHandler.servertest.ts+++ b/web/src/__tests__/server/unit/chbWebhookHandler.servertest.ts@@ -693,7 +693,7 @@ describe("chbWebhookHandler", () => {await chbWebhookHandler(post(attachedPlanCreated()));- expect(seededThresholds()).toEqual([2000, 4000]);+ expect(seededThresholds()).toEqual([5000]);});it("leaves an org's own alerts alone", async () => {diff --git a/web/src/ee/features/billing/server/defaultSpendAlerts.ts b/web/src/ee/features/billing/server/defaultSpendAlerts.tsindex 5f288ecca0..1a1627f5c3 100644--- a/web/src/ee/features/billing/server/defaultSpendAlerts.ts+++ b/web/src/ee/features/billing/server/defaultSpendAlerts.ts@@ -21,14 +21,20 @@ type PlanWithoutSpendAlerts =type PlanWithSpendAlerts = Exclude<Plan, PlanWithoutSpendAlerts>;+/**+ * Both providers report spend including the plan's base fee, so each threshold+ * has to sit well above that fee to leave room for usage. Otherwise the alert+ * fires at the start of every billing period.+ */const DEFAULT_SPEND_ALERT_THRESHOLDS: Record<PlanWithSpendAlerts, number> = {"cloud:core": 200,"cloud:pro": 1000,- "cloud:team": 1000,- "cloud:enterprise": 2000,+ "cloud:team": 1500,+ "cloud:enterprise": 5000,};-// Universal threshold applied to all plans in addition to the plan-specific threshold+// Universal threshold added on top of the plan-specific one, for plans whose+// plan threshold is below itconst UNIVERSAL_SPEND_ALERT_THRESHOLD = 4000;/** Which webhook is seeding, for the audit actor and the log prefix. */@@ -71,10 +77,11 @@ export async function createDefaultSpendAlerts({return;}- // Create plan-specific alert plus the universal $4K alert (deduplicated)- const thresholds = [- ...new Set([planThreshold, UNIVERSAL_SPEND_ALERT_THRESHOLD]),- ];+ // Create plan-specific alert plus the universal $4K alert when it is higher+ const thresholds =+ planThreshold < UNIVERSAL_SPEND_ALERT_THRESHOLD+ ? [planThreshold, UNIVERSAL_SPEND_ALERT_THRESHOLD]+ : [planThreshold];for (const threshold of thresholds) {const alert = await prisma.cloudSpendAlert.create({