openapi: 3.1.0
info:
  title: Live API
  version: v1
  description: |
    Live monitors public HTTPS endpoints and publishes status pages. Use a workspace bearer key
    with the scope listed on each authenticated operation. Published page history is public.

    JSON request bodies use `Content-Type: application/json` and are limited to 4,096 bytes.
    Request timestamps use UTC with a trailing `Z`. Errors include an `error` string.
    An unsupported method returns 405 with an `Allow` header.
servers:
  - url: https://live.tvr.works/v1
security:
  - WorkspaceKey: []
tags:
  - name: Monitors
  - name: Status pages
  - name: Maintenance

paths:
  /monitors:
    get:
      tags: [Monitors]
      operationId: listMonitors
      summary: List monitors
      description: Requires a management key. Includes enabled and disabled monitors.
      responses:
        '200':
          description: Monitor configurations.
          content:
            application/json:
              schema:
                type: object
                required: [monitors]
                properties:
                  monitors:
                    type: array
                    items: { $ref: '#/components/schemas/Monitor' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
    post:
      tags: [Monitors]
      operationId: createMonitor
      summary: Create a monitor
      description: |
        Requires a management key. A workspace can enable up to 100 monitors. A hostname can
        have up to 10 enabled monitors across all workspaces and regions.
      requestBody: { $ref: '#/components/requestBodies/Monitor' }
      responses:
        '201': { $ref: '#/components/responses/Monitor' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '409': { $ref: '#/components/responses/Conflict' }
        '413': { $ref: '#/components/responses/TooLarge' }
        '415': { $ref: '#/components/responses/UnsupportedMedia' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /monitors/{monitorId}:
    parameters:
      - $ref: '#/components/parameters/MonitorId'
    get:
      tags: [Monitors]
      operationId: readMonitorHistory
      summary: Read a monitor’s uptime history
      description: |
        Requires a status key. Without explicit dates, the default window is 90 buckets ending
        at the end of the current bucket. Pass both `from` and `to` for an explicit window.
        Boundaries must align to the bucket width.
      parameters:
        - $ref: '#/components/parameters/From'
        - $ref: '#/components/parameters/To'
        - $ref: '#/components/parameters/BucketMinutes'
        - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: Monitor uptime and buckets, in chronological order.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/MonitorHistory' }
              example:
                bucketMinutes: 1440
                from: '2026-11-19T00:00:00.000Z'
                to: '2026-11-20T00:00:00.000Z'
                generatedAt: '2026-11-20T14:01:00+00:00'
                monitor:
                  id: d842f79c-0fa7-49a7-992f-615182463fba
                  name: Example API
                  passed: 99
                  failed: 1
                  maintenance: 2
                  observedUptimePercent: 99
                  buckets:
                    - startsAt: '2026-11-19T00:00:00.000Z'
                      complete: true
                      passed: 99
                      failed: 1
                      maintenance: 2
                      observedUptimePercent: 99
        '400': { $ref: '#/components/responses/BadHistoryRange' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
    put:
      tags: [Monitors]
      operationId: updateMonitor
      summary: Update or disable a monitor
      description: |
        Requires a management key. Send the required fields on every update. Set `enabled`
        to `false` to stop checks and keep history. Create a new monitor for a different
        target URL. A region change preserves history and schedules a fresh check.
      requestBody: { $ref: '#/components/requestBodies/Monitor' }
      responses:
        '200': { $ref: '#/components/responses/Monitor' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '413': { $ref: '#/components/responses/TooLarge' }
        '415': { $ref: '#/components/responses/UnsupportedMedia' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /status-pages:
    get:
      tags: [Status pages]
      operationId: listStatusPages
      summary: List status pages
      description: Requires a management key. Includes drafts and published pages.
      responses:
        '200':
          description: Status page configurations.
          content:
            application/json:
              schema:
                type: object
                required: [pages]
                properties:
                  pages:
                    type: array
                    items: { $ref: '#/components/schemas/StatusPage' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
    post:
      tags: [Status pages]
      operationId: createStatusPage
      summary: Create a status page
      description: Requires a management key. Set `published` to `true` to publish immediately.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/StatusPageInput'
                - required: [name, monitorIds]
            example:
              name: Example status
              monitorIds: [d842f79c-0fa7-49a7-992f-615182463fba]
              published: true
      responses:
        '201': { $ref: '#/components/responses/StatusPage' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '413': { $ref: '#/components/responses/TooLarge' }
        '415': { $ref: '#/components/responses/UnsupportedMedia' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /status-pages/{pageId}:
    parameters:
      - $ref: '#/components/parameters/PageId'
    get:
      tags: [Status pages]
      operationId: readPublishedPage
      summary: Read a published page’s uptime history
      description: |
        Public. Returns enabled monitors selected for the page, in display order.
        Drafts and unknown pages return 404. The history defaults match the monitor history endpoint.
      security: []
      parameters:
        - $ref: '#/components/parameters/From'
        - $ref: '#/components/parameters/To'
        - $ref: '#/components/parameters/BucketMinutes'
        - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: A published page and its monitor histories.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PublishedPageHistory' }
        '400': { $ref: '#/components/responses/BadHistoryRange' }
        '404': { $ref: '#/components/responses/NotFound' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
    patch:
      tags: [Status pages]
      operationId: updateStatusPage
      summary: Update or publish a status page
      description: |
        Requires a management key. Supply at least one field. Set `published` to `false` to
        unpublish. The page ID and hosted URL remain stable. Monitors must belong to your workspace.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/StatusPageInput' }
            example: { published: true }
      responses:
        '200': { $ref: '#/components/responses/StatusPage' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '413': { $ref: '#/components/responses/TooLarge' }
        '415': { $ref: '#/components/responses/UnsupportedMedia' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /monitors/{monitorId}/maintenance:
    parameters:
      - $ref: '#/components/parameters/MonitorId'
    get:
      tags: [Maintenance]
      operationId: listMaintenance
      summary: List open maintenance windows
      description: Requires a maintenance key. Windows are ordered by start time, oldest first.
      parameters:
        - name: state
          in: query
          schema: { type: string, enum: [open] }
      responses:
        '200':
          description: Open windows for this monitor.
          content:
            application/json:
              schema:
                type: object
                required: [monitorId, windows]
                properties:
                  monitorId: { $ref: '#/components/schemas/Id' }
                  windows:
                    type: array
                    items:
                      type: object
                      required: [id, startsAt]
                      properties:
                        id: { $ref: '#/components/schemas/WindowId' }
                        startsAt: { type: string, format: date-time }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /monitors/{monitorId}/maintenance/{windowId}:
    parameters:
      - $ref: '#/components/parameters/MonitorId'
      - $ref: '#/components/parameters/WindowId'
    put:
      tags: [Maintenance]
      operationId: backfillMaintenance
      summary: Backfill a completed window
      description: |
        Requires a maintenance key. Use a new window ID and send `startsAt < endsAt`,
        with `endsAt` at or before now. Retrying with the same timestamps returns the saved window.
        Live refreshes affected summaries.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [startsAt, endsAt]
              properties:
                startsAt: { $ref: '#/components/schemas/UtcTimestamp' }
                endsAt: { $ref: '#/components/schemas/UtcTimestamp' }
            example: { startsAt: '2026-11-20T14:00:00Z', endsAt: '2026-11-20T14:15:00Z' }
      responses:
        '200': { $ref: '#/components/responses/Window' }
        '201': { $ref: '#/components/responses/Window' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/WindowConflict' }
        '413': { $ref: '#/components/responses/TooLarge' }
        '415': { $ref: '#/components/responses/UnsupportedMedia' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /monitors/{monitorId}/maintenance/{windowId}/start:
    parameters:
      - $ref: '#/components/parameters/MonitorId'
      - $ref: '#/components/parameters/WindowId'
    put:
      tags: [Maintenance]
      operationId: startMaintenance
      summary: Start a maintenance window
      description: |
        Requires a maintenance key. Send an empty body. Live sets the start time on the first
        request. A retry returns the saved window with 200. A closed window stays closed.
      responses:
        '200': { $ref: '#/components/responses/Window' }
        '201': { $ref: '#/components/responses/Window' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /monitors/{monitorId}/maintenance/{windowId}/stop:
    parameters:
      - $ref: '#/components/parameters/MonitorId'
      - $ref: '#/components/parameters/WindowId'
    put:
      tags: [Maintenance]
      operationId: stopMaintenance
      summary: Stop a maintenance window
      description: |
        Requires a maintenance key. Send an empty body to use the current time. For a missed
        stop, the supplied end must be at or after the start and at or before now.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: [endsAt]
              properties:
                endsAt: { $ref: '#/components/schemas/UtcTimestamp' }
            example: { endsAt: '2026-11-20T14:15:00Z' }
      responses:
        '200': { $ref: '#/components/responses/Window' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/WindowConflict' }
        '413': { $ref: '#/components/responses/TooLarge' }
        '415': { $ref: '#/components/responses/UnsupportedMedia' }
        '502': { $ref: '#/components/responses/BadGateway' }
        '503': { $ref: '#/components/responses/Unavailable' }

components:
  securitySchemes:
    WorkspaceKey:
      type: http
      scheme: bearer
      description: A workspace key matching the scope listed in the operation.
  parameters:
    MonitorId:
      name: monitorId
      in: path
      required: true
      schema: { $ref: '#/components/schemas/Id' }
    PageId:
      name: pageId
      in: path
      required: true
      schema: { $ref: '#/components/schemas/Id' }
    WindowId:
      name: windowId
      in: path
      required: true
      schema: { $ref: '#/components/schemas/WindowId' }
    From:
      name: from
      in: query
      description: Inclusive, bucket-aligned start. Required when to is supplied.
      schema: { $ref: '#/components/schemas/UtcTimestamp' }
    To:
      name: to
      in: query
      description: Exclusive, bucket-aligned end. Required when from is supplied.
      schema: { $ref: '#/components/schemas/UtcTimestamp' }
    BucketMinutes:
      name: bucketMinutes
      in: query
      description: |
        Minutes per bucket. Retention is 30 days for widths under 60 minutes, 90 days
        for hourly widths, and 365 days for daily buckets.
      schema: { type: integer, enum: [1, 5, 15, 30, 60, 180, 360, 720, 1440], default: 1440 }
    Limit:
      name: limit
      in: query
      description: Select the newest buckets within the window.
      schema: { type: integer, minimum: 1, maximum: 120 }
  requestBodies:
    Monitor:
      required: true
      content:
        application/json:
          schema: { $ref: '#/components/schemas/MonitorInput' }
          example:
            name: Example API
            url: https://example.com/health
            intervalMinutes: 5
  responses:
    Monitor:
      description: Saved monitor configuration.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Monitor' }
    StatusPage:
      description: Saved status page configuration.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/StatusPage' }
    Window:
      description: Saved maintenance window.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Window' }
    BadRequest:
      description: Invalid parameters, request body, or target URL.
      content: &errorContent
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    BadHistoryRange:
      description: Invalid parameters or the requested range exceeds the available history.
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Error'
              - properties:
                  earliestAvailableAt:
                    type: string
                    format: date-time
                    description: Earliest available timestamp when history has aged out.
    Unauthorized:
      description: Missing or invalid key.
      headers:
        WWW-Authenticate:
          schema: { type: string, example: Bearer }
      content: *errorContent
    Forbidden:
      description: The organization key lacks the required permission.
      content: *errorContent
    NotFound:
      description: The requested monitor, published page, or window is unavailable.
      content: *errorContent
    Conflict:
      description: The monitor limit was reached or a monitor setting conflicts with the saved configuration.
      content: *errorContent
    WindowConflict:
      description: The saved window conflicts with the request, or the correction exceeded raw check retention.
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Error'
              - properties:
                  earliestCorrectableAt:
                    type: string
                    format: date-time
                    description: Earliest correctable timestamp when raw checks have aged out.
    TooLarge:
      description: JSON request body exceeds 4,096 bytes.
      content: *errorContent
    UnsupportedMedia:
      description: A JSON body requires Content-Type application/json.
      content: *errorContent
    BadGateway:
      description: The gateway could not reach the API.
      content: *errorContent
    Unavailable:
      description: The API or database is temporarily unavailable.
      content: *errorContent
  schemas:
    Id:
      type: string
      format: uuid
      pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
      examples: [d842f79c-0fa7-49a7-992f-615182463fba]
    WindowId:
      type: string
      pattern: '^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$'
      examples: [deploy-123]
    UtcTimestamp:
      type: string
      format: date-time
      pattern: 'Z$'
      examples: ['2026-11-20T14:00:00Z']
    Name:
      type: string
      minLength: 1
      description: Between 1 and 80 characters after trimming.
    MonitorInput:
      type: object
      required: [name, url, intervalMinutes]
      properties:
        name: { $ref: '#/components/schemas/Name' }
        url:
          type: string
          format: uri
          maxLength: 1024
          description: |
            Public HTTPS URL on the default port, without credentials, query, or fragment.
            The endpoint must support HTTP/1.1 and present a valid TLS certificate.
            Redirects count as failed checks.
        intervalMinutes: { type: integer, enum: [1, 5, 15] }
        enabled: { type: boolean, default: true }
        probeRegion:
          type: string
          description: |
            A [Supabase Edge Function region](https://supabase.com/docs/guides/functions/regional-invocation#available-regions).
            Defaults to us-east-1 on create. Omit on update to keep the current region.
          examples: [us-east-1]
    Monitor:
      allOf:
        - $ref: '#/components/schemas/MonitorInput'
        - type: object
          required: [id, enabled, probeRegion]
          properties:
            id: { $ref: '#/components/schemas/Id' }
    StatusPageInput:
      type: object
      minProperties: 1
      additionalProperties: false
      properties:
        name: { $ref: '#/components/schemas/Name' }
        monitorIds:
          type: array
          uniqueItems: true
          maxItems: 25
          description: Monitor UUIDs in display order. An empty array clears the selection.
          items: { $ref: '#/components/schemas/Id' }
        published:
          type: boolean
          description: Defaults to false on create.
    StatusPage:
      type: object
      required: [id, name, monitorIds, published, url]
      properties:
        id: { $ref: '#/components/schemas/Id' }
        name: { $ref: '#/components/schemas/Name' }
        monitorIds:
          type: array
          items: { $ref: '#/components/schemas/Id' }
        published: { type: boolean }
        url: { type: string, format: uri, description: Stable hosted status page URL. }
    HistoryRange:
      type: object
      required: [bucketMinutes, from, to, generatedAt]
      properties:
        bucketMinutes: { type: integer }
        from: { type: string, format: date-time }
        to: { type: string, format: date-time }
        generatedAt: { type: string, format: date-time }
    Counts:
      type: object
      required: [passed, failed, maintenance, observedUptimePercent]
      properties:
        passed: { type: integer, minimum: 0 }
        failed: { type: integer, minimum: 0 }
        maintenance: { type: integer, minimum: 0 }
        observedUptimePercent:
          type: [number, 'null']
          minimum: 0
          maximum: 100
          description: 100 × passed / (passed + failed), or null when no regular checks were recorded.
    Bucket:
      allOf:
        - $ref: '#/components/schemas/Counts'
        - type: object
          required: [startsAt, complete]
          properties:
            startsAt: { type: string, format: date-time }
            complete: { type: boolean, description: True once the bucket’s end time has passed. }
    MonitorUptime:
      allOf:
        - $ref: '#/components/schemas/Counts'
        - type: object
          required: [id, name, buckets]
          properties:
            id: { $ref: '#/components/schemas/Id' }
            name: { type: string }
            buckets:
              type: array
              items: { $ref: '#/components/schemas/Bucket' }
    MonitorHistory:
      allOf:
        - $ref: '#/components/schemas/HistoryRange'
        - type: object
          required: [monitor]
          properties:
            monitor: { $ref: '#/components/schemas/MonitorUptime' }
    PublishedPageHistory:
      allOf:
        - $ref: '#/components/schemas/HistoryRange'
        - type: object
          required: [page, monitors]
          properties:
            page:
              type: object
              required: [id, name]
              properties:
                id: { $ref: '#/components/schemas/Id' }
                name: { type: string }
            monitors:
              type: array
              items: { $ref: '#/components/schemas/MonitorUptime' }
    Window:
      type: object
      required: [monitorId, id, startsAt, endsAt]
      properties:
        monitorId: { $ref: '#/components/schemas/Id' }
        id: { $ref: '#/components/schemas/WindowId' }
        startsAt: { type: string, format: date-time }
        endsAt: { type: [string, 'null'], format: date-time, description: Null while the window is open. }
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string }
