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:trueResponse
{"collection": "contracts", "took_ms": 41.8, "docs": 3127,
"sample": ["acme/msa-2024.txt", "initech/sow-7.txt", "..."]}| Name | Type | What it does |
|---|---|---|
docs | integer | Documents that match: every one, counted once, newest versions only. |
sample | [string] | Up to 20 of their ids. |
took_ms | number | Time 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.