{
  "openapi": "3.1.0",
  "info": {
    "title": "illari Management API",
    "version": "1.0.0",
    "description": "Provision and manage monitors. Your jobs still only call the ping URL; this API is for setup and automation (CI, scripts, coding agents, monitors as code). Human reference: https://illari.dev/docs/api",
    "contact": {
      "name": "illari",
      "email": "hello@illari.dev",
      "url": "https://illari.dev"
    }
  },
  "servers": [
    {
      "url": "https://illari.dev/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Monitors",
      "description": "Create, read, update, and delete monitors."
    },
    {
      "name": "Pings",
      "description": "Read a monitor's check-in history."
    }
  ],
  "paths": {
    "/monitors": {
      "get": {
        "tags": [
          "Monitors"
        ],
        "summary": "List monitors",
        "operationId": "listMonitors",
        "responses": {
          "200": {
            "description": "All monitors on the account, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Monitor"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Monitors"
        ],
        "summary": "Create a monitor",
        "operationId": "createMonitor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MonitorCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created. Includes the generated pingKey.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Monitor"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "Monitor limit reached for the plan, or metricRules sent on a Free account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/monitors/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "tags": [
          "Monitors"
        ],
        "summary": "Get a monitor",
        "operationId": "getMonitor",
        "responses": {
          "200": {
            "description": "The monitor.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Monitor"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Monitors"
        ],
        "summary": "Update a monitor",
        "description": "Partial update: only the keys present in the body change. Includes pause/snooze. Changing cronExpression or timezone recomputes the next expected run.",
        "operationId": "updateMonitor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MonitorPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated monitor.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Monitor"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "metricRules sent on a Free account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Monitors"
        ],
        "summary": "Delete a monitor",
        "description": "Deletes the monitor and its check-in history. The ping URL then returns 404.",
        "operationId": "deleteMonitor",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/monitors/{id}/pings": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "tags": [
          "Pings"
        ],
        "summary": "List a monitor's check-ins",
        "description": "Newest first. Keyset pagination: pass the response `nextBefore` back as `before` for the next page; it is null on the last page.",
        "operationId": "listPings",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Return check-ins received strictly before this timestamp."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of check-ins.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "nextBefore"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Ping"
                      }
                    },
                    "nextBefore": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "An API key (`illari_` followed by 32 hex characters), created under Settings -> API keys and shown once. Send as `Authorization: Bearer illari_...`."
      }
    },
    "responses": {
      "BadRequest": {
        "description": "A field failed validation.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, malformed, or revoked API key.",
        "headers": {
          "WWW-Authenticate": {
            "schema": {
              "type": "string"
            },
            "example": "Bearer"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "No monitor with that id is visible to this key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "MetricRule": {
        "description": "A threshold rule (fixed condition) or an anomaly rule (value moved far off its recent baseline). Checked against numbers a completion ping reports.",
        "oneOf": [
          {
            "$ref": "#/components/schemas/ThresholdRule"
          },
          {
            "$ref": "#/components/schemas/AnomalyRule"
          }
        ]
      },
      "ThresholdRule": {
        "type": "object",
        "required": [
          "metric",
          "op",
          "value"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "threshold"
            ],
            "default": "threshold"
          },
          "metric": {
            "type": "string",
            "pattern": "^[a-zA-Z][\\w.-]{0,39}$",
            "description": "Name of a numeric field the job reports on a completion ping."
          },
          "op": {
            "type": "string",
            "enum": [
              "lt",
              "lte",
              "gt",
              "gte",
              "eq",
              "ne"
            ]
          },
          "value": {
            "type": "number"
          }
        },
        "example": {
          "kind": "threshold",
          "metric": "rows",
          "op": "lt",
          "value": 1
        }
      },
      "AnomalyRule": {
        "type": "object",
        "required": [
          "kind",
          "metric",
          "direction"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "anomaly"
            ]
          },
          "metric": {
            "type": "string",
            "pattern": "^[a-zA-Z][\\w.-]{0,39}$"
          },
          "direction": {
            "type": "string",
            "enum": [
              "up",
              "down",
              "both"
            ],
            "description": "Which drift to alert on: a spike, a drop, or either. Needs ~8 prior runs of the metric to establish a baseline."
          }
        },
        "example": {
          "kind": "anomaly",
          "metric": "cost_usd",
          "direction": "up"
        }
      },
      "Monitor": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "command": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500,
            "description": "Free text: the command or script this monitor watches. Never executed."
          },
          "cronExpression": {
            "type": [
              "string",
              "null"
            ],
            "description": "Standard 5-field cron, or a macro (@daily etc.). Null for an interval/grace-only monitor."
          },
          "timezone": {
            "type": "string",
            "default": "UTC",
            "description": "IANA timezone used to interpret the cron schedule (DST-aware)."
          },
          "gracePeriodSeconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 86400,
            "default": 300
          },
          "maxRuntimeSeconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 604800,
            "description": "Opt-in hung-run detection. Null = off."
          },
          "metricRules": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MetricRule"
            },
            "description": "Custom-metric rules (Pro): threshold conditions and baseline-anomaly rules."
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "up",
              "late",
              "down"
            ],
            "readOnly": true
          },
          "paused": {
            "type": "boolean",
            "default": false
          },
          "snoozedUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Temporary pause with an expiry. Send null to wake now."
          },
          "pingKey": {
            "type": "string",
            "readOnly": true,
            "description": "The credential in the ping URL: https://illari.dev/ping/<pingKey>"
          },
          "badgeKey": {
            "type": "string",
            "readOnly": true
          },
          "lastPingAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "readOnly": true
          },
          "nextExpectedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "readOnly": true
          },
          "lastAlertSentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "readOnly": true
          },
          "lastNotifiedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        }
      },
      "MonitorCreate": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "command": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500,
            "description": "Free text: the command or script this monitor watches. Never executed."
          },
          "cronExpression": {
            "type": [
              "string",
              "null"
            ],
            "description": "Standard 5-field cron, or a macro (@daily etc.). Null for an interval/grace-only monitor."
          },
          "timezone": {
            "type": "string",
            "default": "UTC",
            "description": "IANA timezone used to interpret the cron schedule (DST-aware)."
          },
          "gracePeriodSeconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 86400,
            "default": 300
          },
          "maxRuntimeSeconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 604800,
            "description": "Opt-in hung-run detection. Null = off."
          },
          "metricRules": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MetricRule"
            },
            "description": "Custom-metric rules (Pro): threshold conditions and baseline-anomaly rules."
          }
        },
        "example": {
          "name": "nightly-etl",
          "cronExpression": "0 2 * * *",
          "timezone": "America/Chicago",
          "gracePeriodSeconds": 600
        }
      },
      "MonitorPatch": {
        "type": "object",
        "description": "Any subset of these keys.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "command": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500,
            "description": "Free text: the command or script this monitor watches. Never executed."
          },
          "cronExpression": {
            "type": [
              "string",
              "null"
            ],
            "description": "Standard 5-field cron, or a macro (@daily etc.). Null for an interval/grace-only monitor."
          },
          "timezone": {
            "type": "string",
            "default": "UTC",
            "description": "IANA timezone used to interpret the cron schedule (DST-aware)."
          },
          "gracePeriodSeconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 86400,
            "default": 300
          },
          "maxRuntimeSeconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 604800,
            "description": "Opt-in hung-run detection. Null = off."
          },
          "metricRules": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MetricRule"
            },
            "description": "Custom-metric rules (Pro): threshold conditions and baseline-anomaly rules."
          },
          "paused": {
            "type": "boolean",
            "default": false
          },
          "snoozedUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Temporary pause with an expiry. Send null to wake now."
          }
        },
        "example": {
          "paused": true
        }
      },
      "Ping": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "monitorId": {
            "type": "string",
            "format": "uuid"
          },
          "receivedAt": {
            "type": "string",
            "format": "date-time"
          },
          "sourceIp": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "type": "string",
            "enum": [
              "success",
              "start",
              "fail"
            ]
          },
          "exitCode": {
            "type": [
              "integer",
              "null"
            ]
          },
          "durationMs": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Wall-clock time from the matching start ping to this completion."
          },
          "body": {
            "type": [
              "string",
              "null"
            ],
            "description": "Captured request body, truncated to ~10 KB."
          },
          "metrics": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": {
              "type": "number"
            },
            "description": "Numeric key=value pairs sent with the ping."
          }
        }
      }
    }
  }
}