SmartGradeAI API Documentation

Build powerful educational applications with our RESTful API

Version: v1 Base URL: https://smartgradeai.polimas.net/api/v1 Rate Limit: 1000 req/hour

Introduction

Welcome to the SmartGradeAI API! Our RESTful API allows you to integrate AI-powered quiz generation and grading capabilities into your applications.

Base URL: All API requests should be made to: https://smartgradeai.polimas.net/api/v1

Key Features

  • AI-powered quiz question generation
  • Automated grading with AI assistance
  • Course and student management
  • Real-time analytics and reporting
  • Secure authentication with JWT tokens
  • Comprehensive error handling

Quick Start

# Get your API key from the dashboard
API_KEY="your_api_key_here"

# Make your first API call
curl -X GET "https://smartgradeai.polimas.net/api/v1/courses" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json"

Authentication

SmartGradeAI API uses Bearer token authentication. Include your API key in the Authorization header of all requests.

Security: Never expose your API key in client-side code or public repositories.

Request Headers

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Accept: application/json

Obtaining an API Key

  1. Log in to your SmartGradeAI account
  2. Navigate to Settings → API Keys
  3. Click "Generate New API Key"
  4. Copy and securely store your key

Rate Limiting

Rate Limit Information
  • Default limit: 1000 requests per hour
  • AI Generation: 100 requests per hour
  • Bulk operations: 10 requests per minute

Rate Limit Headers

The API returns rate limit information in response headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200

Handling Rate Limits

// Example: Handling rate limits in JavaScript
async function makeAPICall(endpoint) {
    const response = await fetch(endpoint, {
        headers: {
            'Authorization': `Bearer ${API_KEY}`
        }
    });
    
    if (response.status === 429) {
        const retryAfter = response.headers.get('Retry-After');
        console.log(`Rate limited. Retry after ${retryAfter} seconds`);
        // Implement exponential backoff
        await sleep(retryAfter * 1000);
        return makeAPICall(endpoint);
    }
    
    return response.json();
}

Error Handling

The API uses standard HTTP status codes and returns JSON error responses.

Error Response Format

{
    "error": {
        "code": "RESOURCE_NOT_FOUND",
        "message": "The requested quiz was not found",
        "details": {
            "quiz_id": 123
        },
        "timestamp": "2024-01-15T10:30:00Z"
    }
}

Common Error Codes

Status Code Error Code Description
400 BAD_REQUEST Invalid request parameters
401 UNAUTHORIZED Missing or invalid API key
403 FORBIDDEN Access denied to resource
404 NOT_FOUND Resource not found
429 RATE_LIMITED Too many requests
500 INTERNAL_ERROR Server error

Authentication Endpoints

POST /auth/login

Authenticate user and obtain access token.

Request Body
{
    "username": "user@example.com",
    "password": "securepassword"
}
Response
{
    "success": true,
    "data": {
        "access_token": "eyJhbGciOiJIUzI1NiIs...",
        "token_type": "Bearer",
        "expires_in": 3600,
        "user": {
            "id": 1,
            "username": "john_doe",
            "email": "user@example.com",
            "role": "lecturer"
        }
    }
}
POST /auth/refresh

Refresh access token using refresh token.

Request Body
{
    "refresh_token": "eyJhbGciOiJIUzI1NiIs..."
}

Quiz Endpoints

GET /quizzes

Retrieve list of quizzes with optional filters.

Query Parameters
Parameter Type Required Description
course_id integer Optional Filter by course ID
status string Optional Filter by status (published, draft)
page integer Optional Page number (default: 1)
limit integer Optional Items per page (default: 20, max: 100)
Response
{
    "success": true,
    "data": {
        "quizzes": [
            {
                "id": 1,
                "title": "Chapter 1 Quiz",
                "description": "Introduction to Programming",
                "course_id": 5,
                "total_marks": 100,
                "duration_minutes": 60,
                "is_published": true,
                "created_at": "2024-01-15T10:00:00Z"
            }
        ],
        "pagination": {
            "page": 1,
            "limit": 20,
            "total": 45,
            "pages": 3
        }
    }
}
POST /quizzes

Create a new quiz.

Request Body
{
    "course_id": 5,
    "title": "Midterm Exam",
    "description": "Covers chapters 1-5",
    "quiz_type": "exam",
    "total_marks": 100,
    "duration_minutes": 120,
    "start_datetime": "2024-02-01T09:00:00Z",
    "end_datetime": "2024-02-01T11:00:00Z",
    "attempts_allowed": 1,
    "instructions": "Read all questions carefully",
    "is_published": false
}
Response
201 Created
{
    "success": true,
    "data": {
        "quiz_id": 123,
        "message": "Quiz created successfully"
    }
}

AI Generation Endpoints

POST /ai/generate-questions

Generate quiz questions using AI based on topic and parameters.

This endpoint has a separate rate limit of 100 requests per hour.
Request Body
{
    "topic": "Data Structures and Algorithms",
    "difficulty": "medium",
    "questions": {
        "mcq": 5,
        "short_answer": 3,
        "essay": 2
    },
    "language": "en",
    "context": "Computer Science undergraduate level"
}
Response
{
    "success": true,
    "data": {
        "questions": [
            {
                "type": "mcq",
                "question": "What is the time complexity of binary search?",
                "options": [
                    "O(n)",
                    "O(log n)",
                    "O(n²)",
                    "O(1)"
                ],
                "correct_answer": "O(log n)",
                "explanation": "Binary search divides the search space in half...",
                "marks": 2
            }
        ],
        "metadata": {
            "total_questions": 10,
            "generation_time": 3.2,
            "tokens_used": 1500
        }
    }
}
POST /ai/grade-answer

Get AI-powered grading suggestions for student answers.

Request Body
{
    "question": "Explain the concept of recursion in programming",
    "student_answer": "Recursion is when a function calls itself...",
    "max_marks": 10,
    "grading_criteria": "Clarity, accuracy, examples"
}
Response
{
    "success": true,
    "data": {
        "suggested_score": 8,
        "feedback": "Good explanation with clear understanding...",
        "strengths": ["Clear definition", "Good example"],
        "improvements": ["Could include more complex examples"],
        "confidence": 0.85
    }
}

Try It Out

Interactive API Explorer

Test API endpoints directly from your browser.

SDKs & Libraries

JavaScript/Node.js

Official JavaScript SDK for browser and Node.js

npm install smartgradeai-sdk
View on GitHub
Python

Python SDK for SmartGradeAI API

pip install smartgradeai
View on GitHub
PHP

PHP SDK for SmartGradeAI API

composer require smartgradeai/php-sdk
View on GitHub
Java

Java SDK for SmartGradeAI API

<dependency>
    <groupId>com.smartgradeai</groupId>
    <artifactId>sdk</artifactId>
</dependency>
View on GitHub

Postman Collection

Download our Postman collection to quickly test all API endpoints.

SmartGradeAI API Collection

Complete collection with all endpoints, examples, and test scripts.

Import Instructions

  1. Open Postman
  2. Click "Import" in the top left
  3. Select the downloaded JSON file
  4. Configure your API key in the collection variables
  5. Start testing!

Changelog

v1.2.0 - January 15, 2024
New Features
  • Added bulk quiz creation endpoint
  • Introduced webhook support for real-time events
  • New analytics endpoints for detailed reporting
Improvements
  • Enhanced AI grading accuracy
  • Improved response times by 30%
  • Better error messages with detailed debugging info
v1.1.0 - December 1, 2023
New Features
  • AI question generation endpoint
  • Batch submission grading
  • CSV export functionality
Bug Fixes
  • Fixed pagination issues in quiz listing
  • Resolved timezone handling in date filters
v1.0.0 - November 1, 2023

Initial release of SmartGradeAI API

  • Basic CRUD operations for quizzes, courses, and users
  • Authentication with JWT tokens
  • Rate limiting and error handling