Skip to main content

Overview

The Aggregate Events endpoint provides powerful analytics capabilities for usage events. It returns time-series data showing how usage evolves over time, with support for multiple features and custom grouping.

Use Cases

  • Usage analytics: Visualize usage trends over time
  • Billing calculations: Calculate usage-based charges for specific periods
  • Capacity planning: Identify usage patterns and predict future needs
  • Feature adoption: Track how different features are being used
  • Segmentation analysis: Break down usage by custom properties (e.g., API model, region)

Key Concepts

Time Periods (Bins)

Events are aggregated into time periods called “bins”. Each bin represents a specific time window:
  • hour: Hourly aggregation
  • day: Daily aggregation (default)
  • month: Monthly aggregation

Range Options

Predefined time ranges make it easy to query common periods:
  • 24h: Last 24 hours
  • 7d: Last 7 days
  • 30d: Last 30 days
  • 90d: Last 90 days
  • last_cycle: Previous billing cycle
  • 1bc: Current billing cycle (default)
  • 3bc: Last 3 billing cycles
Alternatively, use custom_range with start and end timestamps (epoch milliseconds).

Basic Aggregation

Single Feature, Daily Bins

Response:

Multiple Features

Aggregate multiple features in a single request:
Response:

Advanced: Grouped Aggregation

Group events by custom properties to analyze usage across different dimensions.

Group by Property

Use the group_by parameter to break down usage by event properties:
Response:

Multiple Features with Grouping

Response:

Bin Size Selection

Choose the appropriate bin size based on your time range:
If not specified, bin_size defaults to hour for 24h range and day for all other ranges.

Custom Time Ranges

For precise control over the aggregation period, use custom_range:
custom_range and range are mutually exclusive. Use one or the other, not both.

JavaScript Example

Response Structure

List Items

Each item in the list array represents one time period:
  • period: Unix timestamp (epoch milliseconds) marking the start of this time bin
  • values: Object with feature IDs as keys and aggregated totals as values
  • grouped_values: (Optional) Nested object breaking down values by group when group_by is used

Total Object

The total object provides overall statistics per feature:
  • count: Number of time periods with data for this feature
  • sum: Total sum of all values across all periods

Example Queries

Hourly Usage for Last 24 Hours

Current Billing Cycle Usage

Usage by Model Type

Monthly Aggregation for Quarterly Report

Multi-Dimensional Analysis

Visualization Example

Best Practices

Choose Appropriate Bin Size

Match bin size to your analysis needs: hourly for real-time, daily for trends, monthly for long-term patterns.

Use Grouping Strategically

Group by meaningful properties (model, region, plan) to gain actionable insights, but avoid over-segmentation.

Monitor Total Metrics

Use the total object for quick summary statistics before diving into time-series data.

Cache Aggregated Data

For frequently accessed reports, cache aggregation results to reduce API calls and improve performance.

Common Use Cases

Usage-Based Billing

Use the total.sum value to calculate charges for the current billing cycle.

Feature Adoption Tracking

Compare values across features to identify which are growing or declining.

Cost Attribution

Break down costs by team, project, or department using grouped aggregation.