Skip to main content

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_jobs
integer
Total number of jobs created by the user
total_documents
integer
Total number of documents across all jobs
documents_processed
integer
Number of successfully processed documents
documents_failed
integer
Number of failed documents
jobs_by_status
object
Count of jobs grouped by status
recent_activity
array
Last 5 jobs (most recent first)

Example Request

cURL
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

React Dashboard
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

StatusDescription
401Unauthorized - Invalid or missing token
500Internal Server Error

Performance Notes

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.

Build docs developers (and LLMs) love