# Query solution metrics from mongo.changes

`POST /metrics/solution`

Composable analytics queries on any `coll_name` in `mongo.changes`. Set `output` to `value` (scalar KPI), `table` (grouped rows), `pie` (slices), `timeseries` (time series), or `histogram` (numeric distribution). For native-object collections, map JSON Schema properties to `data.<property>` paths. Full guide: [Solution Metrics AI Reference](https://github.com/ContextualIO/observability-api/blob/main/docs/solution-metrics-api.md)

[Observability API guide](https://docs.contextual.io/legacy/tenants/tenant-apis/observability-api.md)

```json
{
  "openapi": "3.0.3",
  "info": {
    "title": "Observability API",
    "description": "Query logs, metrics, traces, and solution analytics against ClickHouse. See **Solution Metrics** endpoints and external docs for the AI reference guide.",
    "version": "1.7.7"
  },
  "security": [
    {
      "jwt": []
    }
  ],
  "servers": [
    {
      "url": "https://observability.{tenantId}.my.contextual.io/api/v1",
      "variables": {
        "tenantId": {
          "default": "YOUR-TENANT-ID"
        }
      }
    }
  ],
  "paths": {
    "/metrics/solution": {
      "post": {
        "tags": [
          "Solution Metrics"
        ],
        "summary": "Query solution metrics from mongo.changes",
        "description": "Composable analytics queries on any `coll_name` in `mongo.changes`. Set `output` to `value` (scalar KPI), `table` (grouped rows), `pie` (slices), `timeseries` (time series), or `histogram` (numeric distribution). For native-object collections, map JSON Schema properties to `data.<property>` paths. Full guide: [Solution Metrics AI Reference](https://github.com/ContextualIO/observability-api/blob/main/docs/solution-metrics-api.md)",
        "parameters": [],
        "deprecated": false,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "coll_name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "coll_name_prefix": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9_-]+:$"
                  },
                  "dedup": {
                    "type": "boolean"
                  },
                  "include_deletes": {
                    "type": "boolean"
                  },
                  "last": {
                    "anyOf": [
                      {
                        "type": "string",
                        "const": "all"
                      },
                      {
                        "type": "string",
                        "pattern": "^-?\\d+(mo|[dhm])$"
                      }
                    ]
                  },
                  "from": {
                    "anyOf": [
                      {
                        "type": "string",
                        "pattern": "^(?:\\d+(?:\\.\\d+?)?|(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z))$",
                        "description": "An ISO 8601 date time string",
                        "format": "date-time"
                      },
                      {
                        "type": "string",
                        "pattern": "^-?\\d+(mo|[dhm])$"
                      }
                    ]
                  },
                  "to": {
                    "anyOf": [
                      {
                        "type": "string",
                        "pattern": "^(?:\\d+(?:\\.\\d+?)?|(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z))$",
                        "description": "An ISO 8601 date time string",
                        "format": "date-time"
                      },
                      {
                        "type": "string",
                        "pattern": "^-?\\d+(mo|[dhm])$"
                      }
                    ]
                  },
                  "output": {
                    "default": "table",
                    "type": "string",
                    "enum": [
                      "value",
                      "table",
                      "pie",
                      "timeseries",
                      "histogram"
                    ]
                  },
                  "time_field": {
                    "anyOf": [
                      {
                        "type": "string",
                        "const": "$wall_time"
                      },
                      {
                        "type": "string",
                        "pattern": "^[a-zA-Z0-9_.]+$"
                      }
                    ]
                  },
                  "time_bucket": {
                    "type": "string",
                    "enum": [
                      "minute",
                      "5minute",
                      "15minute",
                      "30minute",
                      "hour",
                      "6hour",
                      "12hour",
                      "day",
                      "week",
                      "month"
                    ]
                  },
                  "week_start": {
                    "type": "string",
                    "enum": [
                      "sunday",
                      "monday"
                    ]
                  },
                  "select": {
                    "minItems": 1,
                    "maxItems": 250,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "path": {
                          "anyOf": [
                            {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "enum": [
                                    "$wall_time",
                                    "$coll_name",
                                    "$operation",
                                    "$document_key",
                                    "$doc_size"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+$"
                                }
                              ]
                            },
                            {
                              "type": "string",
                              "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                            }
                          ]
                        },
                        "field": {
                          "type": "string",
                          "pattern": "^[a-zA-Z0-9_]+$"
                        },
                        "agg": {
                          "type": "string",
                          "enum": [
                            "sum",
                            "avg",
                            "min",
                            "max",
                            "count",
                            "count_distinct",
                            "p05",
                            "p25",
                            "p50",
                            "p75",
                            "p90",
                            "p95",
                            "p99",
                            "latest",
                            "earliest",
                            "top_values",
                            "samples",
                            "entropy",
                            "corr",
                            "rank_corr",
                            "cramers_v",
                            "mad",
                            "mean_interval"
                          ]
                        },
                        "type": {
                          "default": "string",
                          "type": "string",
                          "enum": [
                            "number",
                            "string",
                            "datetime"
                          ]
                        },
                        "transform": {
                          "oneOf": [
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "replace_prefix"
                                },
                                "prefix": {
                                  "type": "string",
                                  "maxLength": 128,
                                  "pattern": "^[a-zA-Z0-9_:.-]+$"
                                }
                              },
                              "required": [
                                "op",
                                "prefix"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "divide"
                                },
                                "by": {
                                  "type": "number",
                                  "exclusiveMinimum": 0
                                },
                                "round": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 10
                                }
                              },
                              "required": [
                                "op",
                                "by"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "extract"
                                },
                                "pattern": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 256
                                }
                              },
                              "required": [
                                "op",
                                "pattern"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "map"
                                },
                                "values": {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string",
                                    "maxLength": 256
                                  },
                                  "additionalProperties": {
                                    "type": "string",
                                    "maxLength": 256
                                  }
                                },
                                "other": {
                                  "type": "string",
                                  "maxLength": 256
                                }
                              },
                              "required": [
                                "op",
                                "values"
                              ],
                              "additionalProperties": false
                            }
                          ],
                          "type": "object"
                        },
                        "when": {
                          "type": "object",
                          "properties": {
                            "path": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "enum": [
                                    "$coll_name",
                                    "$operation",
                                    "$document_key",
                                    "$doc_size",
                                    "$wall_time"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+$"
                                }
                              ]
                            },
                            "operator": {
                              "type": "string",
                              "enum": [
                                "=",
                                "!=",
                                ">",
                                "<",
                                ">=",
                                "<=",
                                "IN",
                                "NOT IN",
                                "LIKE",
                                "exists",
                                "empty",
                                "match"
                              ]
                            },
                            "value": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "number"
                                },
                                {
                                  "type": "boolean"
                                },
                                {
                                  "type": "array",
                                  "items": {
                                    "type": [
                                      "string",
                                      "number"
                                    ]
                                  }
                                }
                              ]
                            },
                            "measure": {
                              "type": "string",
                              "enum": [
                                "char_length",
                                "byte_length",
                                "array_length"
                              ]
                            }
                          },
                          "required": [
                            "path",
                            "operator",
                            "value"
                          ],
                          "additionalProperties": false
                        },
                        "measure": {
                          "type": "string",
                          "enum": [
                            "char_length",
                            "byte_length",
                            "array_length"
                          ]
                        },
                        "derive": {
                          "type": "object",
                          "properties": {
                            "op": {
                              "type": "string",
                              "enum": [
                                "divide",
                                "multiply",
                                "add",
                                "subtract",
                                "pct",
                                "pct_of_total"
                              ]
                            },
                            "left": {
                              "type": "string",
                              "pattern": "^[a-zA-Z0-9_]+$"
                            },
                            "right": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_]+$"
                                },
                                {
                                  "type": "number"
                                }
                              ]
                            },
                            "round": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 10
                            }
                          },
                          "required": [
                            "op",
                            "left"
                          ],
                          "additionalProperties": false
                        },
                        "window": {
                          "oneOf": [
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "cumulative"
                                }
                              },
                              "required": [
                                "op"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "rolling_avg"
                                },
                                "buckets": {
                                  "type": "integer",
                                  "minimum": 2,
                                  "maximum": 168
                                }
                              },
                              "required": [
                                "op",
                                "buckets"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "delta"
                                }
                              },
                              "required": [
                                "op"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "pct_change"
                                }
                              },
                              "required": [
                                "op"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "op": {
                                  "type": "string",
                                  "const": "ema"
                                },
                                "half_life": {
                                  "type": "number",
                                  "minimum": 0.1,
                                  "maximum": 168
                                }
                              },
                              "required": [
                                "op",
                                "half_life"
                              ],
                              "additionalProperties": false
                            }
                          ],
                          "type": "object"
                        },
                        "k": {
                          "type": "integer",
                          "minimum": 1,
                          "maximum": 50
                        },
                        "weight_path": {
                          "anyOf": [
                            {
                              "type": "string",
                              "const": "$doc_size"
                            },
                            {
                              "type": "string",
                              "pattern": "^[a-zA-Z0-9_.]+$"
                            }
                          ]
                        },
                        "path2": {
                          "anyOf": [
                            {
                              "type": "string",
                              "enum": [
                                "$coll_name",
                                "$operation",
                                "$document_key",
                                "$doc_size"
                              ]
                            },
                            {
                              "type": "string",
                              "pattern": "^[a-zA-Z0-9_.]+$"
                            }
                          ]
                        },
                        "to_now": {
                          "type": "boolean"
                        },
                        "alias": {
                          "type": "string",
                          "pattern": "^[a-zA-Z0-9_]+$"
                        }
                      },
                      "required": [
                        "type",
                        "alias"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "group_by": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "anyOf": [
                        {
                          "type": "string",
                          "pattern": "^[a-zA-Z0-9_.]+$"
                        },
                        {
                          "type": "string",
                          "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "path": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "enum": [
                                    "$coll_name",
                                    "$operation",
                                    "$document_key",
                                    "$wall_time"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+$"
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                }
                              ]
                            },
                            "transform": {
                              "oneOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "op": {
                                      "type": "string",
                                      "const": "replace_prefix"
                                    },
                                    "prefix": {
                                      "type": "string",
                                      "maxLength": 128,
                                      "pattern": "^[a-zA-Z0-9_:.-]+$"
                                    }
                                  },
                                  "required": [
                                    "op",
                                    "prefix"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "op": {
                                      "type": "string",
                                      "const": "extract"
                                    },
                                    "pattern": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 256
                                    }
                                  },
                                  "required": [
                                    "op",
                                    "pattern"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "op": {
                                      "type": "string",
                                      "const": "map"
                                    },
                                    "values": {
                                      "type": "object",
                                      "propertyNames": {
                                        "type": "string",
                                        "maxLength": 256
                                      },
                                      "additionalProperties": {
                                        "type": "string",
                                        "maxLength": 256
                                      }
                                    },
                                    "other": {
                                      "type": "string",
                                      "maxLength": 256
                                    }
                                  },
                                  "required": [
                                    "op",
                                    "values"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "op": {
                                      "type": "string",
                                      "const": "date_part"
                                    },
                                    "part": {
                                      "type": "string",
                                      "enum": [
                                        "hour",
                                        "day_of_week",
                                        "day_of_month",
                                        "month"
                                      ]
                                    }
                                  },
                                  "required": [
                                    "op",
                                    "part"
                                  ],
                                  "additionalProperties": false
                                }
                              ],
                              "type": "object"
                            }
                          },
                          "required": [
                            "path"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "h3": {
                              "type": "object",
                              "properties": {
                                "lat_path": {
                                  "anyOf": [
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+$"
                                    },
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                    }
                                  ]
                                },
                                "lng_path": {
                                  "anyOf": [
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+$"
                                    },
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                    }
                                  ]
                                },
                                "resolution": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 15
                                }
                              },
                              "required": [
                                "lat_path",
                                "lng_path",
                                "resolution"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "required": [
                            "h3"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    }
                  },
                  "ref": {
                    "type": "object",
                    "properties": {
                      "namespace": {
                        "default": "native-object",
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128,
                        "pattern": "^[a-zA-Z0-9_-]+$"
                      },
                      "typeId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128,
                        "pattern": "^[a-zA-Z0-9_-]+$"
                      },
                      "instanceId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128,
                        "pattern": "^[a-zA-Z0-9_-]+$"
                      }
                    },
                    "required": [
                      "namespace",
                      "typeId"
                    ],
                    "additionalProperties": false
                  },
                  "where": {
                    "maxItems": 20,
                    "type": "array",
                    "items": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "path": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "enum": [
                                    "$coll_name",
                                    "$operation",
                                    "$document_key",
                                    "$doc_size"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+$"
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                }
                              ]
                            },
                            "operator": {
                              "type": "string",
                              "enum": [
                                "=",
                                "!=",
                                ">",
                                "<",
                                ">=",
                                "<=",
                                "IN",
                                "NOT IN",
                                "LIKE",
                                "has",
                                "has_all",
                                "has_any",
                                "has_token",
                                "has_token_ci",
                                "exists",
                                "empty",
                                "match"
                              ]
                            },
                            "value": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "number"
                                },
                                {
                                  "type": "boolean"
                                },
                                {
                                  "type": "array",
                                  "items": {
                                    "type": [
                                      "string",
                                      "number"
                                    ]
                                  }
                                }
                              ]
                            },
                            "measure": {
                              "type": "string",
                              "enum": [
                                "char_length",
                                "byte_length",
                                "array_length"
                              ]
                            }
                          },
                          "required": [
                            "path",
                            "operator",
                            "value"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "geo": {
                              "type": "object",
                              "properties": {
                                "lat_path": {
                                  "anyOf": [
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+$"
                                    },
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                    }
                                  ]
                                },
                                "lng_path": {
                                  "anyOf": [
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+$"
                                    },
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                    }
                                  ]
                                },
                                "within_radius": {
                                  "type": "object",
                                  "properties": {
                                    "lat": {
                                      "type": "number",
                                      "minimum": -90,
                                      "maximum": 90
                                    },
                                    "lng": {
                                      "type": "number",
                                      "minimum": -180,
                                      "maximum": 180
                                    },
                                    "radius_m": {
                                      "type": "number",
                                      "exclusiveMinimum": 0,
                                      "maximum": 20015087
                                    }
                                  },
                                  "required": [
                                    "lat",
                                    "lng",
                                    "radius_m"
                                  ],
                                  "additionalProperties": false
                                },
                                "within_polygon": {
                                  "minItems": 3,
                                  "maxItems": 1000,
                                  "type": "array",
                                  "items": {
                                    "type": "array",
                                    "prefixItems": [
                                      {
                                        "type": "number",
                                        "minimum": -180,
                                        "maximum": 180
                                      },
                                      {
                                        "type": "number",
                                        "minimum": -90,
                                        "maximum": 90
                                      }
                                    ],
                                    "items": false,
                                    "minItems": 2,
                                    "maxItems": 2
                                  }
                                }
                              },
                              "required": [
                                "lat_path",
                                "lng_path"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "required": [
                            "geo"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    }
                  },
                  "where_mode": {
                    "anyOf": [
                      {
                        "type": "string",
                        "const": "AND"
                      },
                      {
                        "type": "string",
                        "const": "OR"
                      }
                    ]
                  },
                  "subquery": {
                    "type": "object",
                    "properties": {
                      "group_by": {
                        "minItems": 1,
                        "maxItems": 10,
                        "type": "array",
                        "items": {
                          "anyOf": [
                            {
                              "type": "string",
                              "enum": [
                                "$coll_name",
                                "$operation",
                                "$document_key"
                              ]
                            },
                            {
                              "type": "string",
                              "pattern": "^[a-zA-Z0-9_.]+$"
                            }
                          ]
                        }
                      },
                      "select": {
                        "minItems": 1,
                        "maxItems": 250,
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "path": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "const": "$doc_size"
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+$"
                                }
                              ]
                            },
                            "agg": {
                              "type": "string",
                              "enum": [
                                "sum",
                                "avg",
                                "min",
                                "max",
                                "count",
                                "count_distinct",
                                "p05",
                                "p25",
                                "p50",
                                "p75",
                                "p90",
                                "p95",
                                "p99",
                                "latest",
                                "earliest",
                                "entropy",
                                "funnel",
                                "sequence_count"
                              ]
                            },
                            "type": {
                              "default": "string",
                              "type": "string",
                              "enum": [
                                "number",
                                "string",
                                "datetime"
                              ]
                            },
                            "when": {
                              "type": "object",
                              "properties": {
                                "path": {
                                  "anyOf": [
                                    {
                                      "type": "string",
                                      "enum": [
                                        "$coll_name",
                                        "$operation",
                                        "$document_key",
                                        "$doc_size",
                                        "$wall_time"
                                      ]
                                    },
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+$"
                                    }
                                  ]
                                },
                                "operator": {
                                  "type": "string",
                                  "enum": [
                                    "=",
                                    "!=",
                                    ">",
                                    "<",
                                    ">=",
                                    "<=",
                                    "IN",
                                    "NOT IN",
                                    "LIKE",
                                    "exists",
                                    "empty",
                                    "match"
                                  ]
                                },
                                "value": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "number"
                                    },
                                    {
                                      "type": "boolean"
                                    },
                                    {
                                      "type": "array",
                                      "items": {
                                        "type": [
                                          "string",
                                          "number"
                                        ]
                                      }
                                    }
                                  ]
                                },
                                "measure": {
                                  "type": "string",
                                  "enum": [
                                    "char_length",
                                    "byte_length",
                                    "array_length"
                                  ]
                                }
                              },
                              "required": [
                                "path",
                                "operator",
                                "value"
                              ],
                              "additionalProperties": false
                            },
                            "measure": {
                              "type": "string",
                              "enum": [
                                "char_length",
                                "byte_length",
                                "array_length"
                              ]
                            },
                            "steps": {
                              "minItems": 1,
                              "maxItems": 8,
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "path": {
                                    "anyOf": [
                                      {
                                        "type": "string",
                                        "enum": [
                                          "$coll_name",
                                          "$operation",
                                          "$document_key",
                                          "$doc_size",
                                          "$wall_time"
                                        ]
                                      },
                                      {
                                        "type": "string",
                                        "pattern": "^[a-zA-Z0-9_.]+$"
                                      }
                                    ]
                                  },
                                  "operator": {
                                    "type": "string",
                                    "enum": [
                                      "=",
                                      "!=",
                                      ">",
                                      "<",
                                      ">=",
                                      "<=",
                                      "IN",
                                      "NOT IN",
                                      "LIKE",
                                      "exists",
                                      "empty",
                                      "match"
                                    ]
                                  },
                                  "value": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "number"
                                      },
                                      {
                                        "type": "boolean"
                                      },
                                      {
                                        "type": "array",
                                        "items": {
                                          "type": [
                                            "string",
                                            "number"
                                          ]
                                        }
                                      }
                                    ]
                                  },
                                  "measure": {
                                    "type": "string",
                                    "enum": [
                                      "char_length",
                                      "byte_length",
                                      "array_length"
                                    ]
                                  }
                                },
                                "required": [
                                  "path",
                                  "operator",
                                  "value"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "window_seconds": {
                              "type": "integer",
                              "minimum": 1,
                              "maximum": 2592000
                            },
                            "pattern": {
                              "type": "string",
                              "minLength": 4,
                              "maxLength": 128,
                              "pattern": "^(\\(\\?[1-9]\\d?\\)|\\.\\*|\\.)+$"
                            },
                            "alias": {
                              "type": "string",
                              "pattern": "^[a-zA-Z0-9_]+$"
                            }
                          },
                          "required": [
                            "agg",
                            "type",
                            "alias"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "where": {
                        "maxItems": 20,
                        "type": "array",
                        "items": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "path": {
                                  "anyOf": [
                                    {
                                      "type": "string",
                                      "enum": [
                                        "$coll_name",
                                        "$operation",
                                        "$document_key",
                                        "$doc_size"
                                      ]
                                    },
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+$"
                                    },
                                    {
                                      "type": "string",
                                      "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                    }
                                  ]
                                },
                                "operator": {
                                  "type": "string",
                                  "enum": [
                                    "=",
                                    "!=",
                                    ">",
                                    "<",
                                    ">=",
                                    "<=",
                                    "IN",
                                    "NOT IN",
                                    "LIKE",
                                    "has",
                                    "has_all",
                                    "has_any",
                                    "has_token",
                                    "has_token_ci",
                                    "exists",
                                    "empty",
                                    "match"
                                  ]
                                },
                                "value": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "number"
                                    },
                                    {
                                      "type": "boolean"
                                    },
                                    {
                                      "type": "array",
                                      "items": {
                                        "type": [
                                          "string",
                                          "number"
                                        ]
                                      }
                                    }
                                  ]
                                },
                                "measure": {
                                  "type": "string",
                                  "enum": [
                                    "char_length",
                                    "byte_length",
                                    "array_length"
                                  ]
                                }
                              },
                              "required": [
                                "path",
                                "operator",
                                "value"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "geo": {
                                  "type": "object",
                                  "properties": {
                                    "lat_path": {
                                      "anyOf": [
                                        {
                                          "type": "string",
                                          "pattern": "^[a-zA-Z0-9_.]+$"
                                        },
                                        {
                                          "type": "string",
                                          "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                        }
                                      ]
                                    },
                                    "lng_path": {
                                      "anyOf": [
                                        {
                                          "type": "string",
                                          "pattern": "^[a-zA-Z0-9_.]+$"
                                        },
                                        {
                                          "type": "string",
                                          "pattern": "^[a-zA-Z0-9_.]+\\[\\]\\.[a-zA-Z0-9_.]+$"
                                        }
                                      ]
                                    },
                                    "within_radius": {
                                      "type": "object",
                                      "properties": {
                                        "lat": {
                                          "type": "number",
                                          "minimum": -90,
                                          "maximum": 90
                                        },
                                        "lng": {
                                          "type": "number",
                                          "minimum": -180,
                                          "maximum": 180
                                        },
                                        "radius_m": {
                                          "type": "number",
                                          "exclusiveMinimum": 0,
                                          "maximum": 20015087
                                        }
                                      },
                                      "required": [
                                        "lat",
                                        "lng",
                                        "radius_m"
                                      ],
                                      "additionalProperties": false
                                    },
                                    "within_polygon": {
                                      "minItems": 3,
                                      "maxItems": 1000,
                                      "type": "array",
                                      "items": {
                                        "type": "array",
                                        "prefixItems": [
                                          {
                                            "type": "number",
                                            "minimum": -180,
                                            "maximum": 180
                                          },
                                          {
                                            "type": "number",
                                            "minimum": -90,
                                            "maximum": 90
                                          }
                                        ],
                                        "items": false,
                                        "minItems": 2,
                                        "maxItems": 2
                                      }
                                    }
                                  },
                                  "required": [
                                    "lat_path",
                                    "lng_path"
                                  ],
                                  "additionalProperties": false
                                }
                              },
                              "required": [
                                "geo"
                              ],
                              "additionalProperties": false
                            }
                          ]
                        }
                      },
                      "having": {
                        "maxItems": 20,
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "field": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "enum": [
                                    "$coll_name",
                                    "$operation",
                                    "$document_key"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "pattern": "^[a-zA-Z0-9_.]+$"
                                }
                              ]
                            },
                            "operator": {
                              "type": "string",
                              "enum": [
                                "=",
                                "!=",
                                ">",
                                "<",
                                ">=",
                                "<=",
                                "IN",
                                "NOT IN",
                                "LIKE"
                              ]
                            },
                            "value": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "number"
                                },
                                {
                                  "type": "array",
                                  "items": {
                                    "type": [
                                      "string",
                                      "number"
                                    ]
                                  }
                                }
                              ]
                            }
                          },
                          "required": [
                            "field",
                            "operator",
                            "value"
                          ],
                          "additionalProperties": false
                        }
                      }
                    },
                    "required": [
                      "group_by",
                      "select"
                    ],
                    "additionalProperties": false
                  },
                  "having": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "field": {
                          "type": "string",
                          "pattern": "^[a-zA-Z0-9_]+$"
                        },
                        "operator": {
                          "type": "string",
                          "enum": [
                            "=",
                            "!=",
                            ">",
                            "<",
                            ">=",
                            "<="
                          ]
                        },
                        "value": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "field",
                        "operator",
                        "value"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "anomaly": {
                    "type": "object",
                    "properties": {
                      "method": {
                        "default": "z_score",
                        "type": "string",
                        "enum": [
                          "z_score",
                          "tukey",
                          "flatline"
                        ]
                      },
                      "z_threshold": {
                        "default": 3,
                        "type": "number",
                        "exclusiveMinimum": 0,
                        "maximum": 10
                      },
                      "run_buckets": {
                        "type": "integer",
                        "minimum": 2,
                        "maximum": 500
                      },
                      "only_anomalies": {
                        "default": false,
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "method",
                      "z_threshold",
                      "only_anomalies"
                    ],
                    "additionalProperties": false
                  },
                  "test": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "mann_whitney",
                          "welch_t",
                          "ks",
                          "anova"
                        ]
                      },
                      "split": {
                        "type": "object",
                        "properties": {
                          "path": {
                            "anyOf": [
                              {
                                "type": "string",
                                "enum": [
                                  "$coll_name",
                                  "$operation",
                                  "$document_key",
                                  "$doc_size",
                                  "$wall_time"
                                ]
                              },
                              {
                                "type": "string",
                                "pattern": "^[a-zA-Z0-9_.]+$"
                              }
                            ]
                          },
                          "operator": {
                            "type": "string",
                            "enum": [
                              "=",
                              "!=",
                              ">",
                              "<",
                              ">=",
                              "<=",
                              "IN",
                              "NOT IN",
                              "LIKE",
                              "exists",
                              "empty",
                              "match"
                            ]
                          },
                          "value": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "number"
                              },
                              {
                                "type": "boolean"
                              },
                              {
                                "type": "array",
                                "items": {
                                  "type": [
                                    "string",
                                    "number"
                                  ]
                                }
                              }
                            ]
                          },
                          "measure": {
                            "type": "string",
                            "enum": [
                              "char_length",
                              "byte_length",
                              "array_length"
                            ]
                          }
                        },
                        "required": [
                          "path",
                          "operator",
                          "value"
                        ],
                        "additionalProperties": false
                      },
                      "group": {
                        "anyOf": [
                          {
                            "type": "string",
                            "enum": [
                              "$coll_name",
                              "$operation",
                              "$document_key"
                            ]
                          },
                          {
                            "type": "string",
                            "pattern": "^[a-zA-Z0-9_.]+$"
                          }
                        ]
                      },
                      "min_sample": {
                        "type": "object",
                        "properties": {
                          "mde": {
                            "type": "number",
                            "exclusiveMinimum": 0,
                            "exclusiveMaximum": 1
                          },
                          "power": {
                            "default": 0.8,
                            "type": "number",
                            "minimum": 0.5,
                            "maximum": 0.999
                          },
                          "alpha": {
                            "default": 0.05,
                            "type": "number",
                            "exclusiveMinimum": 0,
                            "maximum": 0.5
                          }
                        },
                        "required": [
                          "mde",
                          "power",
                          "alpha"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "required": [
                      "type"
                    ],
                    "additionalProperties": false
                  },
                  "detect_period": {
                    "type": "boolean"
                  },
                  "decompose": {
                    "type": "object",
                    "properties": {
                      "period": {
                        "type": "integer",
                        "minimum": 2,
                        "maximum": 5000
                      }
                    },
                    "required": [
                      "period"
                    ],
                    "additionalProperties": false
                  },
                  "bins": {
                    "type": "integer",
                    "minimum": 2,
                    "maximum": 100
                  },
                  "bin_edges": {
                    "minItems": 2,
                    "maxItems": 101,
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  },
                  "compare": {
                    "type": "string",
                    "const": "previous_period"
                  },
                  "order_by": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9_,.\\s]+$"
                  },
                  "limit": {
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 100000
                  },
                  "rollup_other": {
                    "anyOf": [
                      {
                        "type": "boolean",
                        "const": true
                      },
                      {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64
                      }
                    ]
                  },
                  "series_limit": {
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 100
                  },
                  "fill": {
                    "type": "boolean"
                  },
                  "sample": {
                    "type": "number",
                    "minimum": 0.000001,
                    "maximum": 0.999999
                  },
                  "debug": {
                    "default": false,
                    "type": "boolean"
                  }
                },
                "required": [
                  "output",
                  "select",
                  "debug"
                ],
                "additionalProperties": false
              },
              "examples": {
                "value_kpi": {
                  "summary": "value — RLA attachment KPIs",
                  "description": "Scalar KPI card: file counts, storage totals, and distinct content types from contextual:files.",
                  "value": {
                    "coll_name": "contextual:files",
                    "last": "-30d",
                    "output": "value",
                    "select": [
                      {
                        "path": "data.meta.size",
                        "agg": "count",
                        "alias": "total_attachments"
                      },
                      {
                        "path": "data.meta.size",
                        "agg": "sum",
                        "alias": "total_storage_bytes"
                      },
                      {
                        "path": "data.meta.size",
                        "agg": "avg",
                        "alias": "avg_file_size_bytes"
                      },
                      {
                        "path": "data.meta.contentType",
                        "agg": "count_distinct",
                        "alias": "unique_content_types"
                      }
                    ],
                    "where": [
                      {
                        "path": "data.meta.contentType",
                        "operator": "!=",
                        "value": ""
                      }
                    ]
                  }
                },
                "table_breakdown": {
                  "summary": "table — trigger events by type",
                  "description": "Grouped table rows with event counts and distinct instance ids, ordered by count.",
                  "value": {
                    "coll_name": "native-object:trigger-event",
                    "last": "-30d",
                    "output": "table",
                    "select": [
                      {
                        "agg": "count",
                        "alias": "event_count"
                      },
                      {
                        "path": "data.id",
                        "agg": "count_distinct",
                        "alias": "unique_instances"
                      }
                    ],
                    "group_by": [
                      "data.type"
                    ],
                    "order_by": "event_count DESC",
                    "limit": 50
                  }
                },
                "pie_distribution": {
                  "summary": "pie — events by data.type",
                  "description": "Pie/donut chart slices. Requires exactly one select metric and one group_by field.",
                  "value": {
                    "coll_name": "native-object:trigger-event",
                    "last": "-30d",
                    "output": "pie",
                    "select": [
                      {
                        "agg": "count",
                        "alias": "events"
                      }
                    ],
                    "group_by": [
                      "data.type"
                    ],
                    "limit": 15
                  }
                },
                "timeseries_hourly": {
                  "summary": "timeseries — hourly events by type",
                  "description": "Line/bar chart over time with optional series split via group_by. Requires time_bucket.",
                  "value": {
                    "coll_name": "native-object:trigger-event",
                    "from": "2026-07-28T00:00:00Z",
                    "to": "2026-07-31T00:00:00Z",
                    "output": "timeseries",
                    "time_bucket": "hour",
                    "select": [
                      {
                        "agg": "count",
                        "alias": "events"
                      }
                    ],
                    "group_by": [
                      "data.type"
                    ],
                    "where": [
                      {
                        "path": "data.type",
                        "operator": "!=",
                        "value": ""
                      }
                    ]
                  }
                },
                "timeseries_created": {
                  "summary": "timeseries — creations by Monday-anchored week",
                  "description": "Birth-rate chart: from/to/last, bucketing, fill, and windows use the document's createdAt rather than $wall_time.",
                  "value": {
                    "coll_name": "native-object:sow",
                    "last": "-3mo",
                    "dedup": true,
                    "output": "timeseries",
                    "time_field": "createdAt",
                    "time_bucket": "week",
                    "week_start": "monday",
                    "fill": true,
                    "select": [
                      {
                        "agg": "count",
                        "window": {
                          "op": "rolling_avg",
                          "buckets": 4
                        },
                        "alias": "sows"
                      }
                    ]
                  }
                },
                "value_created": {
                  "summary": "value — SOWs created in the last 3 months",
                  "description": "KPI card on creation time: last/from/to filter createdAt. wall_time is still pruned from `from` onward.",
                  "value": {
                    "coll_name": "native-object:sow",
                    "last": "-3mo",
                    "dedup": true,
                    "output": "value",
                    "time_field": "createdAt",
                    "select": [
                      {
                        "agg": "count",
                        "alias": "sows"
                      }
                    ]
                  }
                },
                "value_mean_interval": {
                  "summary": "value — mean gap between SOW births",
                  "description": "Consecutive createdAt spacing in seconds. Pair with time_field so last/from/to are births, not updates.",
                  "value": {
                    "coll_name": "native-object:sow",
                    "last": "-3mo",
                    "dedup": true,
                    "output": "value",
                    "time_field": "createdAt",
                    "select": [
                      {
                        "path": "createdAt",
                        "agg": "mean_interval",
                        "alias": "avg_gap_s"
                      }
                    ]
                  }
                },
                "value_created_bounds": {
                  "summary": "value — earliest and latest createdAt (picker bounds)",
                  "description": "Datetime min/max on createdAt parse ISO / DateTime64 (not string order).",
                  "value": {
                    "coll_name": "native-object:sow",
                    "last": "all",
                    "dedup": true,
                    "output": "value",
                    "select": [
                      {
                        "path": "createdAt",
                        "agg": "min",
                        "alias": "first_created"
                      },
                      {
                        "path": "createdAt",
                        "agg": "max",
                        "alias": "last_created"
                      }
                    ]
                  }
                },
                "value_alert_over_limit": {
                  "summary": "value — alert: descriptions over maxLength, with example ids",
                  "description": "Ungrouped KPI for an alert scheduler: count rows over 80% of a 255-char maxLength, sample id values for the ticket, drop the row when n < 10 (empty data = don't fire).",
                  "value": {
                    "coll_name": "native-object:upload-request",
                    "last": "-1h",
                    "dedup": true,
                    "output": "value",
                    "select": [
                      {
                        "agg": "count",
                        "alias": "total"
                      },
                      {
                        "agg": "count",
                        "alias": "over_limit",
                        "when": {
                          "path": "data.description",
                          "measure": "char_length",
                          "operator": ">",
                          "value": 204
                        }
                      },
                      {
                        "path": "id",
                        "agg": "samples",
                        "k": 5,
                        "alias": "example_ids",
                        "when": {
                          "path": "data.description",
                          "measure": "char_length",
                          "operator": ">",
                          "value": 204
                        }
                      },
                      {
                        "derive": {
                          "op": "pct",
                          "left": "over_limit",
                          "right": "total"
                        },
                        "alias": "pct_over"
                      }
                    ],
                    "having": [
                      {
                        "field": "total",
                        "operator": ">=",
                        "value": 10
                      }
                    ]
                  }
                }
              }
            }
          },
          "description": "Query body. Use the Examples dropdown for one request per output type (value, table, pie, timeseries)."
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$SolutionMetricsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {}
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "jwt": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "$SolutionMetricsResponse": {
        "type": "object",
        "properties": {
          "output": {
            "type": "string",
            "enum": [
              "value",
              "table",
              "pie",
              "timeseries",
              "histogram"
            ]
          },
          "data": {
            "anyOf": [
              {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {}
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {}
                }
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "value": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "label",
                    "value"
                  ],
                  "additionalProperties": false
                }
              }
            ]
          },
          "meta": {
            "type": "object",
            "properties": {
              "metrics": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "series_keys": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "time_bucket": {
                "type": "string"
              },
              "time_field": {
                "type": "string"
              },
              "week_start": {
                "type": "string",
                "enum": [
                  "sunday",
                  "monday"
                ]
              },
              "dedup": {
                "type": "boolean"
              },
              "deletes_excluded": {
                "type": "boolean"
              },
              "sql_generated": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "output",
          "data",
          "meta"
        ],
        "additionalProperties": false
      },
      "$ErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": [
              "string",
              "number"
            ]
          },
          "message": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {}
          }
        },
        "required": [
          "code",
          "message"
        ],
        "additionalProperties": false
      }
    }
  }
}
```