Skip to navigation

Query metrics

Aggregates usage events (the events view) or credit movements (the credits view) over a window: counts, and on credits sums of amount, split by any field of the view and optionally by hour, day, week or month. Returns one result with every row and no cursor; a query that could return more than 50,000 rows (groups × periods) is refused before it runs with invalid_request, param naming what to narrow. Reads the narrowest pre-summed table that holds every grouped and filtered field (eventName aside), and raw events otherwise, with the window capped at 31 days, or 90 with a customer filter on a read by name; a credits query reads the credit ledger’s copy, about a minute behind it, with no window cap; a metadata query folds the raw events sharing a value of the payload key key names into entities, with the window capped at 31 days, or 90 with a customer filter. readFrom says which. A read, sent as a POST because the query is a structured body: it creates nothing and is safe to retry.

Authentication

AuthorizationBearer
API Key authentication using Bearer token

Headers

Paid-BetaenumRequired

This endpoint is in the metrics=v1 beta. Send this header to use it.

Allowed values:

Request

Body
viewstringRequired1-128 characters

The view to read, by the key GET /v1/metrics/views lists: events (usage events), credits (credit spends and grants) or metadata (entities: one customer’s events sharing a value of the payload key key names). More views may be added.

aggregationslist of objectsOptional

The figures each row carries, 1 to 10, each pair once. Defaults to [{ "aggregation": "count" }]. On credits, a sum needs one credit currency: filter creditCurrency with eq, else invalid_request naming aggregations; or group by creditCurrency alone, with groupLimit at least the account’s number of credit currencies, else invalid_request naming groupLimit.

endsAtdatetimeOptional

Exclusive end of the window, on a whole UTC hour and after startsAt. Leave it out to end at the first whole UTC hour after asOf, so the hour in progress is included.

filterslist of objectsOptional

Conditions every counted event or credit movement meets, up to 20, all of which must hold. Any field of the view can be filtered on. On credits, no type filter reads spends and grants both.

granularityenumOptional
The length of each period. Leave it out to treat the whole window as one period. With it, the window holds at most 250 periods.
Allowed values:
groupBylist of stringsOptional

Fields to split the rows by, up to 20, each once. Any field of the view can be grouped by. Defaults to []: one row per period.

groupLimitintegerOptional1-10000Defaults to 100

How many groups to keep, 1 to 10,000 without granularity and 1 to 1,000 with it (over is invalid_request naming groupLimit), ranked by rankBy, else by event (or movement) count, largest first, over the whole window, ties broken by the stored value. The rest fold into one remainder row per period, with remainder: true and every group value null. Defaults to 100. With groupBy, (groupLimit + 1) × periods can be at most 50,000 rows; over it is invalid_request naming groupLimit.

keyobjectOptional

The entity the metadata view folds events into. Required with view: "metadata", and invalid_request naming key with any other view.

rankByobjectOptional

Which of the request’s aggregations ranks the groups, and which way. Groups are ranked by that figure over the whole window (an avg as the window’s sum over its count), ties broken by the stored value, a null figure (an avg, min or max over no numbers) last either way: the first groupLimit are kept, and within a period rows come by that figure, then by group value, the remainder row last. Needs groupBy, and the pair must be one of aggregations; else invalid_request naming rankBy. Leave it out to rank by count, largest first.

startsAtdatetimeOptional

Inclusive start of the window, on a whole UTC hour. Events count by their timestamp, when they happened; credit movements by when billing places them. Leave it out to start at the first hour the view holds data for the account; with endsAt left out too, the window is all time. The result’s window says where it started.

Response

200
objectenum

The type of object. Always metricsResult.

Allowed values:
asOfdatetime
When the figures were computed.
datalist of objects

Every row of the result, by period, then by rankBy’s figure (then group value), else by group value in byte order. The remainder row, the one with remainder: true, is the last of its period. At most 50,000.

granularityenum

The request’s granularity, or null when it had none and each group has one row for the whole window.

Allowed values:
groupsobject

How many groups the window held. Null when the request had no groupBy.

keyobject

On metadata, the request’s key with from resolved. Null on every other view.

readFromenum

rollup when a pre-summed table answered the query; events when it was read from raw events, which caps the window at 31 days (90 with a customer filter on a read by name), as every events query with a countDistinct, or a sum, avg, min, max or count of a payload field, is. The figures are the same either way. ledger on every credits query: the credit ledger’s copy, about a minute behind it. events on every metadata query. More values may be added.

Allowed values:
viewstring
The view the rows were read from.
windowobject

The window the figures cover, as resolved from the request: what a query that left out startsAt or endsAt read.

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
409
Conflict Error
429
Too Many Requests Error
500
Internal Server Error