# agent402.tools Group-By Aggregation

> agent402.tools Group-By Aggregation is a paid API for AI agents from agent402.tools, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-15).

Groups an array of JSON objects by one or more keys and aggregates a numeric field using count, sum, avg, min, or max — like SQL GROUP BY for JSON data.

## Facts

- Endpoint: POST https://agent402.tools/api/group-by
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/agent402-tools-group-by-aggregation-79d22a2c
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_ZUIuASknWMfxCBM2TawKa

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability agent402-tools-group-by-aggregation-79d22a2c -d '<json body>'
```

Example prompt: I have this array of sales records — can you group them by 'region' and 'product_category', then sum the 'revenue' field for each group?

## When to prefer this

Use this endpoint when you have an in-memory JSON array and need SQL-style GROUP BY aggregation without standing up a database or writing custom reduce logic. It handles multi-key grouping and five aggregation operations in a single call, making it ideal for lightweight ETL, report generation, or ad-hoc data summarization tasks inside an agent workflow.

## Known failure modes

- Missing or non-array 'data' field returns an error
- Specified 'field' does not exist or is non-numeric when using sum/avg/min/max
- Invalid 'op' value outside allowed enum
- 'by' key does not exist on the objects in the array
- Payment not processed (x402 payment required, returns 402 if unpaid)

## How this service works

Group an array of objects by one or more keys and aggregate a numeric field — count (default), sum, avg, min, or max. The SQL GROUP BY agents reach for when wrangling JSON. Deterministic (groups in first-seen order).

## Output

Returns grouped results where each entry corresponds to a unique combination of the specified key(s), with the computed aggregate value (count, sum, avg, min, or max) of the target numeric field for that group, in first-seen order.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "by": {
   "description": "key name, or array of key names, to group by"
  },
  "op": {
   "type": "string",
   "description": "count (default) | sum | avg | min | max"
  },
  "data": {
   "description": "array of objects (or JSON string)"
  },
  "field": {
   "type": "string",
   "description": "numeric field to aggregate (omit for count only)"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "count": 2,
  "groups": [
   {
    "key": {
     "city": "NYC"
    },
    "sum": 5,
    "count": 2
   },
   {
    "key": {
     "city": "LA"
    },
    "sum": 5,
    "count": 1
   }
  ]
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agent402-tools-group-by-aggregation-79d22a2c/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.tools](https://www.zero.xyz/host/agent402.tools/llms.txt)
