Get Prompt Analytics
Sprint 3
Get analytics for a prompt including execution statistics and performance metrics.
Endpoint
GET /api/v1/prompts/{prompt_id}/analytics
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <access_token> |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt_id | integer | Yes | Prompt ID |
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period_start | string | No | Start date (ISO 8601 format, e.g., "2024-12-01T00:00:00Z") |
period_end | string | No | End date (ISO 8601 format, e.g., "2024-12-31T23:59:59Z") |
Response
Success (200)
{
"success": true,
"data": {
"prompt_id": 1,
"execution_count": 50,
"success_count": 45,
"failure_count": 5,
"success_rate": 0.9,
"avg_total_duration_ms": 8500,
"avg_ai_response_time_ms": 3500,
"avg_query_execution_time_ms": 5000,
"most_used_data_sources": [
{
"data_source_id": 1,
"data_source_name": "Production PostgreSQL",
"count": 30
}
],
"most_used_schemas": [
{
"schema_name": "public",
"count": 40
}
],
"period_start": "2024-12-01T00:00:00Z",
"period_end": "2024-12-31T23:59:59Z",
"last_calculated_at": "2024-12-31T23:59:59Z"
},
"message": "Analytics retrieved successfully"
}
Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | BAD_REQUEST | Invalid date format (use ISO 8601) |
| 401 | UNAUTHORIZED | Invalid or missing authentication token |
| 404 | NOT_FOUND | Prompt not found |
| 500 | INTERNAL_SERVER_ERROR | Internal server error |
Features
- Execution statistics (count, success rate)
- Performance metrics (average durations)
- Data source usage statistics
- Schema usage statistics
- Date range filtering
- Organization-scoped access control
Date Format
Dates must be in ISO 8601 format:
2024-12-01T00:00:00Z2024-12-01T00:00:00+00:00
Example
curl -X GET "https://api.rivergen.com/api/v1/prompts/1/analytics?period_start=2024-12-01T00:00:00Z&period_end=2024-12-31T23:59:59Z" \
-H "Authorization: Bearer <access_token>"
Related Endpoints
- Get Prompt - Get prompt details
- Get Query Analytics - Get comprehensive query analytics