---
title: "Fetch Analytics"
method: POST
path: "/tracing/analytics/query"
tags: ["Deprecated"]
deprecated: true
---

# Fetch Analytics

`POST /tracing/analytics/query`

> **Deprecated.**

Aggregate span metrics into time buckets.

Runs filtering and windowing identical to `POST /tracing/spans/query`,
then bucketizes the matched spans by time and computes one or more
metric summaries per bucket. Use this to build charts of latency,
cost, token usage, or custom numeric and categorical attributes.

## Request body

- `filtering` — same shape as the query endpoint, scoped to the spans
  that contribute to the analytics.
- `windowing` — `oldest`/`newest` for the time range and `interval`
  for bucket width (in seconds).
- `specs` — a list of `MetricSpec` entries describing which
  attributes to summarize and how. Each spec declares a `type`
  (`numeric/continuous`, `numeric/discrete`, `binary`,
  `categorical/single`, `categorical/multiple`, `string`, `json`,
  or `*` for auto) and a dotted `path` into the span (for example
  `attributes.ag.metrics.costs.cumulative.total`).

## Response

Buckets are returned in chronological order. Each bucket carries a
`metrics` dict keyed by spec path. See [Tracing — the ag.*
namespace](/reference/api-guide/tracing#the-ag-attribute-namespace)
for the cumulative/incremental metric layout on each span.

## Query parameters

- `focus` 'trace' | 'span'
- `format` 'agenta' | 'opentelemetry'
- `oldest` union
  - string
  - integer
- `newest` union
  - string
  - integer
- `interval` integer, nullable
- `rate` number, nullable
- `filter` unknown
- `specs` unknown

## Response `200`

Successful Response

- AnalyticsResponse — Analytics response with user-specified metric specs.
  - `count` integer — Number of time buckets returned.
  - `buckets` MetricsBucket[] — Time-bucketed aggregates. Each bucket's `metrics` dict is keyed by the dotted `path` of the corresponding `MetricSpec`, ordered oldest to newest.
    - `timestamp` string, date-time, required
    - `interval` integer, required
    - `metrics` object, nullable
  - `query` TracingQuery
    - `formatting` Formatting
      - `focus` 'trace' | 'span'
      - `format` 'agenta' | 'opentelemetry'
    - `windowing` Windowing
      - `newest` string, date-time, nullable
      - `oldest` string, date-time, nullable
      - `next` string, uuid, nullable
      - `limit` integer, nullable
      - `order` 'ascending' | 'descending', nullable
      - `interval` integer, nullable
      - `rate` number, nullable
    - `filtering` FilteringOutput
      - `operator` 'and' | 'or' | 'not' | 'nand' | 'nor'
      - `conditions` union[]
        - union
          - Condition
            - `field` string, required
            - `key` string, nullable
            - `value` union
              - …
            - `operator` union
              - …
            - `options` union
              - …
          - FilteringOutput — recursive
  - `specs` MetricSpec[] — The resolved metric specs applied in each bucket.
    - `type` 'numeric/continuous' | 'numeric/discrete' | 'binary' | 'categorical/single' | 'categorical/multiple' | 'string' | 'json' | 'none' | '*'
    - `path` string
    - `bins` integer, nullable
    - `vmin` number, nullable
    - `vmax` number, nullable
    - `edge` boolean, nullable

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/agenta-ai/apis/agenta-api.md) · [All operations](https://skmtc.net/agenta-ai/apis/agenta-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/agenta-ai/agenta-api/versions/ea6421d829f1/schema)
