{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/latitude-so/json-schema/latitude-so-paginated-monitors-schema.json",
  "title": "PaginatedMonitors",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/latitude-so-monitors-api-openapi.yml#/components/schemas/PaginatedMonitors",
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Monitor"
      },
      "description": "Page of items, in the requested sort order."
    },
    "nextCursor": {
      "type": [
        "string",
        "null"
      ],
      "description": "Opaque cursor for fetching the next page. `null` when there are no more pages. Pass it back in `cursor` to continue."
    },
    "hasMore": {
      "type": "boolean",
      "description": "`true` when there is at least one more page after this one."
    }
  },
  "required": [
    "items",
    "nextCursor",
    "hasMore"
  ],
  "$defs": {
    "AlertBaseline": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "average",
            "period"
          ],
          "description": "How the comparison rate is computed. `average` is the rolling rate over the last `lookback`; `period` is the equal-length window immediately before it (e.g. `lookback` of 1 day compares against yesterday) for daily/weekly seasonality."
        },
        "lookback": {
          "$ref": "#/$defs/AlertDuration"
        }
      },
      "required": [
        "kind",
        "lookback"
      ],
      "description": "Fixed-window baseline the current rate is compared against."
    },
    "AlertCondition": {
      "oneOf": [
        {
          "$ref": "#/$defs/AlertThresholdCondition"
        },
        {
          "$ref": "#/$defs/AlertEscalatingCondition"
        }
      ],
      "description": "Condition that controls threshold or escalating incidents."
    },
    "AlertDuration": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "unit": {
              "type": "string",
              "enum": [
                "minutes"
              ],
              "description": "The duration is expressed in whole minutes; read `minutes`."
            },
            "minutes": {
              "type": "number",
              "minimum": 0,
              "exclusiveMinimum": true,
              "description": "Number of minutes."
            }
          },
          "required": [
            "unit",
            "minutes"
          ]
        },
        {
          "type": "object",
          "properties": {
            "unit": {
              "type": "string",
              "enum": [
                "hours"
              ],
              "description": "The duration is expressed in whole hours; read `hours`."
            },
            "hours": {
              "type": "number",
              "minimum": 0,
              "exclusiveMinimum": true,
              "description": "Number of hours."
            }
          },
          "required": [
            "unit",
            "hours"
          ]
        },
        {
          "type": "object",
          "properties": {
            "unit": {
              "type": "string",
              "enum": [
                "days"
              ],
              "description": "The duration is expressed in whole days; read `days`."
            },
            "days": {
              "type": "number",
              "minimum": 0,
              "exclusiveMinimum": true,
              "description": "Number of days."
            }
          },
          "required": [
            "unit",
            "days"
          ]
        }
      ],
      "description": "Length of the window used to compute the baseline rate."
    },
    "AlertEscalatingCondition": {
      "type": "object",
      "properties": {
        "trigger": {
          "type": "string",
          "enum": [
            "escalating"
          ],
          "description": "Opens when the monitor target is escalating or sustained."
        },
        "metric": {
          "$ref": "#/$defs/MonitorMetric"
        },
        "threshold": {
          "allOf": [
            {
              "$ref": "#/$defs/AlertMetricThreshold"
            },
            {
              "description": "How the metric is compared when threshold-based."
            }
          ]
        },
        "direction": {
          "type": "string",
          "enum": [
            "above",
            "below"
          ],
          "description": "Direction that opens the incident. Defaults to `above` when omitted."
        },
        "sensitivity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 6,
          "description": "Detector sensitivity from 1 (noisiest) to 6 (strictest). Defaults to 3 when omitted."
        },
        "window": {
          "type": "object",
          "properties": {
            "minutes": {
              "type": "integer",
              "minimum": 5,
              "description": "How long the threshold must stay crossed before the incident opens. Minimum 5."
            }
          },
          "required": [
            "minutes"
          ],
          "description": "Sustained-condition window."
        }
      },
      "required": [
        "trigger",
        "metric",
        "window"
      ]
    },
    "AlertMetricThreshold": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "mode": {
              "type": "string",
              "enum": [
                "absolute"
              ],
              "description": "Compare the metric against a fixed value; read `value`."
            },
            "value": {
              "type": "number",
              "minimum": 0,
              "exclusiveMinimum": true,
              "description": "Metric value that opens the incident."
            }
          },
          "required": [
            "mode",
            "value"
          ]
        },
        {
          "type": "object",
          "properties": {
            "mode": {
              "type": "string",
              "enum": [
                "multiplier"
              ],
              "description": "Compare the metric rate against `factor × baseline`; read `factor` and `baseline`."
            },
            "factor": {
              "type": "number",
              "minimum": 0,
              "exclusiveMinimum": true,
              "description": "Multiple of the baseline rate that opens the incident (e.g. `3` = 3×)."
            },
            "baseline": {
              "$ref": "#/$defs/AlertBaseline"
            }
          },
          "required": [
            "mode",
            "factor",
            "baseline"
          ]
        },
        {
          "type": "object",
          "properties": {
            "mode": {
              "type": "string",
              "enum": [
                "expected"
              ],
              "description": "Compare against the seasonally-learned expected value for this time of day/week."
            },
            "sensitivity": {
              "type": "integer",
              "minimum": 1,
              "maximum": 6,
              "description": "Detector sensitivity from 1 (noisiest) to 6 (strictest). Defaults to 3 when omitted."
            }
          },
          "required": [
            "mode"
          ]
        }
      ],
      "description": "How the metric is compared."
    },
    "AlertThresholdCondition": {
      "type": "object",
      "properties": {
        "trigger": {
          "type": "string",
          "enum": [
            "threshold"
          ],
          "description": "Opens once the measured value crosses the threshold."
        },
        "metric": {
          "$ref": "#/$defs/MonitorMetric"
        },
        "threshold": {
          "$ref": "#/$defs/AlertMetricThreshold"
        },
        "direction": {
          "type": "string",
          "enum": [
            "above",
            "below"
          ],
          "description": "Direction that opens the incident. Defaults to `above` when omitted."
        }
      },
      "required": [
        "trigger",
        "metric",
        "threshold"
      ]
    },
    "FilterCondition": {
      "type": "object",
      "properties": {
        "op": {
          "type": "string",
          "enum": [
            "eq",
            "neq",
            "gt",
            "gte",
            "lt",
            "lte",
            "in",
            "notIn",
            "contains",
            "notContains",
            "gtePercentile"
          ],
          "description": "Comparison operator applied to the field's value (e.g. `eq`, `neq`, `in`). The full operator list lives in the API reference."
        },
        "value": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            },
            {
              "type": "array",
              "items": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  }
                ]
              }
            }
          ],
          "description": "Right-hand value compared against the field. Arrays are required for `in` / `notIn`-style operators."
        }
      },
      "required": [
        "op",
        "value"
      ]
    },
    "Monitor": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 24,
          "maxLength": 24,
          "description": "Stable monitor identifier."
        },
        "organizationId": {
          "type": "string",
          "minLength": 24,
          "maxLength": 24,
          "description": "Organization that owns this monitor."
        },
        "projectId": {
          "type": "string",
          "minLength": 24,
          "maxLength": 24,
          "description": "Project this monitor belongs to."
        },
        "slug": {
          "type": "string",
          "description": "URL-safe slug derived from `name`. Unique within the project."
        },
        "name": {
          "type": "string",
          "description": "Human-readable name."
        },
        "description": {
          "type": "string",
          "description": "Free-form description. Empty string when not set."
        },
        "system": {
          "type": "boolean",
          "description": "`true` for auto-provisioned system monitors, which cannot be deleted or edited; `false` otherwise."
        },
        "target": {
          "$ref": "#/$defs/MonitorTarget"
        },
        "rule": {
          "$ref": "#/$defs/MonitorRule"
        },
        "mutedAt": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 timestamp at which the monitor was muted, or `null` when active."
        },
        "deletedAt": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 timestamp at which the monitor was deleted, or `null`."
        },
        "createdAt": {
          "type": "string",
          "description": "ISO-8601 timestamp of creation."
        },
        "updatedAt": {
          "type": "string",
          "description": "ISO-8601 timestamp of the last update."
        }
      },
      "required": [
        "id",
        "organizationId",
        "projectId",
        "slug",
        "name",
        "description",
        "system",
        "target",
        "rule",
        "mutedAt",
        "deletedAt",
        "createdAt",
        "updatedAt"
      ]
    },
    "MonitorConfig": {
      "type": "object",
      "properties": {
        "filterSet": {
          "allOf": [
            {
              "$ref": "#/$defs/MonitorFilterSet"
            },
            {
              "description": "Filters applied by the monitor rule."
            }
          ]
        },
        "query": {
          "type": [
            "string",
            "null"
          ],
          "description": "Semantic query applied by inline monitor targets."
        },
        "metric": {
          "allOf": [
            {
              "$ref": "#/$defs/MonitorMetric"
            },
            {
              "description": "Metric evaluated by threshold and escalating monitor rules."
            }
          ]
        },
        "condition": {
          "$ref": "#/$defs/AlertCondition"
        }
      },
      "description": "Rule configuration used when the monitor is evaluated."
    },
    "MonitorFilterSet": {
      "type": "object",
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/FilterCondition"
        }
      },
      "description": "Additional filters applied when evaluating the monitor."
    },
    "MonitorMetric": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "count"
              ],
              "description": "Count matching events in each evaluation bucket."
            }
          },
          "required": [
            "kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "errorRate"
              ],
              "description": "Measure the fraction of matching events that errored."
            }
          },
          "required": [
            "kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "cacheHitRate"
              ],
              "description": "Token-weighted prompt-cache hit rate (cache-read tokens over total input-side tokens), a 0..1 fraction."
            }
          },
          "required": [
            "kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "avg"
              ],
              "description": "Average a numeric field over matching events."
            },
            "field": {
              "type": "string",
              "enum": [
                "duration",
                "cost",
                "tokens"
              ],
              "description": "Numeric field to aggregate."
            }
          },
          "required": [
            "kind",
            "field"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "sum"
              ],
              "description": "Sum a numeric field over matching events."
            },
            "field": {
              "type": "string",
              "enum": [
                "duration",
                "cost",
                "tokens"
              ],
              "description": "Numeric field to aggregate."
            }
          },
          "required": [
            "kind",
            "field"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "min"
              ],
              "description": "Find the minimum numeric field value over matching events."
            },
            "field": {
              "type": "string",
              "enum": [
                "duration",
                "cost",
                "tokens"
              ],
              "description": "Numeric field to aggregate."
            }
          },
          "required": [
            "kind",
            "field"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "max"
              ],
              "description": "Find the maximum numeric field value over matching events."
            },
            "field": {
              "type": "string",
              "enum": [
                "duration",
                "cost",
                "tokens"
              ],
              "description": "Numeric field to aggregate."
            }
          },
          "required": [
            "kind",
            "field"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "median"
              ],
              "description": "Find the median numeric field value over matching events."
            },
            "field": {
              "type": "string",
              "enum": [
                "duration",
                "cost",
                "tokens"
              ],
              "description": "Numeric field to aggregate."
            }
          },
          "required": [
            "kind",
            "field"
          ]
        }
      ],
      "description": "Metric measured over the monitor target."
    },
    "MonitorRule": {
      "type": "object",
      "properties": {
        "trigger": {
          "type": "string",
          "enum": [
            "match",
            "threshold",
            "escalating"
          ],
          "description": "When the monitor opens incidents: `match`, `threshold`, or `escalating`."
        },
        "config": {
          "$ref": "#/$defs/MonitorConfig"
        },
        "severity": {
          "type": "string",
          "enum": [
            "low",
            "medium",
            "high",
            "urgent"
          ],
          "description": "Severity of incidents this monitor opens: `low`, `medium`, `high`, or `urgent`."
        }
      },
      "required": [
        "trigger",
        "config",
        "severity"
      ],
      "description": "Single rule evaluated by this monitor."
    },
    "MonitorTarget": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "savedSearch",
            "tool",
            "user",
            "session"
          ],
          "description": "Product target category: `savedSearch`, `tool`, `user`, or `session`."
        },
        "id": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 24,
          "maxLength": 24,
          "description": "Target entity id, or `null` for project-wide targets."
        },
        "filterSet": {
          "$ref": "#/$defs/MonitorFilterSet"
        },
        "query": {
          "type": [
            "string",
            "null"
          ],
          "description": "Semantic query applied when evaluating inline trace targets."
        },
        "kind": {
          "type": "string",
          "enum": [
            "savedSearch",
            "tool",
            "user",
            "session"
          ],
          "description": "Normalized target kind returned on persisted monitors."
        },
        "stream": {
          "type": "string",
          "enum": [
            "traces",
            "spans",
            "sessions"
          ],
          "description": "Telemetry stream evaluated by the monitor."
        },
        "savedSearchId": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 24,
          "maxLength": 24,
          "description": "Saved-search id for saved-search monitors, or `null` for inline targets."
        },
        "metric": {
          "allOf": [
            {
              "$ref": "#/$defs/MonitorMetric"
            },
            {
              "description": "Default metric evaluated for this target."
            }
          ]
        }
      },
      "required": [
        "type",
        "id"
      ],
      "description": "Entity or filter set watched by this monitor."
    }
  }
}