CSV aggregate
POST /api/csv-aggregateSummarize 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.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
csv | string | yes | CSV text with a header row (at most 100,000 characters) |
groupBy | string | no | Column to group rows by (optional) |
columns | array of string | no | Columns to summarize (default every column but groupBy); a comma-separated string also works |
delimiter | string | no | comma (default), semicolon, tab, pipe, or any single character other than a quote or a line break |
limit | number | no | Groups 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
POST /api/csv-aggregate$0.002 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example 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
}
}
}
]
}| Field | Type | Always present | In the example |
|---|---|---|---|
rows | number | yes | 5 |
delimiter | string | yes | , |
columns | object | yes | 2 fields: product, units |
groupBy | string | yes | region |
returned | number | yes | 2 |
matched | number | yes | 2 |
complete | boolean | yes | true |
truncated | boolean | yes | false |
groups | array of objects | yes | 1 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
csvis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement runs after the tool and only on a successful response. Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Free tier: no outbound network call leaves the server for this tool, so proof-of-work (16 leading zero bits of sha256) pays for it.
- A
GETorHEADto /api/csv-aggregate returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
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
Compute the full descriptive-stats panel for an array of numbers in one call: count, sum, mean, median, mode, stddev.
JSON lint
Check JSON text and point at the first syntax error: its line, column, character position (offset), the path.
A2A Agent Card validate
Validate an A2A (Agent2Agent protocol) Agent Card: required fields, skill shape, transport names, capability flags.
Amortization schedule
Build the full per-period amortization schedule for a fully-amortizing loan.
Annuity present/future value
Present and future value of a level annuity (equal periodic payments).
AQI calculator (US EPA)
US EPA Air Quality Index from the pollutant concentrations you supply: PM2.5 and PM10 (µg/m³, 24-hour), ozone (ppb.