GET /api/history/stats
Get comprehensive statistics for the current user’s dashboard, including job counts, document metrics, and recent activity.
Authentication
Requires valid JWT access token in Authorization header.
Response
Total number of jobs created by the user
Total number of documents across all jobs
Number of successfully processed documents
Number of failed documents
Count of jobs grouped by status {
"completed" : 15 ,
"processing" : 2 ,
"failed" : 1 ,
"cancelled" : 0
}
Last 5 jobs (most recent first) Show JobSummary properties
Type of job: single, batch, webhook
Successfully processed documents
When processing completed
Example Request
curl -X GET 'http://localhost:8000/api/history/stats' \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Example Response
{
"total_jobs" : 18 ,
"total_documents" : 453 ,
"documents_processed" : 447 ,
"documents_failed" : 6 ,
"jobs_by_status" : {
"completed" : 15 ,
"processing" : 2 ,
"failed" : 1
},
"recent_activity" : [
{
"id" : "123e4567-e89b-12d3-a456-426614174000" ,
"job_type" : "batch" ,
"status" : "completed" ,
"total_documents" : 25 ,
"processed_count" : 24 ,
"failed_count" : 1 ,
"started_at" : "2024-01-15T10:30:00Z" ,
"completed_at" : "2024-01-15T10:45:00Z" ,
"created_at" : "2024-01-15T10:29:00Z"
}
]
}
Use Cases
Dashboard Metrics Display key metrics on user dashboard:
Total documents processed
Success/failure rates
Recent activity timeline
Usage Analytics Track usage patterns:
Job completion rates
Processing throughput
Error analysis
Progress Monitoring Monitor ongoing work:
Active job count
Documents in processing
Recent completions
Billing Integration Calculate usage for billing:
Total documents processed
API calls made
Processing time consumed
Implementation Example
import { useEffect , useState } from 'react' ;
function Dashboard () {
const [ stats , setStats ] = useState ( null );
useEffect (() => {
async function fetchStats () {
const response = await fetch ( 'http://localhost:8000/api/history/stats' , {
headers: {
'Authorization' : `Bearer ${ localStorage . getItem ( 'access_token' ) } `
}
});
const data = await response . json ();
setStats ( data );
}
fetchStats ();
}, []);
if ( ! stats ) return < div > Loading... </ div > ;
return (
< div className = "dashboard" >
< h1 > Dashboard </ h1 >
< div className = "metrics" >
< div className = "metric" >
< h3 > Total Jobs </ h3 >
< p > { stats . total_jobs } </ p >
</ div >
< div className = "metric" >
< h3 > Documents Processed </ h3 >
< p > { stats . documents_processed } / { stats . total_documents } </ p >
</ div >
< div className = "metric" >
< h3 > Success Rate </ h3 >
< p >
{ (( stats . documents_processed / stats . total_documents ) * 100 ). toFixed ( 1 ) } %
</ p >
</ div >
</ div >
< div className = "recent-activity" >
< h2 > Recent Activity </ h2 >
{ stats . recent_activity . map ( job => (
< div key = { job . id } className = "activity-item" >
< span > { job . job_type } </ span >
< span > { job . status } </ span >
< span > { job . processed_count } / { job . total_documents } documents </ span >
</ div >
)) }
</ div >
</ div >
);
}
Error Responses
Status Description 401 Unauthorized - Invalid or missing token 500 Internal Server Error
The stats endpoint fetches up to 1000 jobs to calculate statistics. For users with large job histories, this may take a few seconds. Consider caching the results on the frontend.