Skip to content

Commit d7d223a

Browse files
committed
fix: suppress noisy cost/req alerts below $5/req and format values properly
Add absolute $/req floor (default $5) to skip alerts on normal thinking model costs. Fix Slack and email alerts showing raw cents instead of formatted dollar amounts for cost_per_req metric. Made-with: Cursor
1 parent f011b4f commit d7d223a

5 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/app/settings/settings-client.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,27 @@ export function SettingsClient({ config: initial }: SettingsClientProps) {
202202
hint={config.trends.costPerReqMinSpendCents === 0 ? "disabled" : "skip low spenders"}
203203
unit="cents"
204204
/>
205+
<Field
206+
label="Min $/req to alert"
207+
value={config.trends.costPerReqMinAbsoluteCents}
208+
onChange={(v) =>
209+
setConfig({
210+
...config,
211+
trends: { ...config.trends, costPerReqMinAbsoluteCents: v },
212+
})
213+
}
214+
suffix={
215+
config.trends.costPerReqMinAbsoluteCents > 0
216+
? `$${(config.trends.costPerReqMinAbsoluteCents / 100).toFixed(0)}/req`
217+
: undefined
218+
}
219+
hint={
220+
config.trends.costPerReqMinAbsoluteCents === 0
221+
? "disabled"
222+
: "skip unless $/req exceeds this"
223+
}
224+
unit="cents"
225+
/>
205226
<div className="text-[10px] text-zinc-600 space-y-0.5 mt-1">
206227
<p>
207228
Compares today&apos;s average cost per request against the user&apos;s historical

src/lib/alerts/email.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function formatValue(metric: string, value: number): string {
1111
switch (metric) {
1212
case "spend":
1313
return `$${(value / 100).toFixed(2)}`;
14+
case "cost_per_req":
15+
return `$${(value / 100).toFixed(2)}/req`;
1416
case "tokens":
1517
return `${(value / 1_000_000).toFixed(2)}M tokens`;
1618
case "requests":

src/lib/alerts/slack.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function formatValue(metric: string, value: number): string {
1919
switch (metric) {
2020
case "spend":
2121
return `$${(value / 100).toFixed(2)}`;
22+
case "cost_per_req":
23+
return `$${(value / 100).toFixed(2)}/req`;
2224
case "tokens":
2325
return `${(value / 1_000_000).toFixed(2)}M`;
2426
case "requests":

src/lib/anomaly/trends.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function detectTrendAnomalies(config: DetectionConfig): Anomaly[] {
1919
cycleOutlierMultiplier,
2020
costPerReqSpikeMultiplier,
2121
costPerReqMinSpendCents,
22+
costPerReqMinAbsoluteCents,
2223
} = config.trends;
2324

2425
detectSpendSpikes(anomalies, now, spendSpikeMultiplier, spendSpikeLookbackDays);
@@ -28,6 +29,7 @@ export function detectTrendAnomalies(config: DetectionConfig): Anomaly[] {
2829
now,
2930
costPerReqSpikeMultiplier,
3031
costPerReqMinSpendCents,
32+
costPerReqMinAbsoluteCents,
3133
spendSpikeLookbackDays,
3234
);
3335

@@ -115,6 +117,7 @@ function detectCostPerReqSpikes(
115117
now: string,
116118
spikeMultiplier: number,
117119
minSpendCents: number,
120+
minAbsoluteCents: number,
118121
lookbackDays: number,
119122
): void {
120123
if (spikeMultiplier <= 0) return;
@@ -123,6 +126,7 @@ function detectCostPerReqSpikes(
123126

124127
for (const user of users) {
125128
if (user.today_spend_cents < minSpendCents) continue;
129+
if (minAbsoluteCents > 0 && user.today_cost_per_req < minAbsoluteCents) continue;
126130
if (!user.hist_avg_cost_per_req || user.hist_avg_cost_per_req <= 0) continue;
127131
if (user.hist_days < 3) continue;
128132

src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ export interface DetectionConfig {
394394
cycleOutlierMultiplier: number;
395395
costPerReqSpikeMultiplier: number;
396396
costPerReqMinSpendCents: number;
397+
costPerReqMinAbsoluteCents: number;
397398
};
398399
cronIntervalMinutes: number;
399400
enableInfoAnomalies: boolean;
@@ -414,6 +415,7 @@ export const DEFAULT_CONFIG: DetectionConfig = {
414415
cycleOutlierMultiplier: 10,
415416
costPerReqSpikeMultiplier: 3,
416417
costPerReqMinSpendCents: 2000,
418+
costPerReqMinAbsoluteCents: 500,
417419
},
418420
cronIntervalMinutes: 60,
419421
enableInfoAnomalies: false,

0 commit comments

Comments
 (0)