> ## Documentation Index
> Fetch the complete documentation index at: https://chatcli.edilsonfreitas.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API REST Reference

> Complete reference for the AIOps Platform REST API — all endpoints, parameters, and examples.

The **AIOps Platform REST API** lets you integrate any external system with ChatCLI's autonomous operations platform. All endpoints follow RESTful conventions and return JSON.

The API is served by the Web Dashboard on port `8090` (configurable via `CHATCLI_AIOPS_PORT`).

***

## Authentication

<AccordionGroup>
  <Accordion title="X-API-Key Header">
    All authenticated requests must include the `X-API-Key` header:

    ```bash theme={"system"}
    curl -H "X-API-Key: seu-token-aqui" http://localhost:8090/api/v1/incidents
    ```

    Keys are configured via the `chatcli-api-keys` ConfigMap in the operator namespace:

    ```yaml theme={"system"}
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: chatcli-api-keys
    data:
      keys.json: |
        {
          "keys": [
            {"key": "ops-key-abc123", "role": "operator", "description": "CI/CD pipeline"},
            {"key": "view-key-xyz789", "role": "viewer", "description": "Dashboard read-only"},
            {"key": "admin-key-root01", "role": "admin", "description": "Platform admin"}
          ]
        }
    ```
  </Accordion>

  <Accordion title="Roles and Permissions">
    | Role       | Read | Ack/Snooze | Approve/Reject | CRUD Runbooks | Audit Export |
    | ---------- | ---- | ---------- | -------------- | ------------- | ------------ |
    | `viewer`   | Yes  | No         | No             | No            | No           |
    | `operator` | Yes  | Yes        | Yes            | No            | No           |
    | `admin`    | Yes  | Yes        | Yes            | Yes           | Yes          |
  </Accordion>

  <Accordion title="Development Mode">
    When no API key is configured (ConfigMap absent), the API operates in **dev mode** — all requests are allowed without authentication.

    <Warning>
      Never use dev mode in production. Configure at least one API key before exposing the service.
    </Warning>
  </Accordion>

  <Accordion title="Rate Limiting">
    The API enforces a rate limit of **100 requests per minute** per IP.

    When the limit is exceeded, the API returns:

    ```json theme={"system"}
    {
      "error": "rate limit exceeded",
      "retry_after_seconds": 42
    }
    ```

    | Header                  | Description                              |
    | ----------------------- | ---------------------------------------- |
    | `X-RateLimit-Limit`     | Limit per window (100)                   |
    | `X-RateLimit-Remaining` | Remaining requests                       |
    | `X-RateLimit-Reset`     | Unix timestamp of the window reset       |
    | `Retry-After`           | Seconds until reset (only when exceeded) |
  </Accordion>
</AccordionGroup>

***

## Response Format

All responses follow the standard envelope:

**Success (single item):**

```json theme={"system"}
{
  "data": { ... }
}
```

**Success (list with pagination):**

```json theme={"system"}
{
  "data": [ ... ],
  "pagination": {
    "page": 1,
    "pageSize": 20,
    "total": 142,
    "totalPages": 8
  }
}
```

**Error:**

```json theme={"system"}
{
  "error": "descriptive error message",
  "code": "NOT_FOUND"
}
```

***

## Health

Health check endpoints do not require authentication.

### GET /healthz

Checks whether the server is alive.

<ParamField header="Authorization" type="none">
  No authentication required.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "status": "ok",
  "timestamp": "2026-03-19T14:30:00Z"
}
```

```bash theme={"system"}
curl http://localhost:8090/healthz
```

### GET /readyz

Checks whether the server is ready to receive traffic (connected to the cluster, reconcilers active).

**Response `200 OK`:**

```json theme={"system"}
{
  "status": "ready",
  "checks": {
    "kubernetes": "connected",
    "reconcilers": "running",
    "grpc_server": "listening"
  },
  "timestamp": "2026-03-19T14:30:00Z"
}
```

**Response `503 Service Unavailable`:**

```json theme={"system"}
{
  "status": "not_ready",
  "checks": {
    "kubernetes": "connected",
    "reconcilers": "starting",
    "grpc_server": "not_listening"
  },
  "timestamp": "2026-03-19T14:30:00Z"
}
```

```bash theme={"system"}
curl http://localhost:8090/readyz
```

***

## Incidents

Management of incidents detected by the AIOps pipeline.

### GET /api/v1/incidents

Lists all incidents with filters and pagination.

**Minimum role:** `viewer`

<ParamField query="severity" type="string">
  Filter by severity. Values: `critical`, `high`, `medium`, `low`.
</ParamField>

<ParamField query="state" type="string">
  Filter by state. Values: `detected`, `analyzing`, `remediating`, `resolved`, `escalated`.
</ParamField>

<ParamField query="namespace" type="string">
  Filter by Kubernetes namespace.
</ParamField>

<ParamField query="page" type="integer" default="1">
  Page number.
</ParamField>

<ParamField query="pageSize" type="integer" default="20">
  Items per page. Maximum: 100.
</ParamField>

<ParamField query="from" type="string">
  Start date/time in ISO 8601 format. E.g.: `2026-03-01T00:00:00Z`.
</ParamField>

<ParamField query="to" type="string">
  End date/time in ISO 8601 format.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": [
    {
      "name": "issue-crashloop-api-server-production",
      "namespace": "production",
      "state": "remediating",
      "severity": "critical",
      "riskScore": 75,
      "signalType": "pod_restart",
      "resource": {
        "kind": "Deployment",
        "name": "api-server"
      },
      "description": "Pod api-server-7d4f8b6c9-x2k4m in CrashLoopBackOff (15 restarts)",
      "detectedAt": "2026-03-19T14:10:00Z",
      "acknowledgedAt": null,
      "resolvedAt": null,
      "remediationAttempts": 1,
      "maxRemediationAttempts": 5,
      "labels": {
        "platform.chatcli.io/signal": "pod_restart",
        "platform.chatcli.io/severity": "critical"
      }
    }
  ],
  "pagination": {
    "page": 1,
    "pageSize": 20,
    "total": 42,
    "totalPages": 3
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/incidents?severity=critical&state=remediating&page=1&pageSize=10"
```

### GET /api/v1/incidents/:name

Returns complete details for a specific incident.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  Incident name (Issue CR name).
</ParamField>

<ParamField query="namespace" type="string" default="default">
  Incident namespace.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "issue-crashloop-api-server-production",
    "namespace": "production",
    "state": "remediating",
    "severity": "critical",
    "riskScore": 75,
    "signalType": "pod_restart",
    "resource": {
      "kind": "Deployment",
      "name": "api-server"
    },
    "description": "Pod api-server-7d4f8b6c9-x2k4m in CrashLoopBackOff (15 restarts)",
    "detectedAt": "2026-03-19T14:10:00Z",
    "acknowledgedAt": null,
    "resolvedAt": null,
    "remediationAttempts": 1,
    "maxRemediationAttempts": 5,
    "analysis": {
      "rootCause": "OOM Kill caused by a memory leak in the /api/v1/export handler",
      "confidence": 0.92,
      "recommendations": [
        "Increase memory limit to 1Gi",
        "Investigate the /api/v1/export endpoint for a memory leak",
        "Add pprof profiling"
      ],
      "provider": "claude",
      "model": "claude-sonnet-4-20250514"
    },
    "remediationPlan": {
      "name": "plan-issue-crashloop-api-server-production-1",
      "state": "executing",
      "agenticMode": false,
      "actions": [
        {
          "name": "adjust-memory",
          "type": "AdjustResources",
          "params": {"memory_limit": "1Gi", "memory_request": "512Mi"},
          "result": "pending"
        }
      ]
    },
    "anomalies": [
      "anomaly-pod-restart-api-server-production-a1b2c3",
      "anomaly-oom-kill-api-server-production-d4e5f6"
    ],
    "labels": {
      "platform.chatcli.io/signal": "pod_restart",
      "platform.chatcli.io/severity": "critical",
      "platform.chatcli.io/incident-id": "abc123def456"
    }
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/incidents/issue-crashloop-api-server-production?namespace=production"
```

### POST /api/v1/incidents/:name/acknowledge

Marks an incident as acknowledged.

**Minimum role:** `operator`

<ParamField path="name" type="string" required>
  Incident name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "issue-crashloop-api-server-production",
    "state": "remediating",
    "acknowledgedAt": "2026-03-19T14:35:00Z",
    "acknowledgedBy": "operator:ops-key-abc123"
  }
}
```

```bash theme={"system"}
curl -X POST -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/incidents/issue-crashloop-api-server-production/acknowledge"
```

### POST /api/v1/incidents/:name/snooze

Suspends notifications for an incident for a specified duration.

**Minimum role:** `operator`

<ParamField path="name" type="string" required>
  Incident name.
</ParamField>

<ParamField body="duration" type="string" required>
  Snooze duration. Go duration format: `30m`, `1h`, `2h30m`, `24h`.
</ParamField>

**Request body:**

```json theme={"system"}
{
  "duration": "1h"
}
```

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "issue-crashloop-api-server-production",
    "snoozedUntil": "2026-03-19T15:35:00Z",
    "snoozeDuration": "1h"
  }
}
```

```bash theme={"system"}
curl -X POST -H "X-API-Key: ops-key-abc123" \
  -H "Content-Type: application/json" \
  -d '{"duration": "1h"}' \
  "http://localhost:8090/api/v1/incidents/issue-crashloop-api-server-production/snooze"
```

### GET /api/v1/incidents/:name/timeline

Returns the complete timeline of an incident — from detection to resolution.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  Incident name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "issue-crashloop-api-server-production",
    "events": [
      {
        "timestamp": "2026-03-19T14:10:00Z",
        "type": "detected",
        "description": "Anomaly detected: CrashLoopBackOff on pod api-server-7d4f8b6c9-x2k4m"
      },
      {
        "timestamp": "2026-03-19T14:10:12Z",
        "type": "correlated",
        "description": "Correlated with OOM Kill anomaly — risk score updated to 75 (Critical)"
      },
      {
        "timestamp": "2026-03-19T14:10:30Z",
        "type": "analysis_started",
        "description": "AIInsight created — AI analysis started (claude/claude-sonnet-4-20250514)"
      },
      {
        "timestamp": "2026-03-19T14:11:05Z",
        "type": "analysis_completed",
        "description": "Root cause identified: OOM Kill due to memory leak (confidence: 0.92)"
      },
      {
        "timestamp": "2026-03-19T14:11:10Z",
        "type": "remediation_started",
        "description": "RemediationPlan created: AdjustResources (memory_limit: 1Gi)"
      },
      {
        "timestamp": "2026-03-19T14:11:45Z",
        "type": "action_executed",
        "description": "AdjustResources executed successfully — deployment updated"
      },
      {
        "timestamp": "2026-03-19T14:13:00Z",
        "type": "resolved",
        "description": "Incident resolved automatically — pods healthy"
      }
    ],
    "duration": "2m60s"
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/incidents/issue-crashloop-api-server-production/timeline"
```

### GET /api/v1/incidents/:name/remediation

Returns remediation details for an incident, including the plan, executed actions, and results.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  Incident name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "incidentName": "issue-crashloop-api-server-production",
    "plans": [
      {
        "name": "plan-issue-crashloop-api-server-production-1",
        "state": "completed",
        "agenticMode": false,
        "runbookRef": "auto-pod-restart-critical-deployment",
        "actions": [
          {
            "name": "adjust-memory",
            "type": "AdjustResources",
            "description": "Increase memory limit to 1Gi",
            "params": {"memory_limit": "1Gi", "memory_request": "512Mi"},
            "result": "success",
            "executedAt": "2026-03-19T14:11:45Z",
            "preflightSnapshot": {
              "memory_limit": "256Mi",
              "memory_request": "128Mi"
            }
          }
        ],
        "startedAt": "2026-03-19T14:11:10Z",
        "completedAt": "2026-03-19T14:13:00Z"
      }
    ],
    "totalAttempts": 1,
    "maxAttempts": 3
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/incidents/issue-crashloop-api-server-production/remediation"
```

***

## SLOs

Management of Service Level Objectives.

### GET /api/v1/slos

Lists all configured SLOs.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": [
    {
      "name": "api-availability",
      "namespace": "production",
      "target": 99.9,
      "current": 99.85,
      "window": "30d",
      "sliType": "availability",
      "service": "api-server",
      "state": "at_risk",
      "burnRate": {
        "1h": 2.4,
        "6h": 1.8,
        "24h": 1.2,
        "72h": 0.9
      }
    },
    {
      "name": "api-latency-p99",
      "namespace": "production",
      "target": 99.0,
      "current": 99.45,
      "window": "30d",
      "sliType": "latency",
      "service": "api-server",
      "state": "healthy",
      "burnRate": {
        "1h": 0.3,
        "6h": 0.5,
        "24h": 0.4,
        "72h": 0.3
      }
    }
  ]
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/slos"
```

### GET /api/v1/slos/:name

Returns details for a specific SLO.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  SLO name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "api-availability",
    "namespace": "production",
    "target": 99.9,
    "current": 99.85,
    "window": "30d",
    "sliType": "availability",
    "service": "api-server",
    "state": "at_risk",
    "errorBudget": {
      "total": 43.2,
      "remaining": 8.6,
      "consumed": 34.6,
      "consumedPercent": 80.1
    },
    "burnRate": {
      "1h": 2.4,
      "6h": 1.8,
      "24h": 1.2,
      "72h": 0.9
    },
    "alerts": [
      {
        "window": "1h",
        "burnRate": 2.4,
        "threshold": 14.4,
        "firing": false
      },
      {
        "window": "6h",
        "burnRate": 1.8,
        "threshold": 6.0,
        "firing": false
      }
    ],
    "history": [
      {"date": "2026-03-18", "value": 99.92},
      {"date": "2026-03-17", "value": 99.97},
      {"date": "2026-03-16", "value": 99.88}
    ]
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/slos/api-availability"
```

### GET /api/v1/slos/:name/budget

Returns the detailed error budget for an SLO.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  SLO name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "api-availability",
    "target": 99.9,
    "window": "30d",
    "budget": {
      "totalMinutes": 43.2,
      "remainingMinutes": 8.6,
      "consumedMinutes": 34.6,
      "consumedPercent": 80.1,
      "projectedExhaustion": "2026-03-22T06:00:00Z",
      "burnRateMultiple": 1.8,
      "recommendation": "Error budget 80% consumed. Consider freezing deploys until recovery."
    }
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/slos/api-availability/budget"
```

***

## Runbooks

CRUD for remediation runbooks.

### GET /api/v1/runbooks

Lists all available runbooks.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": [
    {
      "name": "restart-on-crashloop",
      "namespace": "chatcli-system",
      "description": "Restarts deployment in CrashLoopBackOff",
      "trigger": {
        "signalType": "pod_restart",
        "severity": "high",
        "resourceKind": "Deployment"
      },
      "steps": [
        {
          "name": "restart-deployment",
          "action": "RestartDeployment",
          "description": "Restarts the affected deployment"
        }
      ],
      "autoGenerated": false,
      "timesUsed": 12,
      "lastUsedAt": "2026-03-18T20:15:00Z"
    },
    {
      "name": "auto-pod-restart-critical-deployment",
      "namespace": "chatcli-system",
      "description": "Runbook auto-generated by AI for pod_restart/Critical/Deployment",
      "trigger": {
        "signalType": "pod_restart",
        "severity": "critical",
        "resourceKind": "Deployment"
      },
      "steps": [
        {
          "name": "adjust-memory",
          "action": "AdjustResources",
          "description": "Increase memory limit",
          "params": {"memory_limit": "1Gi", "memory_request": "512Mi"}
        }
      ],
      "autoGenerated": true,
      "timesUsed": 3,
      "lastUsedAt": "2026-03-19T14:13:00Z",
      "labels": {
        "platform.chatcli.io/auto-generated": "true"
      }
    }
  ]
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/runbooks"
```

### GET /api/v1/runbooks/:name

Returns details for a specific runbook.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  Runbook name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "restart-on-crashloop",
    "namespace": "chatcli-system",
    "description": "Restarts deployment in CrashLoopBackOff",
    "trigger": {
      "signalType": "pod_restart",
      "severity": "high",
      "resourceKind": "Deployment"
    },
    "steps": [
      {
        "name": "restart-deployment",
        "action": "RestartDeployment",
        "description": "Restarts the affected deployment"
      }
    ],
    "approvalRequired": false,
    "autoGenerated": false,
    "createdAt": "2026-02-15T10:00:00Z",
    "updatedAt": "2026-03-01T08:30:00Z",
    "timesUsed": 12,
    "lastUsedAt": "2026-03-18T20:15:00Z"
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/runbooks/restart-on-crashloop"
```

### POST /api/v1/runbooks

Creates a new runbook.

**Minimum role:** `admin`

**Request body:**

```json theme={"system"}
{
  "name": "scale-on-high-cpu",
  "namespace": "chatcli-system",
  "description": "Scales deployment when CPU is high",
  "trigger": {
    "signalType": "latency_spike",
    "severity": "high",
    "resourceKind": "Deployment"
  },
  "steps": [
    {
      "name": "scale-up",
      "action": "ScaleDeployment",
      "description": "Increases replicas to 5",
      "params": {"replicas": "5"}
    }
  ],
  "approvalRequired": true
}
```

**Response `201 Created`:**

```json theme={"system"}
{
  "data": {
    "name": "scale-on-high-cpu",
    "namespace": "chatcli-system",
    "createdAt": "2026-03-19T15:00:00Z",
    "message": "Runbook created successfully"
  }
}
```

```bash theme={"system"}
curl -X POST -H "X-API-Key: admin-key-root01" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "scale-on-high-cpu",
    "namespace": "chatcli-system",
    "description": "Scales deployment when CPU is high",
    "trigger": {
      "signalType": "latency_spike",
      "severity": "high",
      "resourceKind": "Deployment"
    },
    "steps": [
      {
        "name": "scale-up",
        "action": "ScaleDeployment",
        "description": "Increases replicas to 5",
        "params": {"replicas": "5"}
      }
    ],
    "approvalRequired": true
  }' \
  "http://localhost:8090/api/v1/runbooks"
```

### PUT /api/v1/runbooks/:name

Updates an existing runbook.

**Minimum role:** `admin`

<ParamField path="name" type="string" required>
  Name of the runbook to update.
</ParamField>

**Request body:** Same format as POST (full RunbookSpec body).

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "scale-on-high-cpu",
    "namespace": "chatcli-system",
    "updatedAt": "2026-03-19T16:00:00Z",
    "message": "Runbook updated successfully"
  }
}
```

```bash theme={"system"}
curl -X PUT -H "X-API-Key: admin-key-root01" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "scale-on-high-cpu",
    "namespace": "chatcli-system",
    "description": "Scales deployment when CPU is high (updated)",
    "trigger": {
      "signalType": "latency_spike",
      "severity": "high",
      "resourceKind": "Deployment"
    },
    "steps": [
      {
        "name": "scale-up",
        "action": "ScaleDeployment",
        "description": "Increases replicas to 8",
        "params": {"replicas": "8"}
      }
    ],
    "approvalRequired": false
  }' \
  "http://localhost:8090/api/v1/runbooks/scale-on-high-cpu"
```

### DELETE /api/v1/runbooks/:name

Removes a runbook.

**Minimum role:** `admin`

<ParamField path="name" type="string" required>
  Name of the runbook to remove.
</ParamField>

<Warning>
  Auto-generated runbooks (`platform.chatcli.io/auto-generated=true`) may be recreated automatically by the AI in future remediations.
</Warning>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "scale-on-high-cpu",
    "message": "Runbook removed successfully"
  }
}
```

```bash theme={"system"}
curl -X DELETE -H "X-API-Key: admin-key-root01" \
  "http://localhost:8090/api/v1/runbooks/scale-on-high-cpu"
```

***

## Approvals

Management of approvals for actions that require human intervention.

### GET /api/v1/approvals

Lists pending or historical approvals.

**Minimum role:** `viewer`

<ParamField query="state" type="string">
  Filter by state. Values: `pending`, `approved`, `rejected`, `expired`.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": [
    {
      "name": "approval-custom-action-api-server-production",
      "namespace": "production",
      "state": "pending",
      "incidentRef": "issue-crashloop-api-server-production",
      "action": {
        "type": "Custom",
        "description": "Run schema migration script",
        "params": {"script": "/opt/scripts/migrate.sh"}
      },
      "requestedAt": "2026-03-19T14:20:00Z",
      "expiresAt": "2026-03-19T15:20:00Z",
      "requestedBy": "ai-insight-controller"
    }
  ]
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/approvals?state=pending"
```

### GET /api/v1/approvals/:name

Returns details for a specific approval.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  Approval name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "approval-custom-action-api-server-production",
    "namespace": "production",
    "state": "pending",
    "incidentRef": "issue-crashloop-api-server-production",
    "action": {
      "type": "Custom",
      "description": "Run schema migration script",
      "params": {"script": "/opt/scripts/migrate.sh"}
    },
    "context": {
      "severity": "critical",
      "riskScore": 85,
      "aiConfidence": 0.78,
      "aiReasoning": "Outdated schema causing ORM failures. Migration resolves the issue."
    },
    "requestedAt": "2026-03-19T14:20:00Z",
    "expiresAt": "2026-03-19T15:20:00Z",
    "requestedBy": "ai-insight-controller",
    "decision": null
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/approvals/approval-custom-action-api-server-production"
```

### POST /api/v1/approvals/:name/approve

Approves a pending action.

**Minimum role:** `operator`

<ParamField path="name" type="string" required>
  Approval name.
</ParamField>

<ParamField body="approver" type="string" required>
  Identifier of the approver.
</ParamField>

<ParamField body="reason" type="string">
  Reason for approval.
</ParamField>

**Request body:**

```json theme={"system"}
{
  "approver": "sre-team:joao.silva",
  "reason": "Migration script reviewed and tested in staging"
}
```

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "approval-custom-action-api-server-production",
    "state": "approved",
    "decision": {
      "approver": "sre-team:joao.silva",
      "reason": "Migration script reviewed and tested in staging",
      "decidedAt": "2026-03-19T14:25:00Z"
    }
  }
}
```

```bash theme={"system"}
curl -X POST -H "X-API-Key: ops-key-abc123" \
  -H "Content-Type: application/json" \
  -d '{"approver": "sre-team:joao.silva", "reason": "Script reviewed and tested in staging"}' \
  "http://localhost:8090/api/v1/approvals/approval-custom-action-api-server-production/approve"
```

### POST /api/v1/approvals/:name/reject

Rejects a pending action.

**Minimum role:** `operator`

<ParamField path="name" type="string" required>
  Approval name.
</ParamField>

<ParamField body="approver" type="string" required>
  Identifier of the rejecter.
</ParamField>

<ParamField body="reason" type="string" required>
  Reason for rejection.
</ParamField>

**Request body:**

```json theme={"system"}
{
  "approver": "sre-team:joao.silva",
  "reason": "Script not adequately tested. Needs validation in staging."
}
```

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "approval-custom-action-api-server-production",
    "state": "rejected",
    "decision": {
      "approver": "sre-team:joao.silva",
      "reason": "Script not adequately tested. Needs validation in staging.",
      "decidedAt": "2026-03-19T14:25:00Z"
    }
  }
}
```

```bash theme={"system"}
curl -X POST -H "X-API-Key: ops-key-abc123" \
  -H "Content-Type: application/json" \
  -d '{"approver": "sre-team:joao.silva", "reason": "Script not adequately tested."}' \
  "http://localhost:8090/api/v1/approvals/approval-custom-action-api-server-production/reject"
```

***

## PostMortems

Querying and management of automatically generated post-mortems.

### GET /api/v1/postmortems

Lists all post-mortems.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": [
    {
      "name": "postmortem-issue-crashloop-api-server-production",
      "namespace": "production",
      "state": "open",
      "incidentRef": "issue-crashloop-api-server-production",
      "summary": "OOM Kill caused CrashLoopBackOff on api-server. Resolved by adjusting memory limits.",
      "duration": "2m60s",
      "createdAt": "2026-03-19T14:13:00Z",
      "source": "agentic"
    }
  ]
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/postmortems"
```

### GET /api/v1/postmortems/:name

Returns complete details for a post-mortem.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  Post-mortem name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "postmortem-issue-crashloop-api-server-production",
    "namespace": "production",
    "state": "open",
    "incidentRef": "issue-crashloop-api-server-production",
    "summary": "OOM Kill caused CrashLoopBackOff on api-server. Resolved by adjusting memory limits.",
    "rootCause": "A memory leak in the /api/v1/export handler caused continuous heap growth until hitting the 256Mi limit, resulting in an OOM Kill by the kernel.",
    "impact": "Partial unavailability of api-server for 3 minutes. 2 pods affected out of 3 replicas.",
    "timeline": [
      {"timestamp": "2026-03-19T14:10:00Z", "event": "Anomaly detected: CrashLoopBackOff"},
      {"timestamp": "2026-03-19T14:10:12Z", "event": "Correlation with OOM Kill — Issue created (Critical)"},
      {"timestamp": "2026-03-19T14:11:05Z", "event": "AI analysis: memory leak identified (confidence: 0.92)"},
      {"timestamp": "2026-03-19T14:11:45Z", "event": "AdjustResources executed: memory_limit 256Mi -> 1Gi"},
      {"timestamp": "2026-03-19T14:13:00Z", "event": "Pods healthy — incident resolved"}
    ],
    "actionsExecuted": [
      {
        "action": "AdjustResources",
        "params": {"memory_limit": "1Gi", "memory_request": "512Mi"},
        "result": "success"
      }
    ],
    "lessonsLearned": [
      "Memory limits should account for usage spikes, not just average consumption",
      "The /api/v1/export endpoint needs streaming to avoid accumulating in memory"
    ],
    "preventionActions": [
      "Implement continuous pprof profiling",
      "Add an alert for memory usage > 80% of the limit",
      "Refactor /api/v1/export to use streaming"
    ],
    "duration": "2m60s",
    "createdAt": "2026-03-19T14:13:00Z",
    "source": "agentic"
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/postmortems/postmortem-issue-crashloop-api-server-production"
```

### POST /api/v1/postmortems/:name/review

Marks a post-mortem as under review.

**Minimum role:** `operator`

<ParamField path="name" type="string" required>
  Post-mortem name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "postmortem-issue-crashloop-api-server-production",
    "state": "in_review",
    "reviewStartedAt": "2026-03-19T16:00:00Z"
  }
}
```

```bash theme={"system"}
curl -X POST -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/postmortems/postmortem-issue-crashloop-api-server-production/review"
```

### POST /api/v1/postmortems/:name/close

Closes a post-mortem after review.

**Minimum role:** `operator`

<ParamField path="name" type="string" required>
  Post-mortem name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "postmortem-issue-crashloop-api-server-production",
    "state": "closed",
    "closedAt": "2026-03-19T17:00:00Z"
  }
}
```

```bash theme={"system"}
curl -X POST -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/postmortems/postmortem-issue-crashloop-api-server-production/close"
```

***

## Analytics

Aggregated metrics and trends for the AIOps platform.

### GET /api/v1/analytics/summary

Returns a general summary of the platform.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "totalIncidents": 342,
    "activeIncidents": 5,
    "resolvedIncidents": 312,
    "escalatedIncidents": 25,
    "autoRemediatedPercent": 91.2,
    "avgResolutionTime": "4m32s",
    "incidentsBySeverity": {
      "critical": 48,
      "high": 112,
      "medium": 134,
      "low": 48
    },
    "incidentsByState": {
      "detected": 1,
      "analyzing": 2,
      "remediating": 2,
      "resolved": 312,
      "escalated": 25
    },
    "topSignals": [
      {"signal": "pod_restart", "count": 98},
      {"signal": "oom_kill", "count": 76},
      {"signal": "error_rate", "count": 65},
      {"signal": "latency_spike", "count": 58},
      {"signal": "deploy_failing", "count": 45}
    ],
    "period": "30d"
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/analytics/summary"
```

### GET /api/v1/analytics/mttd

Returns the Mean Time to Detect.

**Minimum role:** `viewer`

<ParamField query="window" type="string" default="30d">
  Time window. Values: `7d`, `14d`, `30d`, `90d`.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "mttd": "12s",
    "mttdSeconds": 12.4,
    "window": "30d",
    "samples": 342,
    "trend": "stable",
    "history": [
      {"date": "2026-03-19", "mttdSeconds": 11.2},
      {"date": "2026-03-18", "mttdSeconds": 13.5},
      {"date": "2026-03-17", "mttdSeconds": 12.1}
    ]
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/analytics/mttd?window=30d"
```

### GET /api/v1/analytics/mttr

Returns the Mean Time to Resolve.

**Minimum role:** `viewer`

<ParamField query="window" type="string" default="30d">
  Time window. Values: `7d`, `14d`, `30d`, `90d`.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "mttr": "4m32s",
    "mttrSeconds": 272.0,
    "window": "30d",
    "samples": 312,
    "trend": "improving",
    "bySeverity": {
      "critical": {"mttr": "3m15s", "mttrSeconds": 195.0},
      "high": {"mttr": "4m48s", "mttrSeconds": 288.0},
      "medium": {"mttr": "5m20s", "mttrSeconds": 320.0},
      "low": {"mttr": "6m10s", "mttrSeconds": 370.0}
    },
    "history": [
      {"date": "2026-03-19", "mttrSeconds": 250.0},
      {"date": "2026-03-18", "mttrSeconds": 280.0},
      {"date": "2026-03-17", "mttrSeconds": 265.0}
    ]
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/analytics/mttr?window=30d"
```

### GET /api/v1/analytics/trends

Returns incident trends over time.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "daily": [
      {
        "date": "2026-03-19",
        "total": 8,
        "resolved": 7,
        "escalated": 1,
        "avgResolutionSeconds": 245.0,
        "bySeverity": {"critical": 2, "high": 3, "medium": 2, "low": 1}
      },
      {
        "date": "2026-03-18",
        "total": 12,
        "resolved": 11,
        "escalated": 1,
        "avgResolutionSeconds": 310.0,
        "bySeverity": {"critical": 3, "high": 4, "medium": 3, "low": 2}
      }
    ],
    "window": "30d"
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/analytics/trends"
```

### GET /api/v1/analytics/top-resources

Returns the resources with the most incidents.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "resources": [
      {
        "kind": "Deployment",
        "name": "api-server",
        "namespace": "production",
        "incidentCount": 28,
        "lastIncident": "2026-03-19T14:10:00Z",
        "topSignals": ["pod_restart", "oom_kill"],
        "avgResolutionSeconds": 195.0
      },
      {
        "kind": "Deployment",
        "name": "payment-service",
        "namespace": "production",
        "incidentCount": 15,
        "lastIncident": "2026-03-18T22:30:00Z",
        "topSignals": ["error_rate", "latency_spike"],
        "avgResolutionSeconds": 340.0
      }
    ],
    "window": "30d",
    "limit": 10
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/analytics/top-resources"
```

### GET /api/v1/analytics/remediation-stats

Returns remediation statistics.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "total": 337,
    "successful": 312,
    "failed": 25,
    "successRate": 92.6,
    "byType": {
      "RestartDeployment": {"total": 98, "successful": 95, "rate": 96.9},
      "AdjustResources": {"total": 76, "successful": 72, "rate": 94.7},
      "RollbackDeployment": {"total": 52, "successful": 48, "rate": 92.3},
      "ScaleDeployment": {"total": 45, "successful": 43, "rate": 95.6},
      "DeletePod": {"total": 38, "successful": 36, "rate": 94.7},
      "PatchConfig": {"total": 18, "successful": 14, "rate": 77.8},
      "Agentic": {"total": 10, "successful": 4, "rate": 40.0}
    },
    "avgDurationSeconds": 85.2,
    "durationPercentiles": {
      "p50": 62.0,
      "p90": 180.0,
      "p99": 420.0
    },
    "window": "30d"
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/analytics/remediation-stats"
```

***

## Clusters

Information about managed Kubernetes clusters.

### GET /api/v1/clusters

Lists all monitored clusters.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": [
    {
      "name": "production-us-east-1",
      "status": "healthy",
      "provider": "EKS",
      "version": "1.29",
      "nodes": 12,
      "activeIncidents": 2,
      "instanceRef": "chatcli-production",
      "lastSyncAt": "2026-03-19T14:30:00Z"
    },
    {
      "name": "staging-eu-west-1",
      "status": "degraded",
      "provider": "EKS",
      "version": "1.29",
      "nodes": 4,
      "activeIncidents": 5,
      "instanceRef": "chatcli-staging",
      "lastSyncAt": "2026-03-19T14:29:55Z"
    }
  ]
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/clusters"
```

### GET /api/v1/clusters/:name

Returns details for a specific cluster.

**Minimum role:** `viewer`

<ParamField path="name" type="string" required>
  Cluster name.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "name": "production-us-east-1",
    "status": "healthy",
    "provider": "EKS",
    "version": "1.29",
    "nodes": 12,
    "activeIncidents": 2,
    "instanceRef": "chatcli-production",
    "namespaces": ["production", "staging", "monitoring", "kube-system"],
    "watcherTargets": [
      {"namespace": "production", "deployments": 15, "alertsActive": 2},
      {"namespace": "staging", "deployments": 8, "alertsActive": 0}
    ],
    "resources": {
      "cpuCapacity": "48 cores",
      "cpuUsage": "32 cores",
      "memoryCapacity": "192Gi",
      "memoryUsage": "128Gi"
    },
    "lastSyncAt": "2026-03-19T14:30:00Z"
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/clusters/production-us-east-1"
```

### GET /api/v1/clusters/global-status

Returns the global status of all clusters.

**Minimum role:** `viewer`

**Response `200 OK`:**

```json theme={"system"}
{
  "data": {
    "totalClusters": 3,
    "healthy": 2,
    "degraded": 1,
    "unreachable": 0,
    "totalNodes": 20,
    "totalActiveIncidents": 7,
    "clusters": [
      {"name": "production-us-east-1", "status": "healthy", "activeIncidents": 2},
      {"name": "staging-eu-west-1", "status": "degraded", "activeIncidents": 5},
      {"name": "dev-local", "status": "healthy", "activeIncidents": 0}
    ]
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/clusters/global-status"
```

***

## Audit

Audit log of all actions on the platform.

### GET /api/v1/audit

Lists audit events with filters.

**Minimum role:** `viewer`

<ParamField query="type" type="string">
  Event type. Values: `incident.created`, `incident.acknowledged`, `incident.resolved`, `incident.escalated`, `remediation.executed`, `remediation.failed`, `approval.approved`, `approval.rejected`, `runbook.created`, `runbook.deleted`, `api.access`.
</ParamField>

<ParamField query="severity" type="string">
  Filter by audit event severity. Values: `info`, `warning`, `critical`.
</ParamField>

<ParamField query="resource" type="string">
  Filter by affected resource name.
</ParamField>

<ParamField query="from" type="string">
  Start date/time (ISO 8601).
</ParamField>

<ParamField query="to" type="string">
  End date/time (ISO 8601).
</ParamField>

<ParamField query="page" type="integer" default="1">
  Page number.
</ParamField>

<ParamField query="pageSize" type="integer" default="50">
  Items per page. Maximum: 200.
</ParamField>

**Response `200 OK`:**

```json theme={"system"}
{
  "data": [
    {
      "id": "audit-20260319-143500-001",
      "timestamp": "2026-03-19T14:35:00Z",
      "type": "incident.acknowledged",
      "severity": "info",
      "actor": "operator:ops-key-abc123",
      "resource": "issue-crashloop-api-server-production",
      "namespace": "production",
      "description": "Incident acknowledged by the operator",
      "metadata": {
        "incidentState": "remediating",
        "incidentSeverity": "critical"
      }
    },
    {
      "id": "audit-20260319-141145-001",
      "timestamp": "2026-03-19T14:11:45Z",
      "type": "remediation.executed",
      "severity": "warning",
      "actor": "system:remediation-controller",
      "resource": "plan-issue-crashloop-api-server-production-1",
      "namespace": "production",
      "description": "AdjustResources executed: memory_limit 256Mi -> 1Gi",
      "metadata": {
        "actionType": "AdjustResources",
        "result": "success",
        "deployment": "api-server"
      }
    }
  ],
  "pagination": {
    "page": 1,
    "pageSize": 50,
    "total": 1247,
    "totalPages": 25
  }
}
```

```bash theme={"system"}
curl -H "X-API-Key: ops-key-abc123" \
  "http://localhost:8090/api/v1/audit?type=remediation.executed&from=2026-03-19T00:00:00Z&pageSize=20"
```

### GET /api/v1/audit/export

Exports the complete audit log in CSV or JSON format.

**Minimum role:** `admin`

<ParamField query="format" type="string" default="json">
  Export format. Values: `json`, `csv`.
</ParamField>

<ParamField query="from" type="string">
  Start date/time (ISO 8601).
</ParamField>

<ParamField query="to" type="string">
  End date/time (ISO 8601).
</ParamField>

**Response `200 OK` (JSON):**

```json theme={"system"}
{
  "data": {
    "exportedAt": "2026-03-19T15:00:00Z",
    "totalRecords": 1247,
    "format": "json",
    "records": [
      {
        "id": "audit-20260319-143500-001",
        "timestamp": "2026-03-19T14:35:00Z",
        "type": "incident.acknowledged",
        "severity": "info",
        "actor": "operator:ops-key-abc123",
        "resource": "issue-crashloop-api-server-production",
        "namespace": "production",
        "description": "Incident acknowledged by the operator"
      }
    ]
  }
}
```

**Response `200 OK` (CSV):**

The `Content-Type` header will be `text/csv` and the body will contain the CSV with columns:
`id,timestamp,type,severity,actor,resource,namespace,description`

```bash theme={"system"}
# Export as JSON
curl -H "X-API-Key: admin-key-root01" \
  "http://localhost:8090/api/v1/audit/export?format=json&from=2026-03-01T00:00:00Z" \
  -o audit-export.json

# Export as CSV
curl -H "X-API-Key: admin-key-root01" \
  "http://localhost:8090/api/v1/audit/export?format=csv&from=2026-03-01T00:00:00Z" \
  -o audit-export.csv
```

***

## Error Codes

| HTTP Code | Code                  | Description                                                |
| --------- | --------------------- | ---------------------------------------------------------- |
| `400`     | `BAD_REQUEST`         | Invalid parameter or malformed body                        |
| `401`     | `UNAUTHORIZED`        | Missing or invalid API key                                 |
| `403`     | `FORBIDDEN`           | Insufficient role for the operation                        |
| `404`     | `NOT_FOUND`           | Resource not found                                         |
| `409`     | `CONFLICT`            | Resource already exists (e.g.: runbook with the same name) |
| `429`     | `RATE_LIMITED`        | Rate limit exceeded                                        |
| `500`     | `INTERNAL_ERROR`      | Internal server error                                      |
| `503`     | `SERVICE_UNAVAILABLE` | Server is not ready (readyz failed)                        |

***

## SDKs and Integration

<CardGroup cols={2}>
  <Card title="curl" icon="terminal">
    All examples on this page use `curl`. Copy and adapt.
  </Card>

  <Card title="Go Client" icon="golang">
    Use the `operator/pkg/client` package for native Go integration.
  </Card>

  <Card title="Webhook" icon="webhook">
    Configure webhook notifications in the Instance CR (`spec.notifications`).
  </Card>

  <Card title="Grafana" icon="chart-mixed">
    See [Web Dashboard and Grafana](/features/aiops/web-dashboard) for pre-configured dashboards.
  </Card>
</CardGroup>
