Usage & Analytics
Query usage events, aggregations, and materialized analytics views.
Usage Events
| Operation | GraphQL |
|---|---|
| List events (paginated) | usage_events(where: {application_id: {_eq: $appId}, created_at: {_gte: $start, _lte: $end}}, limit: $limit, offset: $offset, order_by: {created_at: desc}) |
| Aggregate by model | usage_events_aggregate(where: {application_id: {_eq: $appId}}) { aggregate { count, sum { cost_pusd, tokens_in, tokens_out }, avg { cost_pusd, latency_ms } } } |
| Aggregate by provider | usage_events_aggregate(where: {application_id: {_eq: $appId}, created_at: {_gte: $start, _lte: $end}}) |
| Aggregate by status | usage_events_aggregate(where: {application_id: {_eq: $appId}, created_at: {_gte: $start, _lte: $end}}) |
Materialized Views
| Operation | GraphQL |
|---|---|
| Daily summary | daily_usage_summary(where: {application_id: {_eq: $appId}}, order_by: {day: desc}) |
| Model performance | model_performance_summary(where: {application_id: {_eq: $appId}}, order_by: {time_bucket: desc}) |
| Cost analysis | cost_analysis_by_app(where: {application_id: {_eq: $appId}}, order_by: {date: desc}, limit: $days) |
| Error analysis | error_analysis(where: {application_id: {_eq: $appId}}, order_by: {time_bucket: desc}, limit: $hours) |
| Token usage trends | token_usage_trends(where: {application_id: {_eq: $appId}}, order_by: {date: desc}, limit: $days) |
| Endpoint summary (30d) | usage_endpoint_summary_30d(where: {application_id: {_eq: $appId}}, order_by: {total_cost_pusd: desc_nulls_last}) |
| Pricing history | pricing_rates_history_by_pk(pricing_history_id: $id) |
Revenue
| Operation | GraphQL |
|---|---|
| Revenue aggregation | billing_ledger_aggregate(where: {type: {_eq: "subscription_fee"}, metadata: {_contains: {application_id: $appId}}, created_at: {_gte: $start}}) |
| Revenue by plan | billing_ledger(where: {type: {_eq: "subscription_fee"}, metadata: {_contains: {application_id: $appId}}}) |
Last updated on