# Query metrics

`POST /metrics`



[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": {
      "post": {
        "tags": [
          "Metrics"
        ],
        "summary": "Query metrics",
        "parameters": [],
        "deprecated": false,
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "filter": {
                    "type": "object",
                    "properties": {
                      "metricName": {
                        "type": "string"
                      },
                      "agentId": {
                        "type": "string"
                      },
                      "podName": {
                        "type": "string"
                      },
                      "subscription": {
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  },
                  "last": {
                    "type": "string",
                    "pattern": "^-?\\d+[dhm]$"
                  },
                  "from": {
                    "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"
                  },
                  "to": {
                    "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"
                  },
                  "rollup": {
                    "type": "object",
                    "properties": {
                      "bucket": {
                        "default": "1 MINUTE",
                        "type": "string",
                        "enum": [
                          "1 MINUTE",
                          "5 MINUTE",
                          "15 MINUTE",
                          "30 MINUTE",
                          "1 HOUR",
                          "6 HOUR",
                          "12 HOUR",
                          "1 DAY",
                          "7 DAY"
                        ]
                      },
                      "agg": {
                        "default": "max",
                        "type": "string",
                        "enum": [
                          "avg",
                          "min",
                          "max",
                          "sum"
                        ]
                      },
                      "groupAgg": {
                        "type": "string",
                        "enum": [
                          "avg",
                          "min",
                          "max",
                          "sum"
                        ]
                      }
                    },
                    "required": [
                      "bucket",
                      "agg"
                    ],
                    "additionalProperties": false
                  },
                  "topN": {
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 100
                  },
                  "rankBy": {
                    "type": "string",
                    "enum": [
                      "avg",
                      "max",
                      "sum"
                    ]
                  },
                  "limit": {
                    "default": 10000,
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 10000
                  },
                  "offset": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000000
                  },
                  "output": {
                    "default": "timeseries",
                    "type": "string",
                    "enum": [
                      "timeseries",
                      "timeseries-by-pod",
                      "timeseries-by-direction",
                      "timeseries-by-group",
                      "timeseries-resource",
                      "timeseries-top-n",
                      "single",
                      "group",
                      "summary",
                      "summary-by-agent",
                      "summary-delta",
                      "table-aggregated",
                      "scalar",
                      "scalar-by-agent",
                      "current-state",
                      "agent-terminated-events"
                    ]
                  }
                },
                "required": [
                  "filter",
                  "limit",
                  "output"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "timestamp": {
                        "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"
                      },
                      "value": {
                        "type": "number"
                      }
                    },
                    "required": [
                      "timestamp",
                      "value"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid search provided",
            "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": {
      "$ErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": [
              "string",
              "number"
            ]
          },
          "message": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {}
          }
        },
        "required": [
          "code",
          "message"
        ],
        "additionalProperties": false
      }
    }
  }
}
```