Implementation:Helicone Helicone Alert Types
| Knowledge Sources | |
|---|---|
| Domains | Alerting, Type System |
| Last Updated | 2026-02-14 06:32 GMT |
Overview
Type definitions and constant arrays that define the metric, aggregation, and grouping dimensions available in Helicone's alerting system.
Description
This module provides the type-safe configuration schema for Helicone's alerting subsystem. It defines three constant arrays (ALERT_METRICS, ALERT_AGGREGATIONS, and ALERT_STANDARD_GROUPINGS) using TypeScript's as const assertion pattern, then derives corresponding union types from each array. This approach ensures that the set of valid values is defined in exactly one place and that both runtime arrays and compile-time types remain in sync.
ALERT_METRICS enumerates the observable metrics: response.status, cost, latency, total_tokens, prompt_tokens, completion_tokens, prompt_cache_read_tokens, prompt_cache_write_tokens, and count.
ALERT_AGGREGATIONS enumerates the statistical operations that can be applied: sum, avg, min, max, and percentile.
ALERT_STANDARD_GROUPINGS enumerates the standard dimensions for grouping: user, model, and provider. The AlertGrouping type extends the standard grouping union with arbitrary strings to support custom properties.
Usage
Use these types and constants when building alert configuration UIs, validating alert definitions on the backend, or constructing alerting queries. Import the constant arrays when you need to iterate over valid options (for example, populating a dropdown), and import the types when you need compile-time checks on alert configurations.
Code Reference
Source Location
- Repository: Helicone
- File: packages/filters/alerts.ts
Signature
export const ALERT_METRICS: readonly ["response.status", "cost", "latency", "total_tokens", "prompt_tokens", "completion_tokens", "prompt_cache_read_tokens", "prompt_cache_write_tokens", "count"];
export type AlertMetric = (typeof ALERT_METRICS)[number];
export const ALERT_AGGREGATIONS: readonly ["sum", "avg", "min", "max", "percentile"];
export type AlertAggregation = (typeof ALERT_AGGREGATIONS)[number];
export const ALERT_STANDARD_GROUPINGS: readonly ["user", "model", "provider"];
export type AlertStandardGrouping = (typeof ALERT_STANDARD_GROUPINGS)[number];
export type AlertGrouping = AlertStandardGrouping | string;
Import
import {
ALERT_METRICS,
AlertMetric,
ALERT_AGGREGATIONS,
AlertAggregation,
ALERT_STANDARD_GROUPINGS,
AlertStandardGrouping,
AlertGrouping,
} from "@helicone/filters/alerts";
I/O Contract
| Export | Type | Description |
|---|---|---|
ALERT_METRICS |
readonly string[] |
Array of 9 metric identifiers available for alert conditions |
AlertMetric |
Union type | Compile-time union of all valid metric strings |
ALERT_AGGREGATIONS |
readonly string[] |
Array of 5 aggregation function names |
AlertAggregation |
Union type | Compile-time union of all valid aggregation strings |
ALERT_STANDARD_GROUPINGS |
readonly string[] |
Array of 3 standard grouping dimensions |
AlertStandardGrouping |
Union type | Compile-time union of standard grouping strings |
AlertGrouping |
Union type | Standard groupings extended with string for custom properties
|
Usage Examples
import { ALERT_METRICS, AlertMetric, ALERT_AGGREGATIONS, AlertAggregation } from "@helicone/filters/alerts";
// Populate a metric selector dropdown
const metricOptions = ALERT_METRICS.map((metric) => ({
label: metric,
value: metric,
}));
// Type-safe alert configuration
interface AlertConfig {
metric: AlertMetric;
aggregation: AlertAggregation;
threshold: number;
groupBy?: AlertGrouping;
}
const alert: AlertConfig = {
metric: "cost",
aggregation: "avg",
threshold: 0.05,
groupBy: "model",
};