---
title: "Several workspace metrics in one request"
method: POST
path: "/v1/aggregate"
tags: ["Aggregate"]
---

# Several workspace metrics in one request

`POST /v1/aggregate`

## Request

- Base URL: `https://api.talonic.com`
- URL: `https://api.talonic.com/v1/aggregate`
- Auth: HTTP bearer

Ask several questions about your workspace in one request and get
numbers back, never rows. For example: how many documents arrived in
the last 12 hours, how many failed, and what a document cost on
average.

**The window.** `from` and `to` are ISO-8601 timestamps with an offset
(`2026-11-05T12:00:00Z`). The window includes `from` and excludes
`to`, and is at most 31 days long.

**The queries.** Up to 20, each with an `id` of your choice (the
answer is keyed by it), a `dataset` and a `measure`:
- `count`: what the dataset counts (its description says whether
  that is rows or documents); `rows`: the number of rows.
- `count_distinct`, `sum`, `avg`, `min`, `max`, `median`, `p1`–`p99`:
  over the field named in `of` (a number field, except for
  `count_distinct`).
- A list of measures (`["avg", "median"]`) answers `values` plus `n`,
  the number of rows they were computed over.

`where` filters rows (`{ "field": "failed", "op": "eq", "value": true }`);
which operators a field takes depends on its type. `group_by` splits
the answer by up to three fields, or by `hour` / `day` (UTC); it
returns at most 200 groups (largest first, or in time order when
grouped by `hour` / `day`), and `groups_total` says how many there
were. `sum`, `avg` and the other computed measures are `null` when
there were no rows; counts are 0.

**Which datasets and fields exist:** `GET /v1/aggregate/catalog`
lists every dataset with what one row is, its fields (type, whether
it can be grouped, which operators it takes) and its default
filters. Most datasets count things *created* in the window and
report their status *now* (a document received yesterday that
failed today counts as failed). Accounts Payable bills and the Money
Found ledger are not datasets; read them from `/v1/ap/overview` and
`/v1/money-found/levers`.

**Narrowing to documents.** `scope` restricts every query to some
documents: `document_ids`, `tags` (`any` / `all`), `system_tags`,
`source_connection_ids`, `document_types` (ids or names),
`client_batch_ids`, `roots_only`, `attachments_only`. A dataset
that is not about documents refuses a scope (400). Rows tied to a
document the key's owner may not see are left out; rows tied to no
document (a model call outside any document, a check of a document
set) still count unless a scope is set.

**Limits.** One request runs at a time per workspace (per API process
where the deployment does not share the limiter; the catalog's
`limits.concurrency.per` says which). A second one gets 429 with
`Retry-After: 5`: retry after that many seconds. The daily rate limit
also answers 429; it sends `X-RateLimit-Reset` instead. Each
statement may run `limits.statement_timeout_ms`; a request runs one
statement per dataset (plus one per grouped query), so a whole
request can take longer. A statement that runs too long stops the
request with 422 `aggregate_timeout`, naming the dataset; ask for a
shorter window or fewer groups. Cost
fields and the `model` dimension answer 403 `cost_not_visible` when
cost visibility is off for your organization. A wrong name answers
400 `invalid_aggregate` listing the names allowed there.

## Request body

- object
  - `from` string, date-time, required
  - `to` string, date-time, required: Exclusive.
  - `scope` object
    - `document_ids` string[]
    - `tags` object
      - `any` string[]
      - `all` string[]
    - `system_tags` object
      - `any` string[]
      - `all` string[]
    - `source_connection_ids` string[]
    - `document_types` string[]: Document type ids or exact names.
    - `client_batch_ids` string[]
    - `roots_only` boolean
    - `attachments_only` boolean
  - `queries` object[], required
    - `id` string, required
    - `dataset` 'documents' | 'document_cost' | 'pipeline_documents' | 'app_verdicts' | 'app_runs' | 'deliveries' | 'llm_calls' | 'compliance_evaluations' | 'money_found_reviews' | 'contract_check_decisions' | 'doc_gen_jobs' | 'doc_gen_documents' | 'price_invoice_checks', required
    - `measure` union, required
      - string
      - string[]
    - `of` string
    - `where` object[]
      - `field` string, required
      - `op` 'eq' | 'neq' | 'in' | 'not_in' | 'is_null' | 'not_null' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains_any' | 'contains_all', required
      - `value` unknown
    - `group_by` string[]

## Response `200`

One result per query id.

- object
  - `window` object
    - `from` string, date-time
    - `to` string, date-time
  - `as_of` string, date-time
  - `results` object

## Other responses

- `400`: The request is invalid.
- `401`: Missing or invalid API key.
- `403`: The API key does not have the required scope.
- `422`: A statement ran past the timeout (`aggregate_timeout`); `details.dataset` names it.
- `429`: Daily rate limit exceeded.

## Changes

- **2026-11-06** `eb01b697e3e3`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/talonic/apis/talonic-api/changes/v1/aggregate/post.md)

---

[API](https://skmtc.dev/talonic/apis/talonic-api.md) - [All operations](https://skmtc.dev/talonic/apis/talonic-api/llms.txt) - [OpenAPI document](https://skmtc.dev/talonic/apis/talonic-api/revisions/9f6d53e2ab5e?raw)
