---
title: "Query Traces"
method: POST
path: "/traces/query"
tags: ["Traces"]
---

# Query Traces

`POST /traces/query`

Query traces as a list of canonical `Trace` records.

Thin wrapper over the shared span-query backend that forces
`focus = "trace"` and returns the list-shaped `Traces` payload
(one entry per trace, each with its nested `spans` tree). Use this
to build a table of runs, where each row is a trace.

## Request body

- `filtering` — span-level conditions, same dialect as
  `POST /spans/query`. A trace matches when any of its spans
  matches.
- `windowing` — cursor pagination and time range.
- `query_ref`, `query_variant_ref`, `query_revision_ref` — resolve
  filters and windowing from a saved query revision. If the
  revision's stored `formatting.focus` is `span`, this endpoint
  returns `409` — call `POST /spans/query` instead.

## Response

Returns `{count, traces: [...]}`. For the per-trace map shape
keyed by `trace_id`, call `POST /tracing/spans/query` with
`focus="trace"`.

## Request body

- TracesQueryRequest — Request body for `POST /traces/query`.
  - `filtering` FilteringInput
    - `operator` 'and' | 'or' | 'not' | 'nand' | 'nor'
    - `conditions` union[]
      - union
        - Condition
          - `field` string, required
          - `key` string, nullable
          - `value` union
            - string
            - integer
            - number
            - boolean
            - unknown[]
              - …
            - object
          - `operator` union
            - 'is' | 'is_not'
            - 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte' | 'btwn'
            - 'startswith' | 'endswith' | 'contains' | 'matches' | 'like'
            - 'in' | 'not_in'
            - 'has' | 'has_not'
            - 'exists' | 'not_exists'
          - `options` union
            - TextOptions
              - …
            - ListOptions
              - …
        - FilteringInput — recursive
  - `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
  - `query_ref` Reference
    - `version` string, nullable
    - `slug` string, nullable
    - `id` string, uuid, nullable
  - `query_variant_ref` Reference
    - `version` string, nullable
    - `slug` string, nullable
    - `id` string, uuid, nullable
  - `query_revision_ref` Reference
    - `version` string, nullable
    - `slug` string, nullable
    - `id` string, uuid, nullable

## Response `200`

Successful Response

- TracesResponse
  - `count` integer — Total number of matching traces in the window.
  - `traces` TraceOutput[], nullable — List of traces in the canonical `Traces` shape. For the map-shaped payload keyed by `trace_id`, call `POST /tracing/spans/query` with `focus="trace"`.
    - `spans` object, nullable
    - `trace_id` string, 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)
