Get Query Analytics
Sprint 3
Get comprehensive query analytics for the dashboard including KPIs, time series, and performance metrics.
Endpoint
GET /api/v1/prompts/analytics/query-analytics
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <access_token> |
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period | string | No | Time period: last_7_days, last_30_days, or custom (default: last_7_days) |
start_date | string | No | Start date (ISO 8601) - required if period=custom |
end_date | string | No | End date (ISO 8601) - required if period=custom |
metric_type | string | No | Metric type: execution_time, query_count, or success_rate (default: execution_time) |
Response
Success (200)
{
"success": true,
"data": {
"kpis": {
"total_queries": 150,
"total_queries_trend": 0.15,
"avg_execution_time_seconds": 2.5,
"avg_execution_time_trend": -0.1,
"success_rate": 0.95,
"successful_queries": 142,
"total_queries_count": 150,
"data_sources_used": 5,
"data_source_types": ["postgresql", "mysql", "snowflake"]
},
"time_series": [
{
"date": "2024-12-01",
"value": 20
},
{
"date": "2024-12-02",
"value": 25
}
],
"most_used_queries": [
{
"query_preview": "SELECT region, SUM(sales) FROM sales_data...",
"executions": 15,
"avg_time_seconds": 1.5,
"last_run": "2024-12-01T10:00:00Z"
}
],
"status_distribution": {
"success": 0.95,
"failed": 0.04,
"running": 0.01
},
"peak_usage_times": [0, 0, 0, 0, 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 30, 25, 20, 15, 10, 5, 0, 0, 0, 0],
"data_source_performance": [
{
"data_source_id": 1,
"data_source_name": "Production PostgreSQL",
"queries": 50,
"avg_latency_ms": 1500,
"status": "healthy"
}
],
"period": {
"start_date": "2024-12-01T00:00:00Z",
"end_date": "2024-12-07T23:59:59Z",
"period": "last_7_days"
}
},
"message": "Query analytics retrieved successfully"
}
Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | BAD_REQUEST | Invalid date format or missing dates when period=custom |
| 401 | UNAUTHORIZED | Invalid or missing authentication token |
| 500 | INTERNAL_SERVER_ERROR | Internal server error |
Features
- Key Performance Indicators (KPIs)
- Time series data
- Most used queries
- Status distribution
- Peak usage times (24-hour breakdown)
- Data source performance metrics
- Custom date range support
- Organization-scoped
Date Format
Dates must be in ISO 8601 format:
2024-12-01T00:00:00Z2024-12-01T00:00:00+00:00
Peak Usage Times
The peak_usage_times array contains 24 values, one for each hour of the day (0-23), representing query count for that hour.
Example
curl -X GET "https://api.rivergen.com/api/v1/prompts/analytics/query-analytics?period=last_30_days&metric_type=execution_time" \
-H "Authorization: Bearer <access_token>"
Related Endpoints
- Get Prompt Analytics - Get analytics for specific prompt
- List Prompts - List all prompts