Skip to main content

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

HeaderRequiredDescription
AuthorizationYesBearer <access_token>

Path Parameters

ParameterTypeRequiredDescription
prompt_idintegerYesPrompt ID

Query Parameters

ParameterTypeRequiredDescription
period_startstringNoStart date (ISO 8601 format, e.g., "2024-12-01T00:00:00Z")
period_endstringNoEnd 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

StatusCodeDescription
400BAD_REQUESTInvalid date format (use ISO 8601)
401UNAUTHORIZEDInvalid or missing authentication token
404NOT_FOUNDPrompt not found
500INTERNAL_SERVER_ERRORInternal 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:00Z
  • 2024-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>"