Base URL
The inspir API is available at:/api. For example, to create a quiz:
Request Format
JSON Requests
Most API endpoints accept JSON request bodies. Include the appropriateContent-Type header:
File Uploads
Endpoints that accept file uploads usemultipart/form-data:
.txt- Plain text files.doc- Microsoft Word (legacy).docx- Microsoft Word (modern)
Request Size Limits
JSON request bodies are limited to 10MB.Response Format
All API responses are JSON-formatted.Success Response
Successful responses return the requested data with a2xx status code:
Error Response
Error responses include anerror field with a human-readable message:
HTTP Status Codes
The API uses standard HTTP status codes:| Code | Meaning | Common Causes |
|---|---|---|
200 | OK | Request succeeded |
400 | Bad Request | Invalid input, validation error |
401 | Unauthorized | Missing or invalid authentication token |
403 | Forbidden | Valid token but insufficient permissions |
404 | Not Found | Resource doesn’t exist |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Server error |
503 | Service Unavailable | AI service overloaded |
504 | Gateway Timeout | AI service timeout |
Error Handling
Validation Errors
Validation errors return400 Bad Request:
"Username and password are required""Passwords do not match""Username already exists""Only TXT, DOC, and DOCX files are allowed"
Authentication Errors
Authentication failures return401 Unauthorized:
"No authorization token provided"- Missing Authorization header"Invalid token"- Malformed JWT token"Token expired"- JWT token has expired (7-day expiration)"Invalid or expired token"- Token valid but user not found"Invalid username or password"- Login credentials incorrect
Rate Limit Errors
When rate limits are exceeded, the API returns429 Too Many Requests:
RateLimit-Limit- Maximum requests allowed in the windowRateLimit-Remaining- Requests remaining in current windowRateLimit-Reset- Time when the limit resets (Unix timestamp)
AI Service Errors
AI-powered endpoints may return service-specific errors: 503 Service Unavailable - AI provider overloaded:Rate Limits
The API implements rate limiting to prevent abuse:Authentication Endpoints
Endpoints:/api/auth/signup, /api/auth/login
15 minutes (900,000 ms)
5 attempts per window
Quiz Generation
Endpoints:/api/quiz/generate
1 hour (3,600,000 ms)
20 quiz generations per hour
Quiz Submission
Endpoints:/api/quiz/submit, /api/quiz/shared/:shareToken/submit
5 minutes (300,000 ms)
10 submissions per 5 minutes
General API
All other endpoints15 minutes (900,000 ms)
100 requests per window
CORS Policy
The API enforces CORS restrictions. Allowed origins:https://quiz.inspir.uk(production frontend)http://localhost:5173(development frontend)http://localhost:3000(local testing)- Configured additional origins via
ADDITIONAL_ORIGINSenvironment variable
GET, POST, PUT, DELETE, OPTIONS
Allowed headers: Content-Type, Authorization
Credentials: Supported (cookies and authentication headers)
Health Check
Check API availability:API Patterns
Optional Authentication
Some endpoints support optional authentication - they work for both guest and authenticated users:/api/quiz/generate- Guests can generate quizzes but won’t save history/api/quiz/submit- Guests can submit but won’t track progress/api/quiz/:id- Anyone can view quizzes they have access to
- Quiz history saved
- Progress tracking
- Ability to share quizzes
- Statistics and analytics
Guest vs Authenticated
Endpoints are categorized as:- Public - No authentication required (e.g., health check, shared quiz access)
- Optional Auth - Enhanced features for authenticated users (e.g., quiz generation)
- Required Auth - Must be authenticated (e.g., quiz history, sharing, user profile)
Next Steps
Authentication
Learn how to authenticate with JWT tokens
Quiz API
Generate and manage quizzes
Doubt Solver
Access AI-powered doubt solver
Study Tools
Access AI-powered study tools