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.
Parameters
Section titled “Parameters”| 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. |
The answer
Section titled “The answer”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 validationwithgroup_by.invalid,range.invalid,range.too_longorenv.invalidinerrors[].
"""API usage per day for the last 7 days: GET /v1/usage (needs the usage_read scope)."""
import datetime as dtimport jsonimport osimport urllib.parseimport 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")// API usage per day for the last 7 days: GET /v1/usage (needs the usage_read scope).
const BASE = process.env.ZEMO_API_BASE ?? "https://api.zemodata.com";const day = (offset) => new Date(Date.now() - offset * 86_400_000).toISOString().slice(0, 10); // UTC
const query = new URLSearchParams({ from: day(6), to: day(0), group_by: "day" });const response = await fetch(`${BASE}/v1/usage?${query}`, { headers: { Authorization: `Bearer ${process.env.ZEMO_API_KEY}` },});if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);const report = await response.json();
const { totals, date_from, date_to } = report.meta;console.log(`${date_from} to ${date_to}: ${totals.requests} requests, ${totals.errors} errors, ${totals.credits} credits`);for (const row of report.data) { // days with no requests are left out console.log(` ${row.day} ${row.requests} requests ${row.credits} credits`);}# API usage per day for the last 7 days: GET /v1/usage (needs the usage_read scope).set -euo pipefailBASE="${ZEMO_API_BASE:-https://api.zemodata.com}"
# Without from/to the report covers the last 30 days (UTC).curl --silent --show-error --fail-with-body -G "$BASE/v1/usage" \ -H "Authorization: Bearer $ZEMO_API_KEY" \ --data-urlencode "from=$(date -u -d '6 days ago' +%F 2>/dev/null || date -u -v-6d +%F)" \ --data-urlencode "to=$(date -u +%F)" \ --data-urlencode "group_by=day"echo