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

# 预览草稿面板

> 内联执行草稿面板，不产生仪表盘新版本。



## OpenAPI

````yaml /api-reference/monitors.openapi.zh.json post /monit/dashboard/panel/preview
openapi: 3.1.0
info:
  title: Flashduty 开放 API
  description: >-
    Flashduty 事件管理平台的公开 HTTP API —— 覆盖故障、通知模板、协作空间、值班排班、监控、RUM、以及平台管理。每次调用都需在
    query 中携带 `app_key`，该 key 在 Flashduty 控制台 账户 → APP Key 中签发。所有响应使用统一结构：成功时为
    `{ request_id, data }`，失败时为 `{ request_id, error }`。
  version: 1.0.0
servers:
  - url: https://api.flashcat.cloud
    description: Flashduty Open API
security:
  - AppKeyAuth: []
tags:
  - name: Monitors/告警规则
    description: 创建、管理和导出监控告警规则，查询规则统计和审计历史。
  - name: Monitors/告警数据源
    description: 管理监控告警规则用于查询指标的数据源。
  - name: Monitors/诊断分析
    description: Flashduty AI SRE 使用的诊断与查询接口——数据源即席查询、日志/指标诊断,以及监控对象侧的工具调用。
  - name: Monitors/通用工具
    description: 监控服务开通及数据预览工具。
  - name: Monitors/仪表盘
    description: 创建、搜索、版本化与运行 Monitors 仪表盘，并解析其变量与查询。
  - name: Monitors/规则分组
    description: 列出仪表盘与告警规则所在的监控节点树。
paths:
  /monit/dashboard/panel/preview:
    post:
      tags:
        - Monitors/仪表盘
      summary: 预览草稿面板
      description: 内联执行草稿面板，不产生仪表盘新版本。
      operationId: monit-dashboard-panel-read-preview
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DashboardPanelPreviewRequest'
            example:
              context:
                kind: existing
                dashboard_id: 01990d7a-9c5b-7ab0-9c18-33e38f6f2101
              panel:
                id: 01990d7a-9c5b-7ab0-9c18-33e38f6f2404
                title: Request rate
                grid:
                  x: 0
                  'y': 0
                  w: 12
                  h: 8
                datasource_ref:
                  kind: fixed
                  datasource_id: 10
                  datasource_type: prometheus
                queries:
                  - ref_id: A
                    legend_alias: '{{env}} requests'
                    query:
                      mode: range
                      expr: sum(rate(http_requests_total{env="{{env}}"}[5m]))
                      args: {}
                      min_step_seconds: 30
                viz_config:
                  kind: time_series
                  options: {}
                  unit: count_per_second
                  decimals: 2
                  threshold:
                    mode: higher_is_worse
                    warning: 1000
                    critical: 2000
              variables:
                - kind: custom
                  name: env
                  label: Environment
                  selection:
                    mode: single
                    include_all: false
                  options:
                    - text: Production
                      value: prod
                    - text: Staging
                      value: staging
                  default:
                    kind: values
                    values:
                      - prod
              selections:
                env:
                  kind: values
                  values:
                    - prod
              time:
                from_ms: 1791100800000
                to_ms: 1791104400000
              max_data_points: 100
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/DashboardPanelPreviewResponse'
              example:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                data:
                  panel_id: 01990d7a-9c5b-7ab0-9c18-33e38f6f2404
                  run_state: success
                  time:
                    from_ms: 1791100800000
                    to_ms: 1791104400000
                  variables:
                    env:
                      kind: values
                      values:
                        - prod
                  refs:
                    - ref_id: A
                      state: success
                      child_request_id: 01HK8XQH7B4N0PQR2S6TVW9X3M
                      execution:
                        status: success
                        frames:
                          - schema:
                              fields:
                                - name: time
                                  type: time
                                - name: value
                                  type: number
                            data:
                              values:
                                - - 1791100800000
                                  - 812.4
                                - - 1791100860000
                                  - 846.1
                  display:
                    kind: time_series
                    options: {}
                    unit: count_per_second
                    decimals: 2
                    threshold:
                      mode: higher_is_worse
                      warning: 1000
                      critical: 2000
                  budget:
                    max_concurrency: 6
                    execution_count: 1
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/ServerError'
components:
  schemas:
    DashboardPanelPreviewRequest:
      type: object
      description: 内联执行一个草稿面板，不会产生仪表盘新版本。同样受 1 MiB 定义体积上限约束。
      properties:
        context:
          $ref: '#/components/schemas/DashboardDraftContext'
        panel:
          $ref: '#/components/schemas/DashboardPanel'
        variables:
          type: array
          items:
            $ref: '#/components/schemas/DashboardVariable'
          maxItems: 20
          description: 该面板可能引用的草稿变量。
        selections:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/DashboardSelection'
          description: 按变量名索引的选择。
        time:
          $ref: '#/components/schemas/DashboardAbsoluteTimeRange'
        max_data_points:
          type:
            - integer
            - 'null'
          minimum: 2
          maximum: 5000
          description: 降采样目标，2～5000 个点。
      required:
        - context
        - panel
        - variables
        - selections
        - time
    SuccessEnvelope:
      type: object
      description: >-
        成功响应结构。2xx 响应中 `request_id` 标识本次调用（同时出现在 `Flashcat-Request-Id`
        响应头中），`data` 为接口业务 payload。失败响应使用不同结构，参见 `ErrorResponse`。
      properties:
        request_id:
          type: string
          description: 本次请求的唯一 ID，也会在 Flashcat-Request-Id 响应头中返回。反馈问题时请一并附上。
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
        data:
          description: 每个接口自己的业务 payload，详见各接口的 200 响应 schema。
      required:
        - request_id
        - data
    DashboardPanelPreviewResponse:
      type: object
      description: 草稿面板执行结果。与已存面板运行结构相同，只是不含仪表盘标识。
      properties:
        panel_id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: 面板 ID。
        run_state:
          type: string
          enum:
            - success
            - partial
            - incompatible
            - cancelled
            - error
          description: >-
            本次运行的整体状态：`success` = 全部查询成功；`partial` = 部分成功；`incompatible` =
            至少一条查询与其数据源类型不兼容；`cancelled` = 运行被取消；`error` = 全部查询失败。
        time:
          $ref: '#/components/schemas/DashboardAbsoluteTimeRange'
        variables:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/DashboardSelection'
          description: 解析成功的变量选择。
        refs:
          type: array
          items:
            $ref: '#/components/schemas/DashboardPanelRunRef'
          description: 面板中每条查询对应一个条目。
        display:
          $ref: '#/components/schemas/DashboardVizConfig'
        budget:
          $ref: '#/components/schemas/DashboardPanelRunBudget'
      required:
        - panel_id
        - run_state
        - time
        - variables
        - refs
        - display
        - budget
    DashboardDraftContext:
      type: object
      description: 未保存的草稿面板/变量集所属的上下文。`existing` 指向已存仪表盘，`new` 指向尚无仪表盘的目录——两者互斥。
      properties:
        kind:
          type: string
          enum:
            - existing
            - new
          description: >-
            草稿上下文类型：`existing` = 指向已存储的仪表盘（必须给出 `dashboard_id`）；`new` =
            指向尚不包含仪表盘的目录（必须给出 `folder_id`）。
        dashboard_id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: '`existing` 时必填，`new` 时禁止设置。'
        folder_id:
          type: integer
          format: uint64
          minimum: 1
          description: '`new` 时必填，`existing` 时禁止设置。'
      required:
        - kind
    DashboardPanel:
      type: object
      description: 单个可视化面板。同一容器内的面板不得重叠；24 列网格在保存时校验。
      properties:
        id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: 标识该面板的 canonical UUIDv7，在整份定义内唯一。
        title:
          type: string
          minLength: 1
          maxLength: 189
          description: 面板标题。
        description:
          type: string
          maxLength: 1024
          description: 可选面板描述。
        grid:
          $ref: '#/components/schemas/DashboardGridPosition'
        datasource_ref:
          $ref: '#/components/schemas/DashboardDatasourceRef'
        queries:
          type: array
          items:
            $ref: '#/components/schemas/DashboardPanelQuery'
          maxItems: 26
          description: 面板内的查询。`time_series` 允许 1～26 条，`text` 不允许查询，其余类型必须恰好 1 条。
        viz_config:
          $ref: '#/components/schemas/DashboardVizConfig'
      required:
        - id
        - title
        - grid
        - queries
        - viz_config
    DashboardVariable:
      description: 仪表盘变量。按 `kind` 选择对应分支。
      oneOf:
        - $ref: '#/components/schemas/DashboardDatasourceVariable'
        - $ref: '#/components/schemas/DashboardCustomVariable'
        - $ref: '#/components/schemas/DashboardQueryVariable'
      discriminator:
        propertyName: kind
        mapping:
          datasource: '#/components/schemas/DashboardDatasourceVariable'
          custom: '#/components/schemas/DashboardCustomVariable'
          query: '#/components/schemas/DashboardQueryVariable'
    DashboardSelection:
      type: object
      description: 变量取值的具体选择。空的 `values` 数组是合法输入，表示未解析——服务端不会为其回退到默认值。
      properties:
        kind:
          type: string
          enum:
            - values
            - all
          description: '`values` 选择列出的项，`all` 表示全选（仅当 `include_all` 为 true 时可用）。'
        values:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 1024
          maxItems: 1000
          description: 已选值，需唯一且不得为 `$__all`。`kind` 为 `all` 时必须为空。
      required:
        - kind
    DashboardAbsoluteTimeRange:
      type: object
      description: >-
        绝对求值窗口。两个边界都是 Unix 毫秒时间戳，`from_ms` 必须小于 `to_ms`，且都不得超过 JavaScript
        安全整数上限。
      properties:
        from_ms:
          type: integer
          format: int64
          minimum: 0
          description: Unix 时间戳（毫秒）。
        to_ms:
          type: integer
          format: int64
          minimum: 1
          description: Unix 时间戳（毫秒）。
      required:
        - from_ms
        - to_ms
    DashboardPanelRunRef:
      type: object
      description: 面板运行中单条查询的结果。原始执行载荷随数据源类型而异且原样透传，因此此处不做 schema 约束。
      properties:
        ref_id:
          type: string
          pattern: ^[A-Z]$
          description: 面板内的查询引用名。
        state:
          type: string
          enum:
            - success
            - error
            - incompatible
          description: >-
            单条查询的执行状态：`success` = 查询执行成功；`error` = 查询执行失败；`incompatible` =
            数据源接受了调用，但查询模式或字段选择与该数据源类型不匹配。
        child_request_id:
          type: string
          description: 底层数据源执行的请求 ID；排查单条查询时可用。
        execution:
          type: object
          additionalProperties: true
          description: 数据源专属的执行载荷，原样透传。
        error:
          $ref: '#/components/schemas/DashboardRuntimeError'
      required:
        - ref_id
        - state
    DashboardVizConfig:
      description: 可视化配置。`kind` 决定使用哪个分支以及哪个同级的配置对象必需；`time_series` 还携带通用的数值配置。
      oneOf:
        - $ref: '#/components/schemas/DashboardTimeSeriesViz'
        - $ref: '#/components/schemas/DashboardTableViz'
        - $ref: '#/components/schemas/DashboardStatViz'
        - $ref: '#/components/schemas/DashboardBarViz'
        - $ref: '#/components/schemas/DashboardGaugeViz'
        - $ref: '#/components/schemas/DashboardLogsViz'
        - $ref: '#/components/schemas/DashboardTextViz'
      discriminator:
        propertyName: kind
        mapping:
          time_series: '#/components/schemas/DashboardTimeSeriesViz'
          table: '#/components/schemas/DashboardTableViz'
          stat: '#/components/schemas/DashboardStatViz'
          bar: '#/components/schemas/DashboardBarViz'
          gauge: '#/components/schemas/DashboardGaugeViz'
          logs: '#/components/schemas/DashboardLogsViz'
          text: '#/components/schemas/DashboardTextViz'
    DashboardPanelRunBudget:
      type: object
      description: 面板运行的执行统计。
      properties:
        max_concurrency:
          type: integer
          minimum: 1
          description: 该面板查询的并发上限。
        execution_count:
          type: integer
          minimum: 0
          description: 发起的查询数量。
      required:
        - max_concurrency
        - execution_count
    ErrorResponse:
      type: object
      description: 错误响应结构。`error` 必填，`data` 不存在。
      properties:
        request_id:
          type: string
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
          description: 本次请求的唯一追踪 ID（trace ID），反馈问题时请提供该值以便检索日志。
        error:
          $ref: '#/components/schemas/DutyError'
      required:
        - request_id
        - error
    DashboardGridPosition:
      type: object
      description: 24 列网格位置。`x`、`y` 从 0 开始；`x + w` 不得超过 24。
      properties:
        x:
          type: integer
          minimum: 0
          maximum: 23
          description: 从 0 开始的列偏移。
        'y':
          type: integer
          minimum: 0
          description: 从 0 开始的行偏移。
        w:
          type: integer
          minimum: 1
          maximum: 24
          description: 宽度（列数），1～24。
        h:
          type: integer
          minimum: 1
          maximum: 100
          description: 高度（行数），1～100。
      required:
        - x
        - 'y'
        - w
        - h
    DashboardDatasourceRef:
      type: object
      description: 把面板或查询变量指向某个数据源——可以是固定 ID，也可以是渲染时求值的数据源变量。
      properties:
        kind:
          type: string
          enum:
            - fixed
            - variable
          description: '`fixed` 使用 `datasource_id`；`variable` 用 `name` 引用某个数据源变量。'
        datasource_id:
          type: integer
          format: uint64
          minimum: 1
          description: 数据源 ID。`kind` 为 `fixed` 时必填，为 `variable` 时禁止设置。
        name:
          type: string
          pattern: ^[A-Za-z_][A-Za-z0-9_]{0,63}$
          description: 数据源变量名。`kind` 为 `variable` 时必填，为 `fixed` 时禁止设置。
        datasource_type:
          type: string
          pattern: ^[a-z][a-z0-9_]{0,63}$
          description: 数据源类型标识，例如 `prometheus`、`victorialogs`。
      required:
        - kind
        - datasource_type
    DashboardPanelQuery:
      type: object
      description: 面板内的一条查询。`ref_id` 用于标识面板中的序列，在同一面板内必须唯一。
      properties:
        ref_id:
          type: string
          pattern: ^[A-Z]$
          description: 单个大写字母（A～Z），在该面板内命名这条查询。
        query:
          $ref: '#/components/schemas/DashboardQuery'
        legend_alias:
          type: string
          maxLength: 1024
          description: 可选图例名；支持与 `expr` 相同的变量模板。
      required:
        - ref_id
        - query
    DashboardDatasourceVariable:
      type: object
      description: 数据源选择变量。候选项为账户下 `datasource_type` 类型的数据源。
      properties:
        kind:
          type: string
          enum:
            - datasource
          description: 变量类型判别字段，固定为 `datasource`，表示选择一个数据源。
        name:
          type: string
          pattern: ^[A-Za-z_][A-Za-z0-9_]{0,63}$
          description: 在 `{{ }}` 模板中引用的变量名，最多 64 个字符。
        label:
          type: string
          maxLength: 189
          description: 可选展示名，缺省时使用 `name`。
        datasource_type:
          type: string
          pattern: ^[a-z][a-z0-9_]{0,63}$
          description: 候选项来自的数据源类型。
        name_patterns:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 189
          maxItems: 10
          description: 缩小候选范围的通配符，空表示该类型下的全部数据源。
        default_datasource_id:
          type: integer
          format: uint64
          description: 默认数据源 ID。若默认值不可用，运行时按名称、再按 ID 取第一个候选项。
      required:
        - kind
        - name
        - datasource_type
    DashboardCustomVariable:
      type: object
      description: 候选项来自内联固定列表的变量。
      properties:
        kind:
          type: string
          enum:
            - custom
          description: 变量类型判别字段，固定为 `custom`，表示候选来自内联提供的固定列表。
        name:
          type: string
          pattern: ^[A-Za-z_][A-Za-z0-9_]{0,63}$
          description: 在 `{{ }}` 模板中引用的变量名，最多 64 个字符。
        label:
          type: string
          maxLength: 189
          description: 可选展示名，缺省时使用 `name`。
        selection:
          $ref: '#/components/schemas/DashboardSelectionConfig'
        options:
          type: array
          items:
            $ref: '#/components/schemas/DashboardCandidate'
          minItems: 1
          maxItems: 1000
          description: 候选项列表，1～1000 条。取值非空、唯一，且不得为 `$__all`。
        default:
          $ref: '#/components/schemas/DashboardSelection'
      required:
        - kind
        - name
        - selection
        - options
    DashboardQueryVariable:
      type: object
      description: 通过向数据源执行查询来解析候选项的变量。
      properties:
        kind:
          type: string
          enum:
            - query
          description: 变量类型判别字段，固定为 `query`，表示候选通过对数据源执行查询解析得到。
        name:
          type: string
          pattern: ^[A-Za-z_][A-Za-z0-9_]{0,63}$
          description: 在 `{{ }}` 模板中引用的变量名，最多 64 个字符。
        label:
          type: string
          maxLength: 189
          description: 可选展示名，缺省时使用 `name`。
        selection:
          $ref: '#/components/schemas/DashboardSelectionConfig'
        default:
          $ref: '#/components/schemas/DashboardSelection'
        datasource_ref:
          $ref: '#/components/schemas/DashboardDatasourceRef'
        variable_query:
          $ref: '#/components/schemas/DashboardVariableQuery'
        refresh:
          type: string
          enum:
            - on_dashboard_load
            - on_time_range_change
          description: >-
            候选项的重新计算时机：`on_dashboard_load` = 仪表盘加载时计算一次；`on_time_range_change` =
            时间范围每次变化时重新计算。
      required:
        - kind
        - name
        - selection
        - datasource_ref
        - variable_query
        - refresh
    DashboardRuntimeError:
      type: object
      description: 变量级或查询级的失败。单个分支失败不会导致整个调用失败。
      properties:
        reason:
          type: string
          description: >-
            机器可读的失败原因。已观察到的取值包括
            `invalid_request`、`variable_invalid`、`panel_missing`、`field_missing`、`datasource_permission_denied`、`timeout`、`panel_deadline`、`panel_canceled`、`canceled`、`overloaded`、`source_too_large`、`edge_unavailable`、`edge_upgrade_required`、`edge_version_unknown`、`mixed_edge_versions`、`internal`。
        message:
          type: string
          description: 失败的可读详情。
      required:
        - reason
        - message
    DashboardTimeSeriesViz:
      type: object
      description: 时序图可视化。
      properties:
        kind:
          type: string
          enum:
            - time_series
          description: 可视化类型判别字段，固定为 `time_series`。
        options:
          type: object
          additionalProperties: true
          description: 所选可视化类型的开放配置对象；也是定义中唯一无损 round-trip 的部分。缺失或 null 时规范化为 `{}`。
        unit:
          type: string
          enum:
            - unitless
            - ratio
            - percent
            - milliseconds
            - seconds
            - bytes
            - bits
            - count_per_second
            - bytes_per_second
            - bits_per_second
          description: >-
            面板数值的展示单位：`unitless` = 原始数值；`ratio` = 占比（0–1 的小数）；`percent` =
            百分比；`milliseconds` = 毫秒；`seconds` = 秒；`bytes` = 字节；`bits` =
            比特；`count_per_second` = 每秒计数；`bytes_per_second` =
            每秒字节数；`bits_per_second` = 每秒比特数。
        decimals:
          type:
            - integer
            - 'null'
          minimum: 0
          description: 固定小数位；省略或传 null 由前端决定。
        threshold:
          $ref: '#/components/schemas/DashboardThreshold'
      required:
        - kind
        - options
    DashboardTableViz:
      type: object
      description: 表格可视化。
      properties:
        kind:
          type: string
          enum:
            - table
          description: 可视化类型判别字段，固定为 `table`。
        options:
          type: object
          additionalProperties: true
          description: 所选可视化类型的开放配置对象；也是定义中唯一无损 round-trip 的部分。缺失或 null 时规范化为 `{}`。
        column_options:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/DashboardColumnOption'
          description: 按字段名索引的列展示覆盖配置，最多 100 项。
        sort:
          type: array
          items:
            $ref: '#/components/schemas/DashboardFieldSort'
          maxItems: 2
          description: 初始排序键；字段需唯一。
        link_columns:
          type: array
          items:
            $ref: '#/components/schemas/DashboardDataLink'
          maxItems: 5
          description: 以表格列形式渲染的下钻链接。与列级链接合计最多 5 个。
      required:
        - kind
        - options
    DashboardStatViz:
      type: object
      description: 单值（stat）可视化。
      properties:
        kind:
          type: string
          enum:
            - stat
          description: 可视化类型判别字段，固定为 `stat`。
        options:
          type: object
          additionalProperties: true
          description: 所选可视化类型的开放配置对象；也是定义中唯一无损 round-trip 的部分。缺失或 null 时规范化为 `{}`。
        unit:
          type: string
          enum:
            - unitless
            - ratio
            - percent
            - milliseconds
            - seconds
            - bytes
            - bits
            - count_per_second
            - bytes_per_second
            - bits_per_second
          description: >-
            面板数值的展示单位：`unitless` = 原始数值；`ratio` = 占比（0–1 的小数）；`percent` =
            百分比；`milliseconds` = 毫秒；`seconds` = 秒；`bytes` = 字节；`bits` =
            比特；`count_per_second` = 每秒计数；`bytes_per_second` =
            每秒字节数；`bits_per_second` = 每秒比特数。
        decimals:
          type:
            - integer
            - 'null'
          minimum: 0
          description: 固定小数位；省略或传 null 由前端决定。
        threshold:
          $ref: '#/components/schemas/DashboardThreshold'
        value_fields:
          type: array
          items:
            type: string
          description: 被归约为展示取值的字段。
        reducer:
          type: string
          enum:
            - last_non_null
            - min
            - max
            - mean
            - sum
          description: >-
            对返回行应用的归约方式：`last_non_null` = 最近的非空值；`min` = 最小值；`max` = 最大值；`mean`
            = 平均值；`sum` = 求和。
      required:
        - kind
        - options
        - value_fields
        - reducer
    DashboardBarViz:
      type: object
      description: 柱状图可视化。
      properties:
        kind:
          type: string
          enum:
            - bar
          description: 可视化类型判别字段，固定为 `bar`。
        options:
          type: object
          additionalProperties: true
          description: 所选可视化类型的开放配置对象；也是定义中唯一无损 round-trip 的部分。缺失或 null 时规范化为 `{}`。
        unit:
          type: string
          enum:
            - unitless
            - ratio
            - percent
            - milliseconds
            - seconds
            - bytes
            - bits
            - count_per_second
            - bytes_per_second
            - bits_per_second
          description: >-
            面板数值的展示单位：`unitless` = 原始数值；`ratio` = 占比（0–1 的小数）；`percent` =
            百分比；`milliseconds` = 毫秒；`seconds` = 秒；`bytes` = 字节；`bits` =
            比特；`count_per_second` = 每秒计数；`bytes_per_second` =
            每秒字节数；`bits_per_second` = 每秒比特数。
        decimals:
          type:
            - integer
            - 'null'
          minimum: 0
          description: 固定小数位；省略或传 null 由前端决定。
        threshold:
          $ref: '#/components/schemas/DashboardThreshold'
        category_field:
          type: string
          description: 提供类目轴的字段。
        value_fields:
          type: array
          items:
            type: string
          description: 提供柱值的字段。
        data_link:
          $ref: '#/components/schemas/DashboardDataLink'
      required:
        - kind
        - options
        - category_field
        - value_fields
    DashboardGaugeViz:
      type: object
      description: 仪表盘（gauge）可视化。
      properties:
        kind:
          type: string
          enum:
            - gauge
          description: 可视化类型判别字段，固定为 `gauge`。
        options:
          type: object
          additionalProperties: true
          description: 所选可视化类型的开放配置对象；也是定义中唯一无损 round-trip 的部分。缺失或 null 时规范化为 `{}`。
        unit:
          type: string
          enum:
            - unitless
            - ratio
            - percent
            - milliseconds
            - seconds
            - bytes
            - bits
            - count_per_second
            - bytes_per_second
            - bits_per_second
          description: >-
            面板数值的展示单位：`unitless` = 原始数值；`ratio` = 占比（0–1 的小数）；`percent` =
            百分比；`milliseconds` = 毫秒；`seconds` = 秒；`bytes` = 字节；`bits` =
            比特；`count_per_second` = 每秒计数；`bytes_per_second` =
            每秒字节数；`bits_per_second` = 每秒比特数。
        decimals:
          type:
            - integer
            - 'null'
          minimum: 0
          description: 固定小数位；省略或传 null 由前端决定。
        threshold:
          $ref: '#/components/schemas/DashboardThreshold'
        value_fields:
          type: array
          items:
            type: string
          description: 被归约为仪表值的字段。
        reducer:
          type: string
          enum:
            - last_non_null
            - min
            - max
            - mean
            - sum
          description: >-
            对返回行应用的归约方式：`last_non_null` = 最近的非空值；`min` = 最小值；`max` = 最大值；`mean`
            = 平均值；`sum` = 求和。
        min:
          type:
            - number
            - 'null'
          description: 刻度下限。
        max:
          type:
            - number
            - 'null'
          description: 刻度上限；两者都设置时必须大于 `min`。
      required:
        - kind
        - options
        - value_fields
        - reducer
    DashboardLogsViz:
      type: object
      description: 日志流可视化。
      properties:
        kind:
          type: string
          enum:
            - logs
          description: 可视化类型判别字段，固定为 `logs`。
        options:
          type: object
          additionalProperties: true
          description: 所选可视化类型的开放配置对象；也是定义中唯一无损 round-trip 的部分。缺失或 null 时规范化为 `{}`。
        display_fields:
          type: array
          items:
            type: string
          description: 每行渲染的日志字段。
      required:
        - kind
        - options
    DashboardTextViz:
      type: object
      description: Markdown 文本面板。
      properties:
        kind:
          type: string
          enum:
            - text
          description: 可视化类型判别字段，固定为 `text`。
        options:
          type: object
          additionalProperties: true
          description: 所选可视化类型的开放配置对象；也是定义中唯一无损 round-trip 的部分。缺失或 null 时规范化为 `{}`。
        markdown:
          type: string
          maxLength: 65536
          description: Markdown 正文，最多 64 KiB。仅限白名单节点（标题、列表、表格、链接、代码）可通过校验。
      required:
        - kind
        - options
        - markdown
    DutyError:
      type: object
      description: 响应结构中的错误 payload，仅在非 2xx 响应时出现。
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
          description: 用户可读的错误描述，语言会跟随调用方的 Accept-Language。可能包含字段名、ID 等请求上下文。
          example: The specified parameter template_id is not valid.
        reason:
          description: 可选的机器可读拒绝原因，包含数据源工具错误；结合 HTTP 状态及 code 判断。
          type: string
          x-flashduty-preserve-absence: true
      required:
        - code
        - message
    DashboardQuery:
      type: object
      description: 仪表盘与排障入口共用的查询内容。
      properties:
        mode:
          type: string
          enum:
            - instant
            - range
            - window
          description: 求值模式：`instant` 在单个时间点求值，`range` 求值一条按步长采样的曲线，`window` 返回时间窗口内的原始数据。
        expr:
          type: string
          description: 目标数据源语法下的查询表达式，可通过 `{{ }}` 模板引用事件标签。
        args:
          type: object
          additionalProperties:
            type: string
          description: 命名查询参数，默认空对象。值按原样透传，不允许包含 `{{ }}` 模板。
        min_step_seconds:
          type:
            - integer
            - 'null'
          format: int64
          minimum: 1
          maximum: 9007199254740
          description: 最小步长（秒）。仅在 `mode` 为 `range` 时可用，且必须大于 0；省略或传 null 由服务端决定。
      required:
        - mode
        - expr
        - args
    DashboardSelectionConfig:
      type: object
      description: 变量的选择数量约束。
      properties:
        mode:
          type: string
          enum:
            - single
            - multi
          description: 选择基数：`single` 表示解析后的选择恰好一个值；`multi` 表示允许选择多个值。
        include_all:
          type: boolean
          description: 为 true 时该变量额外提供 `all` 选项。
      required:
        - mode
        - include_all
    DashboardCandidate:
      type: object
      description: 自定义变量的一个候选项。
      properties:
        text:
          type: string
          minLength: 1
          maxLength: 1024
          description: 选择器中展示的文案。
        value:
          type: string
          minLength: 1
          maxLength: 1024
          description: 替换进模板的取值。
      required:
        - text
        - value
    DashboardVariableQuery:
      description: 变量查询。按 `kind` 选择分支；分支需与所引用数据源类型一致。
      oneOf:
        - $ref: '#/components/schemas/DashboardPrometheusVariableQuery'
        - $ref: '#/components/schemas/DashboardSQLVariableQuery'
        - $ref: '#/components/schemas/DashboardLogsVariableQuery'
      discriminator:
        propertyName: kind
        mapping:
          prometheus: '#/components/schemas/DashboardPrometheusVariableQuery'
          sql: '#/components/schemas/DashboardSQLVariableQuery'
          logs: '#/components/schemas/DashboardLogsVariableQuery'
    DashboardThreshold:
      type: object
      description: 数值的颜色阈值。`warning`/`critical` 至少设置一个；两者都设置时需按 `mode` 满足大小关系。
      properties:
        mode:
          type: string
          enum:
            - higher_is_worse
            - lower_is_worse
          description: 比较方向：`higher_is_worse` = 值高于等于边界即为越限；`lower_is_worse` = 值低于等于边界即为越限。
        warning:
          type:
            - number
            - 'null'
          description: 警告阈值；需为有限数。
        critical:
          type:
            - number
            - 'null'
          description: 严重阈值；需为有限数。
      required:
        - mode
    DashboardColumnOption:
      type: object
      description: 表格中按列的展示覆盖配置。
      properties:
        display_name:
          type: string
          description: 替换原始字段名的表头文案。
        hidden:
          type:
            - boolean
            - 'null'
          description: 隐藏该列；省略表示保持可见。
        width_px:
          type:
            - integer
            - 'null'
          minimum: 80
          maximum: 1200
          description: 列宽（像素），80～1200。
        unit:
          type: string
          enum:
            - unitless
            - ratio
            - percent
            - milliseconds
            - seconds
            - bytes
            - bits
            - count_per_second
            - bytes_per_second
            - bits_per_second
          description: >-
            列展示单位覆盖：`unitless` = 原始数值；`ratio` = 占比（0–1 的小数）；`percent` =
            百分比；`milliseconds` = 毫秒；`seconds` = 秒；`bytes` = 字节；`bits` =
            比特；`count_per_second` = 每秒计数；`bytes_per_second` =
            每秒字节数；`bits_per_second` = 每秒比特数。
        threshold:
          $ref: '#/components/schemas/DashboardThreshold'
        threshold_display:
          type: string
          enum:
            - text
            - background
          description: 阈值的呈现方式：`text` = 为单元格文本着色；`background` = 为单元格背景着色。
        data_link:
          $ref: '#/components/schemas/DashboardDataLink'
    DashboardFieldSort:
      type: object
      description: 单个排序键。
      properties:
        field:
          type: string
          minLength: 1
          description: 排序字段名。
        direction:
          type: string
          enum:
            - asc
            - desc
          description: 排序方向：`asc` = 升序；`desc` = 降序。
      required:
        - field
        - direction
    DashboardDataLink:
      type: object
      description: 从表格列或柱状图面板下钻到另一个仪表盘的链接。目标仪表盘必须存在，且映射来源需与源面板的结构匹配。
      properties:
        dashboard_id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: 目标仪表盘 ID。
        target_id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: 可选的目标 tab/section/panel ID，用于在目标仪表盘中定位。
        pass_time:
          type: boolean
          description: 为 true 时把当前时间范围传递到目标仪表盘。
        variable_mappings:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/DashboardLinkMapping'
          description: 把目标变量名映射到某个来源值，例如表格列或源变量。
      required:
        - dashboard_id
        - pass_time
        - variable_mappings
    ErrorCode:
      type: string
      description: >-
        Flashduty 错误码枚举。每个失败响应的 `error.code` 都是下列稳定值之一，HTTP 状态码仅作参考。


        | 错误码 | HTTP | 含义 |

        |---|---|---|

        | `OK` | 200 | 保留值，正常错误响应不会返回。 |

        | `InvalidParameter` | 400 | 必填参数缺失或未通过校验。 |

        | `BadRequest` | 400 | 通用的 400 错误，通常是请求本身不合法。 |

        | `InvalidContentType` | 400 | 请求头 `Content-Type` 不是 `application/json`。
        |

        | `ResourceNotFound` | 400 | 目标资源不存在。注意 HTTP 状态码是 400 而非 404（历史设计）。 |

        | `NoLicense` | 400 | 功能需要有效授权，但未找到可用的 license。 |

        | `ReferenceExist` | 400 | 该资源仍被其他实体引用，无法删除。 |

        | `Unauthorized` | 401 | `app_key` 缺失、无效或已过期。 |

        | `BalanceNotEnough` | 402 | 账户余额不足，无法执行需要计费的操作。 |

        | `AccessDenied` | 403 | 身份认证通过，但 RBAC 权限不足以执行该操作。 |

        | `RouteNotFound` | 404 | 请求的 URL 路径不是已知路由。 |

        | `MethodNotAllowed` | 405 | 当前路径不接受所使用的 HTTP 方法。 |

        | `UndonedOrderExist` | 409 | 账户存在未完成的订单，请稍后重试。 |

        | `RequestLocked` | 423 | 因连续失败被临时锁定。 |

        | `EntityTooLarge` | 413 | 请求体超过允许的最大长度。 |

        | `RequestTooFrequently` | 429 | 命中限流（全局、账户级或集成级）。 |

        | `RequestVerifyRequired` | 428 | 操作需要二次验证码，但未提供。 |

        | `DangerousOperation` | 428 | 危险操作，需要进行 MFA 验证。 |

        | `InternalError` | 500 | 服务端未预期错误。反馈问题请附上 `request_id`。 |

        | `ServiceUnavailable` | 503 | 后端依赖不可用，请稍后重试。 |
      enum:
        - OK
        - InvalidParameter
        - BadRequest
        - InvalidContentType
        - ResourceNotFound
        - NoLicense
        - ReferenceExist
        - Unauthorized
        - BalanceNotEnough
        - AccessDenied
        - RouteNotFound
        - MethodNotAllowed
        - UndonedOrderExist
        - RequestLocked
        - EntityTooLarge
        - RequestTooFrequently
        - RequestVerifyRequired
        - DangerousOperation
        - InternalError
        - ServiceUnavailable
      x-enumDescriptions:
        OK: 保留值，正常错误响应不会返回。
        InvalidParameter: 必填参数缺失或未通过校验。
        BadRequest: 通用的 400 错误，通常是请求本身不合法。
        InvalidContentType: 请求头 `Content-Type` 不是 `application/json`。
        ResourceNotFound: 目标资源不存在。注意 HTTP 状态码是 400 而非 404（历史设计）。
        NoLicense: 功能需要有效授权，但未找到可用的 license。
        ReferenceExist: 该资源仍被其他实体引用，无法删除。
        Unauthorized: '`app_key` 缺失、无效或已过期。'
        BalanceNotEnough: 账户余额不足，无法执行需要计费的操作。
        AccessDenied: 身份认证通过，但 RBAC 权限不足以执行该操作。
        RouteNotFound: 请求的 URL 路径不是已知路由。
        MethodNotAllowed: 当前路径不接受所使用的 HTTP 方法。
        UndonedOrderExist: 账户存在未完成的订单，请稍后重试。
        RequestLocked: 因连续失败被临时锁定。
        EntityTooLarge: 请求体超过允许的最大长度。
        RequestTooFrequently: 命中限流（全局、账户级或集成级）。
        RequestVerifyRequired: 操作需要二次验证码，但未提供。
        DangerousOperation: 危险操作，需要进行 MFA 验证。
        InternalError: 服务端未预期错误。反馈问题请附上 `request_id`。
        ServiceUnavailable: 后端依赖不可用，请稍后重试。
      example: InvalidParameter
    DashboardPrometheusVariableQuery:
      type: object
      description: Prometheus 标签取值查询。
      properties:
        kind:
          type: string
          enum:
            - prometheus
          description: 查询类型判别字段，固定为 `prometheus`，表示对 Prometheus 执行标签值查询。
        label:
          type: string
          pattern: ^[A-Za-z_][A-Za-z0-9_:.\-]{0,189}$
          description: 取值作为候选项的标签。
        metric:
          type: string
          description: 可选指标名，用于限定参与计算的序列。
        label_filters:
          type: array
          items:
            $ref: '#/components/schemas/DashboardLabelFilter'
          description: 可选匹配条件，在读取标签取值前先缩小序列范围。
      required:
        - kind
        - label
    DashboardSQLVariableQuery:
      type: object
      description: 返回一列候选项的 SQL 查询。
      properties:
        kind:
          type: string
          enum:
            - sql
          description: 查询类型判别字段，固定为 `sql`，表示执行返回单列候选的 SQL 查询。
        expr:
          type: string
          description: SQL 语句；可通过 `{{ }}` 引用其他变量。
        args:
          type: object
          additionalProperties:
            type: string
          description: 具名查询参数；默认为空对象。
        text_field:
          type: string
          description: 作为候选项文案的列；默认与取值列相同。
        value_field:
          type: string
          minLength: 1
          description: 作为候选项取值的列。
      required:
        - kind
        - expr
        - args
        - value_field
    DashboardLogsVariableQuery:
      type: object
      description: 返回某字段取值作为候选项的日志查询。
      properties:
        kind:
          type: string
          enum:
            - logs
          description: 查询类型判别字段，固定为 `logs`，表示执行返回某个字段取值作为候选的日志查询。
        expr:
          type: string
          description: 日志查询表达式；可通过 `{{ }}` 引用其他变量。
        args:
          type: object
          additionalProperties:
            type: string
          description: 具名查询参数；默认为空对象。
        field:
          type: string
          minLength: 1
          description: 取值作为候选项的日志字段。
      required:
        - kind
        - expr
        - args
        - field
    DashboardLinkMapping:
      type: object
      description: 下钻变量映射中的一项。
      properties:
        source:
          type: string
          enum:
            - variable
            - row_column
            - category
            - series
            - value
          description: >-
            取值来源：`variable` = 仪表盘变量；`row_column` = 表格列（必须同时给出
            `column`）；`category` = 柱状图的类目；`series` = 序列名；`value` =
            数值本身。`category`、`series`、`value` 仅对柱状图面板有效。
        column:
          type: string
          description: 来源列名；`source` 为 `row_column` 时必填。
        name:
          type: string
          description: 来源仪表盘变量名；`source` 为 `variable` 时必填。
      required:
        - source
    DashboardLabelFilter:
      type: object
      description: Prometheus 标签匹配条件。
      properties:
        label:
          type: string
          pattern: ^[A-Za-z_][A-Za-z0-9_:.\-]{0,189}$
          description: 标签名。
        op:
          type: string
          enum:
            - '='
            - '!='
            - '=~'
            - '!~'
          description: 匹配操作符：`=` = 等于；`!=` = 不等于；`=~` = 正则匹配；`!~` = 正则不匹配。
        value:
          type: string
          minLength: 1
          description: 匹配值；可通过 `{{ }}` 引用其他变量。
      required:
        - label
        - op
        - value
  responses:
    BadRequest:
      description: 请求非法 — 通常是参数缺失或格式不正确。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingParameter:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: InvalidParameter
                  message: The specified parameter is not valid.
    Unauthorized:
      description: app_key 缺失或无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingAppKey:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: Unauthorized
                  message: You are unauthorized.
    Forbidden:
      description: app_key 有效但没有执行该操作的权限。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            noEditPermission:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: AccessDenied
                  message: Access Denied.
    NotFound:
      description: >-
        目标资源不存在或已被删除。注意：Flashduty 对业务实体的缺失通常返回 HTTP 400 +
        code=`ResourceNotFound`，真正的 404 只用于未知路由。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            resourceMissing:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: ResourceNotFound
                  message: The resource you request is not found
    TooManyRequests:
      description: 命中限流。可能是全局 API 限流、账户级限流或集成级限流。限流按账户聚合。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            rateLimited:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: RequestTooFrequently
                  message: Request too frequently.
    ServerError:
      description: 服务端未预期错误。反馈问题时请携带 request_id。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internal:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: InternalError
                  message: >-
                    We encountered an internal error, and it has been reported.
                    Please try again later.
  securitySchemes:
    AppKeyAuth:
      type: apiKey
      in: query
      name: app_key
      description: >-
        在 Flashduty 控制台 账户 → APP Key 中签发的 app_key。调用任何公开 API
        时都必须携带。它等同于所属账户的身份凭证，请妥善保管。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.