Usage Tracking API

Get usage aggregation

Returns aggregated usage quantities by metric (total quantity, event count, first and last event timestamps) for volume reporting. Call it with a GET request to /usage/aggregation, authenticated with a restricted API key and the "usage:read" scope.

GET https://api.bearlumen.com/v1/usage/aggregation

Returns aggregated usage quantities by metric (total quantity, event count, first and last event timestamps) for volume reporting. This endpoint returns no cost figures; for dollar amounts use GET /cost-data/summary or the other cost-data endpoints. Data sent via POST /usage-events aggregates under metricName `tokens`. Requests count toward your per-API-key rate limit; sustained overruns return 429 with the standard error envelope.

Authentication and scopes

Authenticate with a restricted API key in the Authorization: Bearer <key> header. This endpoint requires the usage:read scope.

Parameters

NameInTypeRequiredDescription
start_datequerystringYesStart of the aggregation range. ISO 8601 date or datetime (e.g. 2026-01-01 or 2026-01-01T00:00:00Z). Include an explicit UTC offset; date-only values are interpreted as UTC midnight. Must be strictly before end_date; the range may not exceed 365 days.
end_datequerystringYesEnd of the aggregation range. ISO 8601 date or datetime. Maximum range: 365 days.
subscription_idquerystringNoOptional: Filter by subscription ID.
metric_namesquerystringNoOptional: Comma-separated list of metric names to include (max 50). Metric names are stored lowercase and matched exactly; pass lowercase values (e.g. tokens).

Response example

Success response (200):

JSON
{
  "aggregations": [
    {
      "event_count": 8,
      "first_event_at": "2026-01-05T09:14:00.000Z",
      "last_event_at": "2026-01-27T19:12:00.000Z",
      "metric_name": "tokens",
      "total_quantity": 31226000
    }
  ],
  "period_end": "2026-01-31T23:59:59.000Z",
  "period_start": "2026-01-01T00:00:00.000Z",
  "total_events": 8
}

Error codes

Errors return the standard error envelope with a code, message, and a correlationId you can quote to support.

StatusWhen it happens
400Invalid request parameters. Check that start_date and end_date are valid ISO 8601 dates, start_date is strictly before end_date, the range does not exceed 365 days, and metric_names lists at most 50 names.
401Missing or invalid API key. Send your key as Authorization: Bearer YOUR_API_KEY.
403Forbidden. The API key is missing the usage:read scope; create or update a key with that scope.
404Subscription not found or not accessible with this API key. Check the subscription_id value.
429Rate limit or plan quota exceeded. Slow down and retry after the current window resets.

Rate limits and retries

Rate limit or plan quota exceeded. Slow down and retry after the current window resets.