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 hours7d: Last 7 days30d: Last 30 days90d: Last 90 dayslast_cycle: Previous billing cycle1bc: Current billing cycle (default)3bc: Last 3 billing cycles
custom_range with start and end timestamps (epoch milliseconds).
Basic Aggregation
Single Feature, Daily Bins
Multiple Features
Aggregate multiple features in a single request:Advanced: Grouped Aggregation
Group events by custom properties to analyze usage across different dimensions.Group by Property
Use thegroup_by parameter to break down usage by event properties:
Multiple Features with Grouping
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, usecustom_range:
JavaScript Example
Response Structure
List Items
Each item in thelist 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_byis used
Total Object
Thetotal 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
total.sum value to calculate charges for the current billing cycle.