{"slug":"x402-agent-tools-nerolabs-workers-dev-data-aggregate-8d2fcb","title":"Groups up to 500 JSON rows and works out totals per group","host":"x402-agent-tools.nerolabs.workers.dev","method":"POST","resource":"https://x402-agent-tools.nerolabs.workers.dev/data/aggregate","category":"other","description":"Groups up to 500 JSON rows and works out totals per group: count, sum, average, min, max, median, distinct count, first and last, with date buckets (day, week, month, quarter, year), a pivot table, sorting, top N and a totals row. Returns one row per group plus a summary. $0.001 per row sent, $0.002","price_listed":0.003,"price_asked":0.003,"state":"answering","state_label":"Answering","checks_7d":1,"answered_7d":1,"latency_ms_median":36,"reported_calls_30d":0,"reported_payers_30d":0,"networks":["eip155:8453"],"badge":"unverified","paid_checks_7d":0,"paid_ok_7d":0,"example_input":{"body":{"aggregations":[{"field":"sales","function":"sum"},{"function":"count"}],"groupByFields":["region"],"rows":[{"region":"North","sales":120},{"region":"South","sales":80},{"region":"North","sales":60}]},"bodyType":"json","method":"POST","type":"http"},"output_schema":{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"input":{"additionalProperties":false,"properties":{"body":{"additionalProperties":false,"properties":{"aggregations":{"description":"What to compute per group, for example [{\"function\":\"count\",\"alias\":\"orders\"}, {\"field\":\"amount\",\"function\":\"sum\",\"alias\":\"total_amount\"}]. Every function except count needs a field. alias is the output column name (defaults to function_field, or \"count\"). Omitted gives a plain row count per group. Up to 20.","items":{"properties":{"alias":{"description":"Output column name.","type":"string"},"field":{"description":"The field to aggregate. Optional for count, which then counts rows.","type":"string"},"function":{"enum":["count","countDistinct","sum","avg","min","max","median","first","last","list","listDistinct"],"type":"string"}},"required":["function"],"type":"object"},"type":"array"},"dateBucketField":{"description":"A date or timestamp field to group by time period, for example \"orderedAt\". Adds a group column named like \"orderedAt_month\". Unreadable dates land in an \"(invalid date)\" group.","type":"string"},"dateBucketGranularity":{"description":"Bucket size for dateBucketField: day (2026-08-19), week (2026-W34), month (2026-08, default), quarter (2026-Q3) or year.","enum":["day","week","month","quarter","year"],"type":"string"},"groupByFields":{"description":"One output row per distinct combination of these field values, like SQL GROUP BY, for example [\"region\"] or [\"city\", \"category\"]. Dot paths like \"address.city\" work. Empty or omitted aggregates every row into a single row.","items":{"type":"string"},"type":"array"},"groupMatching":{"description":"normalized (default) ignores letter case and extra whitespace when grouping, so \"South\" and \"south \" are one group. exact requires identical values.","enum":["normalized","exact"],"type":"string"},"includeTotalsRow":{"description":"Appends a grand-total row labelled \"(total)\" and adds a _rowType column (\"group\" or \"total\").","type":"boolean"},"lenientNumbers":{"description":"On by default: \"$1,234.50\", \"49 USD\", \"12%\" and \"(300)\" count as numbers for sum, avg, min, max and median. Set false to accept only real numbers and plain numeric strings.","type":"boolean"},"pivotField":{"description":"Turns this field's distinct values into columns, pivot-table style: group by \"region\" and pivot on \"product\" for one row per region with a column per product. Must not also be a group-by field. At most 50 distinct values.","type":"string"},"pivotFunction":{"description":"How pivot cell values are combined. Defaults to sum when pivotValueField is set; ignored (row count) without one.","enum":["count","countDistinct","sum","avg","min","max","median","first","last","list","listDistinct"],"type":"string"},"pivotValueField":{"description":"The field whose values fill the pivot cells, for example \"amount\". Omitted fills each cell with a row count.","type":"string"},"rows":{"description":"The records to aggregate, up to 500. Each row is a JSON object; keys may differ between rows.","items":{"type":"object"},"type":"array"},"sortBy":{"description":"An output column to sort by: a group field, an aggregation alias such as \"total_amount\", or a pivot column. Omitted sorts by the group fields.","type":"string"},"sortDirection":{"description":"asc (default) or desc. Use desc with topN for \"top N by\" questions.","enum":["asc","desc"],"type":"string"},"topN":{"description":"After sorting, keep only the first N groups. The totals row still covers every input row.","minimum":1,"type":"integer"}},"required":["rows"],"type":"object"},"bodyType":{"enum":["json","form-data","text"],"type":"string"},"method":{"enum":["POST"],"type":"string"},"type":{"const":"http","type":"string"}},"required":["type","method","bodyType","body"],"type":"object"},"output":{"properties":{"example":{"type":"object"},"type":{"type":"string"}},"required":["type"],"type":"object"}},"required":["input"],"type":"object"},"history":[{"day":"2026-10-21","reachable":true,"status":402,"valid_402":true,"asked_usdc":0.003,"price_match":true,"latency_ms":36,"error":null}],"description_full":"Groups up to 500 JSON rows and works out totals per group: count, sum, average, min, max, median, distinct count, first and last, with date buckets (day, week, month, quarter, year), a pivot table, sorting, top N and a totals row. Returns one row per group plus a summary. $0.001 per row sent, $0.002 minimum. Same engine as nerolabs/dataset-aggregate-pivot.","last_updated":"2026-10-21T14:15:18.357Z","schemes":["exact"]}