Skip to content

CSV aggregate

FREE with proof-of-workor $0.002 in USDCPOST /api/csv-aggregate

Summarize CSV columns: count, empty cells, distinct values, and for numbers sum, mean, min and max, over the whole table or per group with groupBy (a column name). Send POST /api/csv-aggregate with the required field csv and pay $0.002 per call over x402 or MPP, or call it free by solving a proof-of-work challenge. It returns a JSON object with rows, delimiter, columns, groupBy, returned and 4 more.

The first row is the header. columns picks the columns to summarize (default all). Comma by default, or delimiter: semicolon, tab, pipe or any single character other than a quote or a line break. CSV up to 100,000 characters (in a request body of at most 100 KB; JSON escaping counts, so a newline takes two bytes) and 200 columns; up to 1,000 groups listed, largest first. A call reads up to 200,000 row-by-column cells and builds up to 50,000 group-by-column summaries; past either it answers 413.

Category: Live public dataTags: csv aggregate group-by sum count mean average minAlso found as: csv-sum csv-group-by csv-distinct csv-stats csv-column-stats csv-average

Try in playground →

Parameters

NameTypeRequiredDescription
csvstringyesCSV text with a header row (at most 100,000 characters)
groupBystringnoColumn to group rows by (optional)
columnsarray of stringnoColumns to summarize (default every column but groupBy); a comma-separated string also works
delimiterstringnocomma (default), semicolon, tab, pipe, or any single character other than a quote or a line break
limitnumbernoGroups to list, 1-1000 (default 100), largest first

Example request

curl -i -X POST https://agent402.tools/api/csv-aggregate \
  -H "Content-Type: application/json" \
  -d '{"csv":"region,product,units,price\nwest,widget,12,2.50\neast,widget,7,2.50\nwest,gadget,3,9.99\neast,gadget,5,9.99\nwest,widget,8,2.75\n","groupBy":"region"}'

Without payment this returns HTTP 402 Payment Required with the exact price for csv-aggregate; any x402 v2 or MPP client pays it and retries.

Watch a call get paid

RequestPOST /api/csv-aggregate
402$0.002 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example response

{
  "rows": 5,
  "delimiter": ",",
  "columns": {
    "product": {
      "count": 5,
      "empty": 0,
      "distinct": 2,
      "numeric": 0
    },
    "units": {
      "count": 5,
      "empty": 0,
      "distinct": 5,
      "numeric": 5,
      "sum": 35,
      "mean": 7,
      "min": 3,
      "max": 12
    }
  },
  "groupBy": "region",
  "returned": 2,
  "matched": 2,
  "complete": true,
  "truncated": false,
  "groups": [
    {
      "key": "west",
      "rows": 3,
      "columns": {
        "units": {
          "count": 3,
          "empty": 0,
          "distinct": 3,
          "numeric": 3,
          "sum": 23,
          "mean": 7.66666666666667,
          "min": 3,
          "max": 12
        }
      }
    }
  ]
}
FieldTypeAlways presentIn the example
rowsnumberyes5
delimiterstringyes,
columnsobjectyes2 fields: product, units
groupBystringyesregion
returnednumberyes2
matchednumberyes2
completebooleanyestrue
truncatedbooleanyesfalse
groupsarray of objectsyes1 item in the example

From an MCP client

catalog.call {
  "slug": "csv-aggregate",
  "params": {
    "csv": "region,product,units,price\nwest,widget,12,2.50\neast,widget,7,2.50\nwest,gadget,3,9.99\neast,gadget,5,9.99\nwest,widget,8,2.75\n",
    "groupBy": "region"
  }
}

On the hosted connector at https://agent402.tools/mcp, catalog.call runs csv-aggregate free (rate-limited, no wallet). Local install: npx -y agent402-mcp@0.15.0.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.002" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/csv-aggregate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "csv": "region,product,units,price\nwest,widget,12,2.50\neast,widget,7,2.50\nwest,gadget,3,9.99\neast,gadget,5,9.99\nwest,widget,8,2.75\n",
    "groupBy": "region"
  }),
});

No wallet? Pay with compute

Fetch a challenge, solve the sha256 puzzle (16 leading zero bits, a fraction of a second of CPU), and resend with the X-Pow-Solution header:

import { createHash } from "node:crypto";
const lz = (b) => { let t = 0; for (const x of b) { if (!x) { t += 8; continue; } t += Math.clz32(x) - 24; break; } return t; };
const c = await (await fetch("https://agent402.tools/api/pow/challenge?slug=csv-aggregate")).json();
let n = 0;
while (lz(createHash("sha256").update(c.challenge + ":" + n).digest()) < c.difficulty) n++;
await fetch("https://agent402.tools/api/csv-aggregate", { method: "POST", headers: { "X-Pow-Solution": c.token + ":" + n, "Content-Type": "application/json" }, body: JSON.stringify({"csv":"region,product,units,price\nwest,widget,12,2.50\neast,widget,7,2.50\nwest,gadget,3,9.99\neast,gadget,5,9.99\nwest,widget,8,2.75\n","groupBy":"region"}) });

Related tools

Stats summary

FREE w/ computeor $0.001POST /api/stats-summary

Compute the full descriptive-stats panel for an array of numbers in one call: count, sum, mean, median, mode, stddev.

JSON lint

FREE w/ computeor $0.001POST /api/json-lint

Check JSON text and point at the first syntax error: its line, column, character position (offset), the path.

A2A Agent Card validate

FREE w/ computeor $0.002POST /api/a2a-card-validate

Validate an A2A (Agent2Agent protocol) Agent Card: required fields, skill shape, transport names, capability flags.

Amortization schedule

FREE w/ computeor $0.001POST /api/amortization

Build the full per-period amortization schedule for a fully-amortizing loan.

Annuity present/future value

FREE w/ computeor $0.001POST /api/annuity

Present and future value of a level annuity (equal periodic payments).

AQI calculator (US EPA)

FREE w/ computeor $0.001GET /api/aqi-calc

US EPA Air Quality Index from the pollutant concentrations you supply: PM2.5 and PM10 (µg/m³, 24-hour), ozone (ppb.