Home / Docs / Count

Count every matching document, exactly

"How many contracts mention indemnity?" gets a number. Count reads every candidate, so the answer is exact, with a sample of ids.

The call

GET /api/collections/{name}/count takes the same q, regex and filter as search.

Shell
curl -G https://stackgrep.com/api/collections/contracts/count \
  -H "Authorization: Bearer $STACKGREP_KEY" \
  --data-urlencode 'q=indemnif' -d filter=signed:true
Response
{"collection": "contracts", "took_ms": 41.8, "docs": 3127,
 "sample": ["acme/msa-2024.txt", "initech/sow-7.txt", "..."]}
NameTypeWhat it does
docsintegerDocuments that match: every one, counted once, newest versions only.
sample[string]Up to 20 of their ids.
took_msnumberTime spent counting, in milliseconds.

Why it's exact

Search engines built for people return the top ten and guess the rest. An agent asked "how many" needs the real number, so count checks every document that could match, not a sample. A count costs 5 credits.

Try it on your own documentsExact and regex search for your agents, from one API. Or see the engine on npm's source first.