ModelRig Docs Leaderboard Console ↗ Sign up

Query your telemetry: filters, limits, and complete answers

The analytics API answers questions about your own AI calls: what they cost, how many tokens they used, which ones failed, broken down by any tag you send. It returns metadata only (names, numbers, hashes, identifiers), never prompts or outputs.

This page explains how to filter so that your answers are fast and complete.

1. A query in one minute


SELECT tag.step, count(*), sum(cost), sum(tokens_out)
FROM inferences
WHERE ts >= '2026-10-24T00:00:00Z' AND tag.project = 'report_generation'
GROUP BY tag.step

curl -s https://api.modelrig.ai/v1/analytics/query \
  -H "authorization: Bearer $MODELRIG_API_KEY" -H 'content-type: application/json' \
  -d '{"query":"SELECT tag.step, count(*), sum(cost) FROM inferences WHERE ts >= '\''2026-10-24T00:00:00Z'\'' AND tag.project = '\''report_generation'\'' GROUP BY tag.step"}'

The response:


{
  "rows": [ { "step": "weighted_tfv", "count": 40, "sum_cost": 3.93 }, … ],
  "scan_complete": true,        // ← check this first
  "scanned_rows": 4904,
  "scan_stop": "complete",
  "truncated": false,
  "filters": [
    { "column": "ts", "op": ">=", "applied": "database" },
    { "column": "tag.project", "op": "=", "applied": "database", "missing_rows": 0 }
  ],
  "limit": 1000
}

2. Start here: see what your calls carry

You can't filter on a tag you don't know about. Ask first:


curl -s "https://api.modelrig.ai/v1/analytics/tags?since=2026-10-29T00:00:00Z" \
  -H "authorization: Bearer $MODELRIG_API_KEY"

{
  "keys": [
    { "key": "project", "rows": 41250, "distinct_values": 3,
      "top_values": [ { "value": "news_ingest", "rows": 36880 },
                      { "value": "report_generation", "rows": 3970 },
                      { "value": "market_news", "rows": 400 } ],
      "redacted_values": 0 },
    { "key": "step", "rows": 3970, "distinct_values": 14, "top_values": [ … ] }
  ],
  "scanned_rows": 20000, "scan_complete": false, "scan_stop": "row_budget"
}

3. Why filters matter: the scan budget

ModelRig reads your calls newest first and adds them up. Each query may read up to 20,000 calls in up to 10 seconds (the scan budget; see scan_budget in /meta).

Filters are how you stay inside the budget. A filter applied in the database means calls that don't match are never read, so they cost nothing against the budget.

Example: an org sends 55,000 calls in 12 days, 90% of them from a news-ingest job. A 12-day question about the report pipeline, without a project filter, reads 20,000 news calls, stops, and returns scan_complete: false. With tag.project = 'report_generation', it reads only that project's 4,904 calls and returns a complete, exact answer.

4. Database filters and after-read filters

Every condition in WHERE is applied one of two ways. The response's filters list shows which:

appliedWhat happensEffect on the budget
databaseNon-matching calls are never readNarrows the scan. This is what you want for big windows
after_readModelRig reads the calls, then drops non-matching onesStill correct, but the dropped calls count against the 20,000

Both are always correct. A condition that runs in the database is also re-checked after reading, so the answer is identical either way. The only difference is how much of the budget you spend.

Which filters run in the database

You filter onDatabase operators
ts= != > >= < <=
route, provider, model, failure_class, served_variant, served_tier= IN IS NULL IS NOT NULL
any tag (tag.<name>, and subject, feature, user, session, cost_center)= != IN NOT IN IS NULL IS NOT NULL
tokens_in, tokens_out, tokens_cached, latency_ms, ttfb_ms= > >= < <= (number literals), IS NULL, IS NOT NULL
cost> >= < <= (number literals), IS NULL, IS NOT NULL
meta.finish_reason, meta.model_snapshot, meta.context_bucket, meta.error_code, meta.region, meta.input_hash, meta.output_hash= IN IS NULL IS NOT NULL

Everything else runs after reading:

GET /v1/analytics/meta lists the exact operators per column, under filter.database and filter.after_read.

A string value runs in the database only when it is a plain token:

So tag.project = 'report_generation' runs in the database, while tag.batch = '42' runs after reading. The answer is still correct; it just costs budget, because '42' also matches a stored number 42.

5. The filter language


WHERE condition AND condition AND …

condition :=  column = 'text' | column = 123
           |  column != … | > | >= | < | <=
           |  column IN ('a', 'b', …)          -- 1 to 100 values, all text or all numbers
           |  column NOT IN ('a', 'b', …)
           |  column IS NULL
           |  column IS NOT NULL

6. Recipes

One project, last 7 days, by step:


SELECT tag.step, count(*), sum(cost) FROM inferences
WHERE ts >= '2026-10-29T00:00:00Z' AND tag.project = 'report_generation'
GROUP BY tag.step

One run, every call:


SELECT tag.step, model, tokens_in, tokens_out, cost FROM inferences
WHERE tag.run_id = 'run_8f2c' LIMIT 500

Several models at once (in place of OR):


SELECT model, count(*), avg(latency_ms) FROM inferences
WHERE ts >= '2026-11-01T00:00:00Z' AND model IN ('gemini-3.1-pro-preview', 'gpt-5.4')
GROUP BY model

Failures only: failure_class is empty on success.


SELECT route, failure_class, count(*) FROM inferences
WHERE ts >= '2026-11-01T00:00:00Z' AND failure_class IS NOT NULL
GROUP BY route, failure_class

Successes only:


SELECT route, count(*), sum(cost) FROM inferences
WHERE ts >= '2026-11-01T00:00:00Z' AND failure_class IS NULL
GROUP BY route

Everything except one noisy job (untagged calls are included; §7):


SELECT tag.project, sum(cost) FROM inferences
WHERE ts >= '2026-11-01T00:00:00Z' AND tag.project NOT IN ('news_ingest')
GROUP BY tag.project

Calls you forgot to tag:


SELECT route, count(*) FROM inferences
WHERE ts >= '2026-11-01T00:00:00Z' AND tag.project IS NULL
GROUP BY route

Expensive calls (cost > runs in the database):


SELECT route, model, count(*), sum(cost) FROM inferences
WHERE ts >= '2026-11-01T00:00:00Z' AND cost > 0.05
GROUP BY route, model

Heavy reasoning in one project. meta.reasoning_tokens > runs after reading, so pair it with a database filter:


SELECT tag.step, count(*) FROM inferences
WHERE ts >= '2026-11-01T00:00:00Z' AND tag.project = 'report_generation'
  AND meta.reasoning_tokens > 20000
GROUP BY tag.step

7. Missing values

A call may have no value for a column: the tag wasn't sent, or a field is empty. ModelRig handles that the way you'd mean it:

Your conditionCalls with no value…
tag.project = 'x', IN (…)are not included (they aren't x)
tag.project != 'x', NOT IN (…)are included ("everything except x" includes calls that aren't x because they have no tag)
>, >=, <, <=are not included (no value isn't bigger or smaller than anything)
IS NULLonly these
IS NOT NULLnever these

Every filter tells you how many calls had no value. Read missing_rows in the response's filters list. If tag.project != 'news_ingest' reports "missing_rows": 120, the answer includes 120 untagged calls. To leave them out, add AND tag.project IS NOT NULL.

The hosted API and the self-hosted /query behave the same way. A number written as text matches the number (tag.batch = 5 matches a stored "5"), and 'true'/'false' match true/false values.

Changed in modelrig 0.17.0:

8. When an answer is incomplete or empty

Read scan_stop and fix_hint, then:

1. row_budget: more than 20,000 calls matched your database filters. Add a database filter: a tag equality (tag.project = …, tag.run_id = …), a route, or a model IN (…). Or narrow the ts window. Check filters to see whether a condition you thought was narrowing the scan actually ran after_read. 2. time_budget: the read took longer than 10 seconds. Narrow the window the same way. 3. limit_reached: a plain listing (no GROUP BY, no aggregate) already has LIMIT rows, the newest ones. Those rows are correct. Raise LIMIT (up to 10,000) or narrow the filter if you need more.

An empty answer (rows: []) may carry hints:

Fix the filter and re-run. ModelRig does not apply the suggestion for you.

Need a total beyond the budget? Split the window (for example, one query per week). Add the parts only if every part came back scan_complete: true.

9. Make filtering easy: tag at ingest

Filters only find what you tagged. Send these tags on every call through the SDK's tags (the SDK adds run_id itself inside rig.run):

TagUse
projectone value per product area or pipeline. This is your most useful database filter
stepthe pipeline step
run_idone pipeline execution. The SDK stamps it inside rig.run
subject, feature, user, session, cost_centerreserved dimensions with first-class columns

Make tag values plain tokens (report_generation, not Report Generation), so they run in the database and group cleanly. A value with spaces, or one longer than 128 characters, is stored but never shown or matched, because analytics never returns free text.

10. Limits

LimitValue
Calls read per query20,000 (scan_budget.rows)
Time per query10 s (scan_budget.seconds)
Result rows (LIMIT)default 1,000, max 10,000
Values in IN / NOT IN100
Text one condition sends to the database4 KB, encoded; a longer IN / NOT IN is still exact but runs after reading (its filters[].reason says so)
Queries per key60 per minute
Not supportedOR, parentheses, LIKE/prefix match, ORDER BY and count_distinct (planned)