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

# Run a cost query

> Executes a CEL query and returns either a time series (`kind: series`) or a period-over-period comparison (`kind: comparison`) when `compare.enabled` is true. Organization comes from the authenticated principal (Clerk session JWT or `ak_*` API key). When `datePreset` is sent alongside `from`/`to`, the preset wins. An omitted `limit` is server-chosen (currently between 10 and 200 depending on the chart shape), not a flat default of 100. Optional `analyze.changePoint` (`true` or `{ ignoreWeekends }`) runs change-point detection once per query after a successful series result; Billy failures attach `analyze.changePoint[].status: failed` without failing the query. Incompatible with comparison. Optional `forecast: true` (Current Month / Current Quarter / Current Year, Day/Week/Month/Period) appends Billy forecast days onto the series: response `splitDate`, per-point `yhatLower`/`yhatUpper` on Day grain, or `forecastSkipReason: not_enough_history` when there are fewer than 21 training days. YTD/MTD + `forecast: true` is ignored. Billy failures degrade to observed-only without failing the query.



## OpenAPI

````yaml https://app-api.costory.io/docs/openapi.json post /queries/run
openapi: 3.0.0
info:
  title: Costory
  version: '1.0'
  description: API Documentation
servers:
  - url: ''
    description: Production server
security: []
paths:
  /queries/run:
    post:
      tags:
        - Query Costs
      summary: Run a cost query
      description: >-
        Executes a CEL query and returns either a time series (`kind: series`)
        or a period-over-period comparison (`kind: comparison`) when
        `compare.enabled` is true. Organization comes from the authenticated
        principal (Clerk session JWT or `ak_*` API key). When `datePreset` is
        sent alongside `from`/`to`, the preset wins. An omitted `limit` is
        server-chosen (currently between 10 and 200 depending on the chart
        shape), not a flat default of 100. Optional `analyze.changePoint`
        (`true` or `{ ignoreWeekends }`) runs change-point detection once per
        query after a successful series result; Billy failures attach
        `analyze.changePoint[].status: failed` without failing the query.
        Incompatible with comparison. Optional `forecast: true` (Current Month /
        Current Quarter / Current Year, Day/Week/Month/Period) appends Billy
        forecast days onto the series: response `splitDate`, per-point
        `yhatLower`/`yhatUpper` on Day grain, or `forecastSkipReason:
        not_enough_history` when there are fewer than 21 training days. YTD/MTD
        + `forecast: true` is ignored. Billy failures degrade to observed-only
        without failing the query.
      operationId: runQuery
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueryRequest'
      responses:
        '200':
          description: Query result, discriminated by `kind`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryResponse'
        '400':
          description: >-
            Invalid query (strict CEL contract, formula refs, period, group-by,
            or other request rules)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidQueryError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Unauthorized'
        '403':
          description: >-
            Hourly granularity requires Costory Pro, or the external-metric
            provider denied access
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/HourlyGranularityForbiddenError'
                  - $ref: '#/components/schemas/ExternalMetricUnauthorizedError'
        '404':
          description: >-
            Scope, external-metric integration, or provider metric absent or not
            visible to this organization
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/QueryNotFoundError'
                  - $ref: >-
                      #/components/schemas/ExternalMetricIntegrationNotFoundError
                  - $ref: '#/components/schemas/ExternalMetricNotFoundError'
        '500':
          description: Unexpected server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerError'
      security:
        - bearerAuth: []
components:
  schemas:
    QueryRequest:
      type: object
      properties:
        queries:
          type: array
          items:
            oneOf:
              - type: object
                properties:
                  type:
                    type: string
                    enum:
                      - cost
                    description: >-
                      Required series discriminator — always set explicitly,
                      never omit. One of: "cost" | "metric" | "usage" |
                      "formula" | "budget" | "externalMetric".
                  groupBy:
                    anyOf:
                      - type: string
                      - type: array
                        items:
                          type: string
                          minLength: 1
                      - nullable: true
                        type: string
                        enum:
                          - null
                  rollingAggregation:
                    type: object
                    properties:
                      aggregator:
                        type: string
                        enum:
                          - SUM
                          - AVG
                          - MAX
                          - MIN
                      window:
                        type: object
                        properties:
                          preset:
                            type: string
                            enum:
                              - MONTH
                              - WEEK
                          relativeDays:
                            type: integer
                            minimum: 1
                    required:
                      - aggregator
                      - window
                  name:
                    type: string
                    pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                    description: >-
                      Required series identifier referenced by formulas (e.g.
                      "a", "b", "a__r6"). Prefer short identifiers; put human
                      labels in alias — never spaces or descriptive phrases in
                      name.
                  alias:
                    type: string
                    minLength: 1
                    maxLength: 50
                    description: >-
                      Optional human-readable label (e.g. "Cost by environment",
                      "AWS spend"). Prefer short identifiers in name; put
                      descriptive text here.
                  filterCel:
                    type: string
                    nullable: true
                    description: >-
                      Optional scope filter as CEL (Common Expression Language).
                      Examples: cos_service_name in ["AmazonEC2"]; cos_provider
                      in ["AWS"] && cos_environment in ["prod"]. Label
                      dimensions use the cos_ prefix; native provider fields
                      omit it. Unlabelled/untagged resources have null values;
                      use == null to match them (e.g. cos_environment == null)
                      and != null to exclude them. Omit or pass empty string for
                      no filter.
                  metricId:
                    type: string
                    enum:
                      - cost
                      - effective_cost
                      - list_cost
                      - contracted_cost
                      - unblended_cost
                      - net_unblended_cost
                      - amortized_cost
                      - net_amortized_cost
                    default: cost
                    description: >-
                      Cost column to query (e.g. "cost", "effective_cost",
                      "amortized_cost"). Defaults to "cost".
                  currency:
                    type: string
                    enum:
                      - USD
                      - EUR
                      - GBP
                      - CNY
                      - KRW
                    default: USD
                    description: >-
                      Currency for cost values (USD, EUR, GBP). Defaults to
                      "USD".
                  chartType:
                    type: string
                    enum:
                      - BAR
                      - LINE
                      - AREA
                      - WATERFALL
                      - TABLE
                    description: >-
                      Explorer chart for this series: BAR, LINE, AREA,
                      WATERFALL, or TABLE. Omit to use LINE.
                  aggregator:
                    type: string
                    enum:
                      - SUM
                      - AVG
                      - MAX
                      - MIN
                    description: Aggregation over the bucket. Defaults to SUM.
                  reducer:
                    type: string
                    enum:
                      - SUM
                      - AVG
                      - MAX
                      - MIN
                  shiftAmount:
                    type: integer
                  shiftUnit:
                    type: string
                    enum:
                      - DAY
                      - WEEK
                      - MONTH
                  excludeGroupByValue:
                    type: object
                    properties:
                      source:
                        type: object
                        properties:
                          type:
                            type: string
                            enum:
                              - indexation
                        required:
                          - type
                        additionalProperties: false
                    required:
                      - source
                    additionalProperties: false
                    description: >-
                      Exclude group-by values already present in the
                      billing-stats indexation catalog before the query window.
                      HTTP API only; not available on MCP query.
                required:
                  - type
                  - name
                additionalProperties: false
              - type: object
                properties:
                  type:
                    type: string
                    enum:
                      - metric
                    description: >-
                      Required series discriminator — always set explicitly,
                      never omit. One of: "cost" | "metric" | "usage" |
                      "formula" | "budget" | "externalMetric".
                  groupBy:
                    anyOf:
                      - type: string
                      - type: array
                        items:
                          type: string
                          minLength: 1
                      - nullable: true
                        type: string
                        enum:
                          - null
                  metricId:
                    type: string
                    description: >-
                      Saved Costory metric id from list_metrics metrics[].id.
                      This is the query identity — not list_metrics
                      `datasourceId` (that filter only returns groupBy
                      dimensions for telemetry).
                  name:
                    type: string
                    pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                    description: >-
                      Required series identifier referenced by formulas (e.g.
                      "a", "b", "a__r6"). Prefer short identifiers; put human
                      labels in alias — never spaces or descriptive phrases in
                      name.
                  alias:
                    type: string
                    minLength: 1
                    maxLength: 50
                    description: >-
                      Optional human-readable label (e.g. "Cost by environment",
                      "AWS spend"). Prefer short identifiers in name; put
                      descriptive text here.
                  chartType:
                    type: string
                    enum:
                      - BAR
                      - LINE
                      - AREA
                      - WATERFALL
                      - TABLE
                    description: >-
                      Explorer chart for this series: BAR, LINE, AREA,
                      WATERFALL, or TABLE. Omit to use LINE.
                  aggregator:
                    type: string
                    enum:
                      - SUM
                      - AVG
                      - MAX
                      - MIN
                    description: Aggregation over the bucket. Defaults to SUM.
                  reducer:
                    type: string
                    enum:
                      - SUM
                      - AVG
                      - MAX
                      - MIN
                  shiftAmount:
                    type: integer
                  shiftUnit:
                    type: string
                    enum:
                      - DAY
                      - WEEK
                      - MONTH
                  rollingAggregation:
                    type: object
                    properties:
                      aggregator:
                        type: string
                        enum:
                          - SUM
                          - AVG
                          - MAX
                          - MIN
                      window:
                        type: object
                        properties:
                          preset:
                            type: string
                            enum:
                              - MONTH
                              - WEEK
                          relativeDays:
                            type: integer
                            minimum: 1
                    required:
                      - aggregator
                      - window
                  rawMetric:
                    type: string
                  unitOverride:
                    type: string
                required:
                  - type
                  - metricId
                  - name
                additionalProperties: false
              - type: object
                properties:
                  type:
                    type: string
                    enum:
                      - usage
                    description: >-
                      Required series discriminator — always set explicitly,
                      never omit. One of: "cost" | "metric" | "usage" |
                      "formula" | "budget" | "externalMetric".
                  groupBy:
                    anyOf:
                      - type: string
                      - type: array
                        items:
                          type: string
                          minLength: 1
                      - nullable: true
                        type: string
                        enum:
                          - null
                  metricId:
                    type: string
                    description: >-
                      Usage metric id (from suggest_usage_metrics). Either a
                      billing consumed_unit (e.g. "hours") or an enrichment
                      metric column published by an integration — those start
                      with `query_` (e.g. query_compute_ms, query_bytes_billed)
                      and are only available to orgs with that integration.
                      Distinct from cost metricId and from list_metrics
                      datasourceId.
                  name:
                    type: string
                    pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                    description: >-
                      Required series identifier referenced by formulas (e.g.
                      "a", "b", "a__r6"). Prefer short identifiers; put human
                      labels in alias — never spaces or descriptive phrases in
                      name.
                  alias:
                    type: string
                    minLength: 1
                    maxLength: 50
                    description: >-
                      Optional human-readable label (e.g. "Cost by environment",
                      "AWS spend"). Prefer short identifiers in name; put
                      descriptive text here.
                  filterCel:
                    type: string
                    nullable: true
                    description: >-
                      Optional scope filter as CEL (Common Expression Language).
                      Examples: cos_service_name in ["AmazonEC2"]; cos_provider
                      in ["AWS"] && cos_environment in ["prod"]. Label
                      dimensions use the cos_ prefix; native provider fields
                      omit it. Unlabelled/untagged resources have null values;
                      use == null to match them (e.g. cos_environment == null)
                      and != null to exclude them. Omit or pass empty string for
                      no filter.
                  chartType:
                    type: string
                    enum:
                      - BAR
                      - LINE
                      - AREA
                      - WATERFALL
                      - TABLE
                    description: >-
                      Explorer chart for this series: BAR, LINE, AREA,
                      WATERFALL, or TABLE. Omit to use LINE.
                  aggregator:
                    type: string
                    enum:
                      - SUM
                      - AVG
                      - MAX
                      - MIN
                    description: Aggregation over the bucket. Defaults to SUM.
                  reducer:
                    type: string
                    enum:
                      - SUM
                      - AVG
                      - MAX
                      - MIN
                  shiftAmount:
                    type: integer
                  shiftUnit:
                    type: string
                    enum:
                      - DAY
                      - WEEK
                      - MONTH
                  rollingAggregation:
                    type: object
                    properties:
                      aggregator:
                        type: string
                        enum:
                          - SUM
                          - AVG
                          - MAX
                          - MIN
                      window:
                        type: object
                        properties:
                          preset:
                            type: string
                            enum:
                              - MONTH
                              - WEEK
                          relativeDays:
                            type: integer
                            minimum: 1
                    required:
                      - aggregator
                      - window
                  excludeGroupByValue:
                    type: object
                    properties:
                      source:
                        type: object
                        properties:
                          type:
                            type: string
                            enum:
                              - indexation
                        required:
                          - type
                        additionalProperties: false
                    required:
                      - source
                    additionalProperties: false
                    description: >-
                      Exclude group-by values already present in the
                      billing-stats indexation catalog before the query window.
                      HTTP API only; not available on MCP query.
                required:
                  - type
                  - metricId
                  - name
                additionalProperties: false
              - type: object
                properties:
                  type:
                    type: string
                    enum:
                      - formula
                    description: >-
                      Required series discriminator — always set explicitly,
                      never omit. One of: "cost" | "metric" | "usage" |
                      "formula" | "budget" | "externalMetric".
                  formula:
                    type: string
                  unitOverride:
                    type: string
                    description: >-
                      Optional unit override. Omit to infer from formula inputs.
                      Currency codes (EUR, USD, GBP, CNY, KRW) format as money
                      and follow the widget/dashboard currency; any other string
                      (e.g. "slot-h/TiB", "%") is displayed as-is.
                  name:
                    type: string
                    pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                    description: >-
                      Required series identifier referenced by formulas (e.g.
                      "a", "b", "a__r6"). Prefer short identifiers; put human
                      labels in alias — never spaces or descriptive phrases in
                      name.
                  alias:
                    type: string
                    minLength: 1
                    maxLength: 50
                    description: >-
                      Optional human-readable label (e.g. "Cost by environment",
                      "AWS spend"). Prefer short identifiers in name; put
                      descriptive text here.
                  chartType:
                    type: string
                    enum:
                      - BAR
                      - LINE
                      - AREA
                      - WATERFALL
                      - TABLE
                    description: >-
                      Explorer chart for this series: BAR, LINE, AREA,
                      WATERFALL, or TABLE. Omit to use LINE.
                  shiftAmount:
                    type: integer
                  shiftUnit:
                    type: string
                    enum:
                      - DAY
                      - WEEK
                      - MONTH
                  rollingAggregation:
                    type: object
                    properties:
                      aggregator:
                        type: string
                        enum:
                          - SUM
                          - AVG
                          - MAX
                          - MIN
                      window:
                        type: object
                        properties:
                          preset:
                            type: string
                            enum:
                              - MONTH
                              - WEEK
                          relativeDays:
                            type: integer
                            minimum: 1
                    required:
                      - aggregator
                      - window
                required:
                  - type
                  - formula
                  - name
                additionalProperties: false
              - type: object
                properties:
                  type:
                    type: string
                    enum:
                      - budget
                    description: >-
                      Required series discriminator — always set explicitly,
                      never omit. One of: "cost" | "metric" | "usage" |
                      "formula" | "budget" | "externalMetric".
                  budgetId:
                    type: string
                  virtualDimensionValue:
                    type: string
                  rollingAggregation:
                    type: object
                    properties:
                      aggregator:
                        type: string
                        enum:
                          - SUM
                          - AVG
                          - MAX
                          - MIN
                      window:
                        type: object
                        properties:
                          preset:
                            type: string
                            enum:
                              - MONTH
                              - WEEK
                          relativeDays:
                            type: integer
                            minimum: 1
                    required:
                      - aggregator
                      - window
                  name:
                    type: string
                    pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                    description: >-
                      Required series identifier referenced by formulas (e.g.
                      "a", "b", "a__r6"). Prefer short identifiers; put human
                      labels in alias — never spaces or descriptive phrases in
                      name.
                  alias:
                    type: string
                    minLength: 1
                    maxLength: 50
                    description: >-
                      Optional human-readable label (e.g. "Cost by environment",
                      "AWS spend"). Prefer short identifiers in name; put
                      descriptive text here.
                  chartType:
                    type: string
                    enum:
                      - BAR
                      - LINE
                      - AREA
                      - WATERFALL
                      - TABLE
                    description: >-
                      Explorer chart for this series: BAR, LINE, AREA,
                      WATERFALL, or TABLE. Omit to use LINE.
                  groupBy:
                    anyOf:
                      - type: string
                      - type: array
                        items:
                          type: string
                          minLength: 1
                      - nullable: true
                        type: string
                        enum:
                          - null
                    description: >-
                      Split by budget line. Must be this budget's virtual
                      dimension bqName from get. Omit for the total. Sibling
                      cost/usage/metric groupBy must be that same field so
                      formulas match per line.
                required:
                  - type
                  - budgetId
                  - name
                additionalProperties: false
              - type: object
                properties:
                  type:
                    type: string
                    enum:
                      - externalMetric
                    description: >-
                      Required series discriminator — always set explicitly,
                      never omit. One of: "cost" | "metric" | "usage" |
                      "formula" | "budget" | "externalMetric".
                  integrationId:
                    type: string
                    minLength: 1
                    description: >-
                      External metric integration ID from
                      list_metrics(includeExternal: true).
                  metricName:
                    type: string
                    default: ''
                  aggregator:
                    type: string
                    enum:
                      - SUM
                      - AVG
                      - MAX
                      - MIN
                  groupByFields:
                    type: array
                    items:
                      type: string
                      minLength: 1
                    maxItems: 7
                    default: []
                  conditions:
                    type: string
                  query:
                    type: string
                    minLength: 1
                  dateColumn:
                    type: string
                    minLength: 1
                  metricColumn:
                    type: string
                    minLength: 1
                  gapFillingMethod:
                    type: string
                    enum:
                      - ZERO
                      - FORWARD_FILL
                      - LINEAR_INTERPOLATION
                      - SPREAD
                  rollingAggregation:
                    type: object
                    properties:
                      aggregator:
                        type: string
                        enum:
                          - SUM
                          - AVG
                          - MAX
                          - MIN
                      window:
                        type: object
                        properties:
                          preset:
                            type: string
                            enum:
                              - MONTH
                              - WEEK
                          relativeDays:
                            type: integer
                            minimum: 1
                    required:
                      - aggregator
                      - window
                  provider:
                    type: string
                    enum:
                      - tsuga
                      - bigquery
                      - datadog
                      - cloudwatch
                      - s3
                      - amplitude
                      - snowflake
                      - cloudmonitoring
                      - push
                    default: tsuga
                    description: >-
                      External metric provider. Defaults to "tsuga" when omitted
                      for backward compatibility with existing Tsuga MCP
                      clients.
                  name:
                    type: string
                    pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                    description: >-
                      Required series identifier referenced by formulas (e.g.
                      "a", "b", "a__r6"). Prefer short identifiers; put human
                      labels in alias — never spaces or descriptive phrases in
                      name.
                  alias:
                    type: string
                    minLength: 1
                    maxLength: 50
                    description: >-
                      Optional human-readable label (e.g. "Cost by environment",
                      "AWS spend"). Prefer short identifiers in name; put
                      descriptive text here.
                  chartType:
                    type: string
                    enum:
                      - BAR
                      - LINE
                      - AREA
                      - WATERFALL
                      - TABLE
                    description: >-
                      Explorer chart for this series: BAR, LINE, AREA,
                      WATERFALL, or TABLE. Omit to use LINE.
                  unitOverride:
                    type: string
                required:
                  - type
                  - integrationId
                  - name
                additionalProperties: false
            discriminator:
              propertyName: type
          minItems: 1
          maxItems: 26
        datePreset:
          type: string
          enum:
            - TRAILING_90_DAYS
            - TRAILING_30_DAYS
            - TRAILING_45_DAYS
            - TRAILING_7_DAYS
            - TRAILING_3_DAYS
            - TRAILING_1_DAYS
            - TRAILING_14_WEEKS
            - MTD
            - QTD
            - YTD
            - CURRENT_MONTH
            - CURRENT_QUARTER
            - CURRENT_YEAR
            - LAST_WEEK
            - LAST_MONTH
            - LAST_6_MONTHS
            - LAST_12_MONTHS
            - LAST_4_YEARS
            - LAST_3_MONTHS
            - LAST_INVOICE_MONTH
        from:
          type: string
          pattern: ^\d{4}-\d{2}-\d{2}$
        to:
          type: string
          pattern: ^\d{4}-\d{2}-\d{2}$
        aggBy:
          type: string
          enum:
            - Hour
            - Day
            - Week
            - Month
            - Period
          default: Month
        forecastDays:
          type: integer
          minimum: 0
        forecast:
          type: boolean
        compare:
          type: object
          properties:
            enabled:
              type: boolean
              default: true
            from:
              type: string
              pattern: ^\d{4}-\d{2}-\d{2}$
            to:
              type: string
              pattern: ^\d{4}-\d{2}-\d{2}$
            chartType:
              type: string
              enum:
                - WATERFALL
                - TABLE
                - KPI_BREAKDOWN
              default: WATERFALL
          additionalProperties: false
        analyze:
          type: object
          properties:
            changePoint:
              anyOf:
                - type: boolean
                - type: object
                  properties:
                    ignoreWeekends:
                      type: boolean
                      description: >-
                        Drop Saturday/Sunday before detection. Maps to Billy
                        `no_weekends`.
                  additionalProperties: false
          additionalProperties: false
        limit:
          type: integer
          minimum: 1
          maximum: 1000
        scopeId:
          type: string
          nullable: true
        displayOptions:
          type: object
          properties:
            sort:
              type: object
              properties:
                by:
                  type: string
                  minLength: 1
                direction:
                  type: string
                  enum:
                    - ASC
                    - DESC
                  default: DESC
              required:
                - by
            hideEmptyRows:
              type: boolean
            topN:
              type: integer
              minimum: 1
              maximum: 100
            showTotal:
              type: boolean
            precision:
              type: integer
              minimum: 0
              maximum: 6
            pivot:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: string
                    enum:
                      - groupBy
                      - query
                      - time
                  minItems: 1
                columns:
                  type: array
                  items:
                    type: string
                    enum:
                      - groupBy
                      - query
                      - time
                  minItems: 1
              required:
                - rows
                - columns
              additionalProperties: false
          additionalProperties: false
      required:
        - queries
      additionalProperties: false
    QueryResponse:
      oneOf:
        - type: object
          properties:
            kind:
              type: string
              enum:
                - series
            data:
              type: object
              properties:
                outputData:
                  type: array
                  items:
                    type: object
                    properties:
                      date:
                        type: string
                        nullable: true
                        format: date-time
                      values:
                        type: array
                        items:
                          type: object
                          properties:
                            groupByValue:
                              type: string
                            queryName:
                              type: string
                            value:
                              type: number
                            yhatLower:
                              type: number
                            yhatUpper:
                              type: number
                          required:
                            - groupByValue
                            - queryName
                            - value
                    required:
                      - date
                      - values
                series:
                  type: array
                  items:
                    type: object
                    properties:
                      queryName:
                        type: string
                      groupByValue:
                        type: string
                      totals:
                        type: number
                      unit:
                        type: string
                    required:
                      - queryName
                      - groupByValue
                      - totals
                      - unit
                aggBy:
                  type: string
                  enum:
                    - Hour
                    - Day
                    - Week
                    - Month
                    - Period
                splitDate:
                  type: string
                  pattern: ^\d{4}-\d{2}-\d{2}$
                forecastSkipReason:
                  type: string
                  enum:
                    - not_enough_history
              required:
                - outputData
                - series
                - aggBy
            analyze:
              type: object
              properties:
                changePoint:
                  type: array
                  items:
                    oneOf:
                      - type: object
                        properties:
                          queryName:
                            type: string
                          status:
                            type: string
                            enum:
                              - completed
                          error_message:
                            type: string
                            enum:
                              - ''
                          periods:
                            type: array
                            items:
                              type: object
                              properties:
                                start:
                                  anyOf:
                                    - type: string
                                      format: date
                                    - type: string
                                      format: date-time
                                stop:
                                  anyOf:
                                    - type: string
                                      format: date
                                    - type: string
                                      format: date-time
                                type:
                                  type: string
                                  enum:
                                    - no trend
                                    - increasing
                                    - decreasing
                                    - peak
                                    - step up
                                    - step down
                                stats:
                                  type: object
                                  properties:
                                    mean:
                                      type: number
                                    max:
                                      type: number
                                    head:
                                      type: number
                                    tail:
                                      type: number
                                  required:
                                    - mean
                                    - max
                                    - head
                                    - tail
                                  additionalProperties: false
                              required:
                                - start
                                - stop
                                - type
                                - stats
                              additionalProperties: false
                        required:
                          - queryName
                          - status
                          - error_message
                          - periods
                        additionalProperties: false
                      - type: object
                        properties:
                          queryName:
                            type: string
                          status:
                            type: string
                            enum:
                              - failed
                          error_message:
                            type: string
                        required:
                          - queryName
                          - status
                          - error_message
                        additionalProperties: false
              required:
                - changePoint
              additionalProperties: false
          required:
            - kind
            - data
        - type: object
          properties:
            kind:
              type: string
              enum:
                - comparison
            data:
              type: object
              properties:
                outputData:
                  type: array
                  items:
                    type: object
                    properties:
                      comparisonPeriodValue:
                        type: number
                      selectedPeriodValue:
                        type: number
                      difference:
                        type: number
                      percentageChange:
                        type: number
                      queryName:
                        type: string
                      groupByValue:
                        type: string
                    required:
                      - comparisonPeriodValue
                      - selectedPeriodValue
                      - difference
                      - percentageChange
                      - queryName
                      - groupByValue
                series:
                  type: array
                  items:
                    type: object
                    properties:
                      queryName:
                        type: string
                      groupByValue:
                        type: string
                      unit:
                        type: string
                    required:
                      - queryName
                      - groupByValue
                      - unit
                totals:
                  type: array
                  items:
                    type: object
                    properties:
                      totalPrevious:
                        type: number
                      totalCurrent:
                        type: number
                      queryName:
                        type: string
                    required:
                      - totalPrevious
                      - totalCurrent
                      - queryName
              required:
                - outputData
                - series
                - totals
          required:
            - kind
            - data
      discriminator:
        propertyName: kind
    InvalidQueryError:
      type: object
      properties:
        error:
          type: string
          enum:
            - INVALID_QUERY
        reason:
          type: string
        details:
          type: array
          items:
            type: object
            properties:
              path:
                type: array
                items:
                  anyOf:
                    - type: string
                    - type: number
              message:
                type: string
              code:
                type: string
            required:
              - path
              - message
              - code
            additionalProperties: false
      required:
        - error
      additionalProperties: false
    Unauthorized:
      type: object
      properties:
        error:
          type: string
          description: Unauthorized error message
      required:
        - error
    HourlyGranularityForbiddenError:
      type: object
      properties:
        error:
          type: string
          enum:
            - HOURLY_GRANULARITY_FORBIDDEN
      required:
        - error
      additionalProperties: false
    ExternalMetricUnauthorizedError:
      type: object
      properties:
        error:
          type: string
          enum:
            - EXTERNAL_METRIC_UNAUTHORIZED
        reason:
          type: string
      required:
        - error
        - reason
      additionalProperties: false
    QueryNotFoundError:
      type: object
      properties:
        error:
          type: string
          enum:
            - NOT_FOUND
        reason:
          type: string
      required:
        - error
      additionalProperties: false
    ExternalMetricIntegrationNotFoundError:
      type: object
      properties:
        error:
          type: string
          enum:
            - EXTERNAL_METRIC_INTEGRATION_NOT_FOUND
      required:
        - error
      additionalProperties: false
    ExternalMetricNotFoundError:
      type: object
      properties:
        error:
          type: string
          enum:
            - EXTERNAL_METRIC_NOT_FOUND
        reason:
          type: string
      required:
        - error
        - reason
      additionalProperties: false
    InternalServerError:
      type: object
      properties:
        error:
          type: string
          enum:
            - INTERNAL_SERVER_ERROR
      required:
        - error
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT or Clerk ak_* API key
      description: >-
        Send `Authorization: Bearer <credential>` using either a Clerk session
        JWT or a Clerk API key (`ak_*`). API keys may identify a user (`user_*`)
        or organization (`org_*`) principal and are generated in the Clerk
        Dashboard under API keys.

````

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