API Documentation
Everything you need to integrate with the Trivia API
Authentication
All API requests require an API key. Include your key in the X-API-Key header with every request.
Get Your API Key
- Go to API Keys in your dashboard
- Click "Create New Key"
- Copy your key and store it securely
// Include your API key in all requests
fetch('https://api.trivia-engine.com/api/v1/trivia/random', {
headers: {
'X-API-Key': 'your_api_key_here'
}
});Endpoints
Base URL: https://api.trivia-engine.com/api/v1
Get Random Question
GET
/trivia/randomReturns a random trivia question. Optionally filter by category.
Parameters
category | string | Filter by category name |
const response = await fetch('https://api.trivia-engine.com/api/v1/trivia/random', {
headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data.trivia.question);List Categories
GET
/trivia/categoriesReturns all available trivia categories with question counts.
const response = await fetch('https://api.trivia-engine.com/api/v1/trivia/categories', {
headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
data.categories.forEach(cat => console.log(cat.title));Questions by Category
GET
/trivia/category/:titleReturns questions from a specific category with pagination.
Parameters
title* | string | Category title (URL encoded) |
limit | integer | Results per page (default: 10, max: 100) |
offset | integer | Number of results to skip |
const category = encodeURIComponent('WORLD HISTORY');
const response = await fetch(
`https://api.trivia-engine.com/api/v1/trivia/category/${category}?limit=5`,
{ headers: { 'X-API-Key': 'YOUR_API_KEY' } }
);
const data = await response.json();Search Questions
GET
/trivia/searchSearch questions by keyword. Searches question text.
Parameters
q* | string | Search query (min 2 characters) |
limit | integer | Results per page (default: 10, max: 100) |
offset | integer | Number of results to skip |
const query = encodeURIComponent('solar system');
const response = await fetch(
`https://api.trivia-engine.com/api/v1/trivia/search?q=${query}&limit=10`,
{ headers: { 'X-API-Key': 'YOUR_API_KEY' } }
);Get Question by ID
GET
/trivia/:idRetrieve a specific question by its ID.
Parameters
id* | integer | The question ID |
const response = await fetch('https://api.trivia-engine.com/api/v1/trivia/12345', {
headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();Response Format
All responses are JSON with a consistent structure.
Trivia Question Object
| Field | Type | Description |
|---|---|---|
id | integer | Unique question identifier |
question | string | The trivia question text |
options | string[] | Array of 4 answer choices |
correctAnswer | string | The correct answer (matches one option) |
category | string | Category name (uppercase) |
Error Handling
Errors return appropriate HTTP status codes with a JSON body.
{
"success": false,
"error": "Invalid API key"
}HTTP Status Codes
| Code | Meaning | Common Cause |
|---|---|---|
200 | Success | Request completed successfully |
400 | Bad Request | Missing required parameters |
401 | Unauthorized | Missing or invalid API key |
404 | Not Found | Question or category not found |
429 | Too Many Requests | Rate limit exceeded |
Rate Limits
API requests are rate limited per API key to ensure fair usage.
Default Limits
- 100 requests per minute per API key
- 10,000 requests per day per API key
Rate Limit Headers
Check these response headers to monitor your usage:
X-RateLimit-Limit | Maximum requests allowed |
X-RateLimit-Remaining | Requests remaining in current window |
X-RateLimit-Reset | Unix timestamp when limit resets |