Skip to content

Usage

GET /v1/usage (scope usage_read) reports what your organization’s keys did. The portal’s Usage page shows the same numbers as charts.

Parameter Meaning
from, to UTC days (YYYY-MM-DD), both included. Default: the last 30 days. At most 400 days.
group_by Any of day, key, route, product, comma separated. Default day.
key_id Only one key.
route Only one endpoint, for example POST /v1/unlock.
product Only one data product (its slug). Empty for requests that named none.
env live or test.
limit Rows to return: 1,000 by default, at most 10,000.

data has one row per group, with the grouping columns you asked for plus requests, errors (status 400 or more), credits, records (returned with full values) and p95_ms (the slowest daily 95th-percentile latency in the row). Days with no requests are left out.

meta has date_from, date_to, group_by, totals (the same counters over all rows) and truncated (true when there were more rows than limit).

Send Accept: text/csv for the same rows as CSV.

  • Numbers are rebuilt every 15 minutes, so the last few minutes may not show yet.
  • Test-key requests count as requests with env=test, never as credits.
  • A replayed spending call (same Idempotency-Key) counts 0 credits: the first call already did.
  • Bad parameters answer 422 validation with group_by.invalid, range.invalid, range.too_long or env.invalid in errors[].
python/usage.py
"""API usage per day for the last 7 days: GET /v1/usage (needs the usage_read scope)."""
import datetime as dt
import json
import os
import urllib.parse
import urllib.request
BASE = os.environ.get("ZEMO_API_BASE", "https://api.zemodata.com")
today = dt.datetime.now(dt.UTC).date()
query = urllib.parse.urlencode(
{"from": (today - dt.timedelta(days=6)).isoformat(), "to": today.isoformat(), "group_by": "day"}
)
request = urllib.request.Request(
f"{BASE}/v1/usage?{query}",
headers={"Authorization": f"Bearer {os.environ['ZEMO_API_KEY']}"},
)
with urllib.request.urlopen(request, timeout=30) as response:
report = json.load(response)
totals = report["meta"]["totals"]
print(
f"{report['meta']['date_from']} to {report['meta']['date_to']}: {totals['requests']} requests, "
f"{totals['errors']} errors, {totals['credits']} credits"
)
for row in report["data"]: # days with no requests are left out
print(f" {row['day']} {row['requests']:>6} requests {row['credits']:>6} credits")