Skip to content

Predictions

Machine learning-powered drift predictions, pattern analysis, and risk insights.

Base path: /api/predictions

Authentication: Bearer token required on all routes

Get High-Risk Predictions

GET /api/predictions/high-risk

Get predictions flagged as high risk across all repositories.

Response

json
{
  "success": true,
  "data": [
    {
      "_id": "pred1",
      "resourceType": "aws_iam_role",
      "resourceAddress": "module.auth.aws_iam_role.admin",
      "riskScore": 0.92,
      "predictedDriftType": "policy_change",
      "confidence": 0.87,
      "repositoryConfig": "abc123"
    }
  ]
}

Example

bash
curl -H "Authorization: Bearer TOKEN" \
  https://api.controlinfra.com/api/predictions/high-risk

Get All Predictions

GET /api/predictions/all

Get all predictions (not just high-risk) for debugging and analysis.

Get ML Insights

GET /api/predictions/insights

Get ML insights for the dashboard including enhanced metrics, anomaly detection, and top risk factors.

Response

json
{
  "success": true,
  "data": {
    "totalPredictions": 45,
    "highRiskCount": 8,
    "avgConfidence": 0.82,
    "topRiskFactors": [
      { "factor": "manual_iam_changes", "frequency": 12 },
      { "factor": "security_group_edits", "frequency": 8 }
    ],
    "anomalies": [...]
  }
}

Get Learned Patterns

GET /api/predictions/patterns

Get drift patterns learned by the ML model from historical data.

Response

json
{
  "success": true,
  "data": [
    {
      "pattern": "iam_policy_drift_after_deploy",
      "frequency": 23,
      "avgSeverity": "high",
      "resources": ["aws_iam_role", "aws_iam_policy"]
    }
  ]
}

Get User Model Info

GET /api/predictions/model

Get information about the user's personalized ML model.

Get ML Dashboard

GET /api/predictions/ml-dashboard

Get comprehensive ML dashboard data (predictions, insights, model performance).

Get Metrics

GET /api/predictions/metrics

Get prediction metrics globally.

GET /api/predictions/metrics/:repositoryConfigId

Get prediction metrics for a specific repository.

Path Parameters

ParameterTypeDescription
repositoryConfigIdstringRepository config ID

Trigger Pattern Learning

POST /api/predictions/learn

Trigger ML pattern learning from drift history. This trains the model on new drift data.

Example

bash
curl -X POST -H "Authorization: Bearer TOKEN" \
  https://api.controlinfra.com/api/predictions/learn

List Predictions for Repository

GET /api/predictions/repository/:repositoryConfigId

List predictions for a specific repository.

Path Parameters

ParameterTypeDescription
repositoryConfigIdstringRepository config ID

Get Prediction

GET /api/predictions/:predictionId

Get details for a specific prediction.

Path Parameters

ParameterTypeDescription
predictionIdstringPrediction ID

Get Prediction Explanation

GET /api/predictions/:predictionId/explanation

Get a detailed SHAP-based explanation for why a prediction was made.

Path Parameters

ParameterTypeDescription
predictionIdstringPrediction ID

Response

json
{
  "success": true,
  "data": {
    "predictionId": "pred1",
    "shapValues": {
      "resource_age_days": 0.35,
      "recent_manual_changes": 0.28,
      "deploy_frequency": 0.15
    },
    "topFeatures": [
      { "feature": "resource_age_days", "impact": "high", "direction": "increases_risk" }
    ]
  }
}

Mark Prediction as Seen

POST /api/predictions/:predictionId/seen

Mark a prediction as seen/acknowledged.

Path Parameters

ParameterTypeDescription
predictionIdstringPrediction ID

Take Action on Prediction

POST /api/predictions/:predictionId/action

Record an action taken on a prediction.

Path Parameters

ParameterTypeDescription
predictionIdstringPrediction ID

Request Body

FieldTypeRequiredDescription
actionstringYesAction taken (e.g., investigate, ignore, scan)

Submit Feedback

POST /api/predictions/:predictionId/feedback

Submit feedback on prediction accuracy.

Path Parameters

ParameterTypeDescription
predictionIdstringPrediction ID

Request Body

FieldTypeRequiredDescription
accuratebooleanYesWhether the prediction was accurate
commentstringNoOptional feedback