Run a custom query over your request logs
Auth: Authorization: Bearer nsin_… or X-Api-Key: nsin_… — see API keys.
Runs a read-only SQL SELECT against the requests table — your raw
request log — for analyses the dedicated endpoints do not cover.
Scoping is enforced by the database engine, not by your query: a
filter restricting rows to the domains this key can access is appended
to every read of requests. You cannot read another account's traffic,
however the query is written.
Restrictions:
- A single statement only, starting with
SELECTorWITH. - Only the
requeststable may be read. Common table expressions you define yourself are fine; other tables and anydb.tablereference are rejected. - Writes, DDL and settings changes are rejected.
- Execution is capped at 30 seconds and 10 000 returned rows —
truncatedtells you when the cap was hit.
Useful requests columns: event_time, domain_id, hostname,
method, uri, status, bytesIn, bytesOut, duration (ms),
remoteAddr, country, asn, asnOrg, userAgent, cacheStatus,
reqStatus, isWS, protocol, referer, originStatus,
originAddr, error.
Request body
Content type: application/json · required
- sqlstringrequired
The query to run.
Responses
200Query result.
Content type: application/json
- columnsarray of string
Column names, in result order.
- rowsarray of object
One entry per row, keyed by column name.
- row_countinteger
- truncatedboolean
True when the 10 000-row cap was reached and results were cut short.
{
"columns": [
"string"
],
"rows": [
{}
],
"row_count": 0,
"truncated": true
}400The query was rejected by validation, or the database refused it.
detail carries the underlying message when the engine rejected it.
Content type: application/json
- errorstring
- detailstring
{
"error": "querying \"system.parts\" is not allowed; only the 'requests' table may be read"
}401Missing, malformed, revoked or expired API key. (A valid key whose
account has been deactivated gets 403 account is inactive instead.)
Content type: application/json
- errorstringrequired
Human-readable description of what went wrong.
{
"error": "invalid API key"
}403The account has no domains whose logs could be queried. (Read-only
keys may call this endpoint: it is the one POST they are
allowed, because it writes nothing.)
Content type: application/json
- errorstringrequired
Human-readable description of what went wrong.
{
"error": "you have no domains to query"
}429The key exceeded its request budget (300 requests per minute by default).
Content type: application/json
- errorstringrequired
Human-readable description of what went wrong.
{
"error": "rate limit exceeded"
}503Either the analytics backend is temporarily unreachable (retry; no data
is lost), or the answer is still being computed. The per-domain
sections and the cached account-wide views (domains-overview,
global-summary, global-summary/peak, requests-compare,
bandwidth-overview, nodes-overview) wait at most about 25 seconds
for their query; past that they answer 503 with pending: true and
a Retry-After header, while the query keeps running and caches its
result, so the retry is served from that cache instead of starting the
same scan again. Identical concurrent requests share one computation.
Content type: application/json
- errorstringrequired
Human-readable description of what went wrong.
- pendingboolean
truewhen the query is still running rather than failing. Retry afterRetry-Afterseconds.
{
"error": "analytics unavailable"
}Example request
curl -X POST "https://api.nsin.ir/analytics/query" \
-H "Authorization: Bearer $NSIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"sql": "SELECT toStartOfHour(event_time) AS h, count() AS c FROM requests WHERE status >= 500 GROUP BY h ORDER BY h"
}'