Skip to content

API Endpoints — AI Insights

Endpoints for the AI Insights engine (rule-based RCA, anomalies, recommendations).


Get Insights Snapshot

GET /api/ai-insights/engine

Returns full computed insight snapshot (cached 30s).

Response Structure

{
  "generated_at": "2026-01-15T10:30:00Z",
  "health": "degraded",
  "risk_score": 67,
  "risk_level": "HIGH",
  "executive_summary": "System health is degraded. 3 critical incidents in the last 24h...",
  "summary_bullets": [
    "3 critical incidents detected.",
    "75.0% of P1 originate from api.",
    "The dominant pattern started 2h ago."
  ],
  "diagnosis": {
    "what": "Database connection pool exhaustion on api",
    "where": "All 3 P1 incidents concentrate on api.",
    "why": "Root cause suspicion: Database connection pool exhaustion.",
    "impact": "3 P1 incidents in 24h · 75.0% of P1 · 3 on api · active 2h",
    "action": "Check PostgreSQL connection limits, max_connections and recent deployments."
  },
  "counts": {"P1": 3, "P2": 12, "P3": 45, "P4": 100, "total": 160, "total_all": 50000},
  "rca": {
    "active": true,
    "service": "api",
    "priority": "P1",
    "incidents": 3,
    "share_pct": 75.0,
    "events": 150,
    "dominant_template": {
      "template_id": "42",
      "text": "Database connection pool exhausted",
      "count": 80,
      "p1": 3,
      "started_at": "2026-01-15T08:30:00Z"
    },
    "reasons": ["75.0% of P1 events", "3 incidents", "Started 2h ago"],
    "evidence": ["Database connection pool exhaustion"],
    "root_cause": "Database connection pool exhaustion",
    "recommended_action": "Check PostgreSQL connection limits...",
    "confidence": 85,
    "focus_card": {...}
  },
  "anomalies": [
    {
      "service": "api",
      "metric": "P1/P2 events",
      "value": 15,
      "baseline": 2,
      "delta_pct": 650,
      "p1_share": 75.0,
      "severity": "P1",
      "kind": "surge"
    }
  ],
  "insights": [
    {
      "type": "issue",
      "icon": "🔴",
      "title": "Database connection pool exhaustion",
      "description": "api · 150 events",
      "severity": "P1",
      "service": "api",
      "events": 150,
      "evidence": "✓ 150 similar logs detected | ✓ Same Drain3 template (42) | ...",
      "recommendation": "Check PostgreSQL connection limits...",
      "action": "Open Events",
      "confidence": 90,
      "detected_at": "2026-01-15T08:30:00Z",
      "family": "database",
      "detection_reasons": [...],
      "related_templates": [...],
      "timeline": [...],
      "mttd_seconds": 300,
      "mtta_seconds": 900,
      "mttr_seconds": 1800,
      "template_id": "42",
      "incident_id": "uuid"
    }
  ],
  "recommendations": [
    {"level": "warn", "label": "Investigate api"},
    {"level": "warn", "label": "Check PostgreSQL connection limits..."},
    {"level": "info", "label": "Review 2 new templates"}
  ],
  "trends": {
    "critical_events": {"yesterday": 1, "today": 3, "delta_abs": 2, "delta_pct": 200},
    "error_events": {"yesterday": 8, "today": 12, "delta_abs": 4, "delta_pct": 50},
    "event_volume": {"yesterday": 15000, "today": 18000, "delta_abs": 3000, "delta_pct": 20}
  },
  "ml": {
    "status": "healthy",
    "cache_hit_pct": 97.2,
    "known_templates": 3847,
    "cache_size": 3847,
    "new_templates": 2,
    "avg_confidence": 87.5,
    "low_confidence_count": 0,
    "fallback_rules": 150,
    "model_version": "roberta_v1.1"
  }
}

List Stored Insights

GET /api/ai-insights

Returns persisted AiInsight records (anomaly snapshots).


Insights Stats

GET /api/ai-insights/stats

Lightweight stats for dashboard KPI cards.

{
  "counts": {"P1": 3, "P2": 12, ...},
  "risk_score": 67,
  "risk_level": "HIGH",
  "health": "degraded",
  "ml_status": "healthy",
  "trends": {...}
}