ML, anomaly detection, and forecasting
TensorCost’s ML surface covers four jobs:- Anomaly detection across GPU metrics and AI spend (statistical baseline + optional ML layer).
- Burn-rate alerting against budget hierarchies (in flight).
- Cost forecasting at tenant, application, and team scope.
- Recommendations — the four shipped Bedrock recommenders, plus their GPU-side counterparts.
apps-new/services/ai-service/src/recommenders/.
Anomaly detection — statistical layer
Every metric stream — GPU utilization, memory, temperature, daily cost, hourly cost, agent invocation count, cache-hit rate — runs through three independent statistical detectors:
An anomaly is confirmed when at least 2 of 3 methods agree (composite confidence ≥ 0.5). Day-of-week seasonal baselines avoid false positives on predictable patterns (training jobs that always spike Tuesday morning, etc.).
Every detection writes a row to the analysis audit log with the inputs, scores, decision, and reason — useful for tuning thresholds and for SOC 2 processing-integrity evidence.
Anomaly detection — ML layer (opt-in)
Customers ongrowth and enterprise plans can enable a per-tenant Isolation Forest layer that composes with the statistical scores.
Training
MLTrainingJob runs daily. For each tenant + model type, retrain triggers on:
Minimum samples default to 1,000. For
ai_spend_anomaly, one sample = one filled hour bucket (so a 14-day lookback caps at 336 samples; new tenants need to accumulate hours, or operators set ML_MIN_TRAINING_POINTS=200 until volume builds).
Inference and ensemble
For each incoming metric:- The statistical scorer runs.
- If
ml-enabledis on and the model is loaded, the sidecar predicts. - The composite score is a weighted average —
ML_ENSEMBLE_WEIGHTdefaults to 0.2 (20% ML, 80% statistical). - An alert fires when the composite crosses the severity threshold.
Circuit breaker
All sidecar calls are wrapped in a circuit breaker. After 3 consecutive failures or 30s timeouts, the breaker opens for 60s and detection falls back to the statistical layer. The ML models admin page surfaces breaker state —CLOSED, HALF_OPEN, or OPEN.
Runaway-loop and retry-storm detection
For agent workloads — where one bug can burn $10,000 overnight — TensorCost ships a dedicated runaway-loop detector alongside the generic anomaly detection. It triggers on:- Sudden invocation-count spike (>3σ from the per-agent baseline).
- Unusually long invocation chains (same
conversation_idexceedingNcalls). - Cost-per-user-session spike vs the rolling baseline.
Cost forecasting
cost-service produces 30-, 60-, and 90-day forecasts at three scopes:
- Tenant total
- Application
- Team
Recommendations
Recommendations are computed by per-domain recommenders. Four are shipped today against Bedrock; the same patterns apply to Azure OpenAI / Vertex / OpenAI / Anthropic as those adapters land.Bedrock recommenders (shipped)
Each recommendation carries:
- A specific dollar impact estimate.
- The evidence (sample request IDs, cost breakdown, A/B plan).
- An accept / dismiss-with-reason / snooze action.
GPU recommenders
Live training and recommendation events
Every job and recommender publishes Socket.IO events:ml.training.started,ml.training.completed,ml.training.failedrecommendation.created,recommendation.accepted,recommendation.dismissedforecast.generated,forecast.budget_breach_predictedanomaly.detected,anomaly.resolvedrunaway_loop.detected,runaway_loop.paused
The ML models admin page
Admins on plans with the ML layer get an ML models page that shows:- Whether
ml-enabledis active for the tenant. - Active models per type with version, sample count, accuracy metrics.
- Ensemble weight.
- Circuit breaker state.
- Per-model retraining status with reason labels.
- A train now button per model.