Trivia API Guide 2026: Open Trivia DB, The Trivia API and Other Quiz APIs
A trivia API returns quiz questions as JSON: the question, the correct answer, usually a few wrong answers, and metadata such as category and difficulty. You call an endpoint, render the question and check the player's answer. That saves you from writing and fact-checking thousands of questions yourself.
This guide compares the trivia APIs that are live in November 2026, shows how to use Open Trivia DB (the most popular free option) with session tokens and rate limits, and lists services that have shut down so you do not build on them. We checked every provider's documentation and made test requests while writing.
Trivia APIs Compared
| API | Question format | Size | Free access | Key | Commercial use |
|---|---|---|---|---|---|
| Open Trivia DB | Multiple choice, true/false | 5,000+ verified questions, 24 categories | Free; 1 request per 5 s per IP; up to 50 questions per call | No | CC BY-SA 4.0 licence (attribution, share-alike) |
| The Trivia API | Multiple choice; image and text-input questions on paid plans | 14,000+ questions, 10 categories | Up to 50 questions per request, 20 requests per 5 s | No (yes for paid features) | Paid subscription required |
| QuizAPI | Multiple choice, true/false, open-ended | About 12,000 questions, 135 categories | 500 calls/month | Yes | Not stated |
| API Ninjas Trivia | Question with a free-text answer | 100 questions on the free plan | 3,000 calls/month | Yes | Not on the free plan |
| API League Random Trivia | A single trivia fact (no answer options) | Not stated | 50 tokens/day, 1 token per call | Yes | Paid plans (from $7/mo) |
| API League Random Riddle | Riddle with answer, 3 difficulty levels | Not stated | 50 tokens/day, 1 token per call | Yes | Paid plans (from $7/mo) |
Quick picks: use Open Trivia DB for a free multiple-choice quiz with no sign-up. Use The Trivia API if you need image questions, translations or a commercial licence. Use API League's trivia and riddle endpoints for "did you know?" facts and brain-teasers alongside other APIs on the same key.
Open Trivia DB (opentdb)
Open Trivia Database is a free, user-contributed question database run by PIXELTAIL GAMES. It needs no API key. The site reports over 5,000 verified questions across 24 categories, from General Knowledge and Science & Nature to Entertainment: Video Games, with thousands more submissions waiting for review.
Request parameters
All questions come from https://opentdb.com/api.php. The API helper page builds URLs for you.
amount: number of questions, maximum 50 per call (required)category: a category ID from 9 to 32 (the list is atapi_category.php)difficulty:easy,mediumorhardtype:multiplefor multiple choice orbooleanfor true/falseencode:urlLegacy,url3986orbase64; the default is HTML entitiestoken: a session token (see below)
A real response to https://opentdb.com/api.php?amount=1:
{
"response_code": 0,
"results": [
{
"type": "multiple",
"difficulty": "medium",
"category": "Entertainment: Cartoon & Animations",
"question": "In what year did the anime adaptation of "March Comes In Like A Lion" air?",
"correct_answer": "2016",
"incorrect_answers": ["2017", "2018", "2015"]
}
]
} Note the HTML entities (&, "). Either decode them before display or request encode=url3986 and run each string through decodeURIComponent. For true/false questions, correct_answer is "True" or "False" and incorrect_answers holds the other value.
Rate limit and response codes
Each IP address can call the API once every 5 seconds. A second call inside that window returns HTTP 429 with response_code 5. In that error response the array key is result, not results, so check the code before reading questions. The response codes are:
0 Success
1 No results: the database cannot supply that many questions for your filters
2 Invalid parameter
3 Token not found
4 Token empty: you have seen every question for this query; reset the token
5 Rate limit exceeded
Because of the 5-second limit, fetch a full round (up to 50 questions) in one call and serve it from memory instead of requesting one question at a time. If many users share your server's IP, fetch on the server and cache.
Session tokens: no repeated questions
Request a token with api_token.php?command=request and add &token=... to question requests. The API then never returns the same question twice for that token. When the pool runs out you get code 4; reset with api_token.php?command=reset&token=.... Tokens are deleted after 6 hours of inactivity.
const BASE = "https://opentdb.com";
function shuffle(items) {
for (let i = items.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[items[i], items[j]] = [items[j], items[i]];
}
return items;
}
async function getToken() {
const res = await fetch(BASE + "/api_token.php?command=request");
return (await res.json()).token;
}
async function getRound(token, amount = 10) {
const url = BASE + "/api.php?amount=" + amount +
"&type=multiple&encode=url3986&token=" + token;
const data = await (await fetch(url)).json();
if (data.response_code === 5) throw new Error("Rate limited, retry after 5 seconds");
if (data.response_code === 4) throw new Error("Token exhausted, reset it");
if (data.response_code !== 0) throw new Error("Open Trivia DB code " + data.response_code);
return data.results.map(q => ({
question: decodeURIComponent(q.question),
correct: decodeURIComponent(q.correct_answer),
answers: shuffle([q.correct_answer, ...q.incorrect_answers].map(decodeURIComponent))
}));
} Licence
Open Trivia DB content is published under the Creative Commons Attribution-ShareAlike 4.0 International licence. That licence allows reuse, including commercially, if you credit the source and share adapted question sets under the same licence. The site does not add separate commercial terms, so read the licence and credit Open Trivia DB in your app.
The Trivia API
The Trivia API (version 2) has more than 14,000 questions across 10 categories. Without a key you can request up to 50 questions per call and up to 20 requests every 5 seconds from one IP. Each question includes correctAnswer, incorrectAnswers, question.text, difficulty, regions and tags such as topic:classic-hollywood, so you can build narrow quizzes.
curl "https://the-trivia-api.com/v2/questions?limit=1"
[
{
"category": "film_and_tv",
"correctAnswer": "William Wyler",
"incorrectAnswers": ["...", "...", "..."],
"question": { "text": "Which director directed Ben-Hur?" },
"tags": ["category:film-and-tv", "topic:film", "topic:classic-hollywood"],
"type": "text_choice",
"difficulty": "hard",
"regions": []
}
] Paid features need a key in the X-API-Key header. Sessions (no repeats) come with the Regular and Complete subscriptions. Text-input questions with LLM answer checking, image questions, translations into 9 languages and semantic search require the Complete subscription. The pricing page names the plans but does not list prices.
Licence: free use is for non-commercial projects under CC BY-NC 4.0, with a discreet credit to the API. A commercial app needs a subscription.
QuizAPI
QuizAPI started as a technical quiz API and has been rebuilt as a quiz platform, currently labelled public beta. Its metadata endpoint lists 135 categories, mixing tech topics (AWS, Docker, Kubernetes, Python) with general ones (History, Geography, Movies), and about 12,000 questions. GET /api/v1/questions filters by category, difficulty (easy to expert), type (multiple choice, true/false, open-ended) and tags, and returns answers with an isCorrect flag plus an explanation.
A key is required. The free plan includes 500 API calls per month; Starter costs $1.99 per month for 10,000 calls and Pro $9.99 per month for 100,000. The rate limit is 60 requests per minute per IP. QuizAPI does not state its commercial-use terms.
API Ninjas Trivia API
API Ninjas offers /v1/trivia and /v1/triviaoftheday. Each item has a category, a question and a free-text answer, with no wrong options, so it suits typed-answer games better than multiple choice. Free users get access to only 100 questions; the full 100,000+ question pool and the category and limit parameters are premium. The free plan allows 3,000 calls per month, is meant for evaluation and demos, requires attribution and does not allow commercial use.
API League: Random Trivia and Random Riddle APIs
API League's Random Trivia API returns a single interesting fact. It does not return a question with answer options, so it fits "did you know?" widgets, loading screens and daily-fact features. An optional max-length parameter keeps facts short enough for small screens.
curl "https://api.apileague.com/retrieve-random-trivia?max-length=200&api-key=YOUR_API_KEY"
{
"trivia": "Koalas sleep up to 20 hours a day."
} The Random Riddle API returns a riddle with its answer and a difficulty of easy, medium or hard, which you can request with the difficulty parameter.
curl "https://api.apileague.com/retrieve-random-riddle?difficulty=easy&api-key=YOUR_API_KEY"
{
"riddle": "What has 13 hearts but no other organs?",
"answer": "A deck of cards",
"difficulty": "easy"
} Both cost 1 token per call. The free plan includes 50 tokens per day at 1 request per second, for non-commercial use with a backlink. Paid plans start with Rookie at $7 per month (500 tokens per day, commercial use, no backlink). The same key works for all 55 API League APIs, including the Random Quote, Random Joke and Search Games APIs, and there are SDKs in 21 languages. See pricing.
Trivia APIs That Have Shut Down
jService: the Jeopardy-style clue API at jservice.io is gone; the domain returns "410 Gone" and the project's README says it is no longer running. The community successor jservice.xyz has also stopped hosting and now only points to its source code for self-hosting.
Numbers API: the numbersapi.com domain no longer serves the API (requests return errors and the HTTPS certificate belongs to an unrelated site). Remove it from existing apps.
If an old tutorial uses either service, switch to Open Trivia DB or The Trivia API.
Building a Quiz App on a Trivia API
Avoid repeats. Use session tokens where the API has them (Open Trivia DB free, The Trivia API on paid plans). Otherwise store the question IDs or text each player has seen.
Shuffle answers. Most APIs put the correct answer in a separate field. Merge and shuffle it with the wrong answers, using a proper shuffle such as Fisher-Yates.
Decode text. Open Trivia DB returns HTML entities by default. Request URL or base64 encoding and decode, or you will show
"to players.Prefetch and cache. Fetch the next round while players answer the current one. That hides latency, respects rate limits and keeps the game running during short outages.
Calibrate difficulty. "Easy" and "hard" mean different things across providers. Track how often each question is answered correctly and adjust scoring or filters.
Let players report errors. Community and generated questions contain mistakes and outdated facts. A "report this question" button and a blocklist of question IDs fix most problems.
Check the licence before you monetize. Open Trivia DB is CC BY-SA, The Trivia API's free use is non-commercial only, and API Ninjas' free plan excludes commercial use.
Keep keys on the server. For APIs that need a key, call them from your backend so the key never ships in browser or mobile code.
Designing Your Own Trivia API
If you need full control over content, a small trivia service is straightforward:
Schema:
id,question,correct_answer,incorrect_answers[],category,difficulty,language,tags[],source,created_at. Index category and difficulty for fast random selection.Endpoints:
GET /questions/randomwith filters,GET /questionswith pagination for study modes, andPOST /sessionsto track served questions.Content pipeline: write questions by hand, adapt openly licensed sources (respecting share-alike terms), and review every question for accuracy and duplicates before it goes live.
Limits and errors: issue keys, enforce per-minute limits, return
X-RateLimit-Remainingheaders, and use standard status codes (400, 401, 429, 500).
Related Guides
Best game APIs: video game data, player stats and platform APIs.
How to write a joke app in React: a small app built on a random-content API.
Best free APIs: free APIs for developers grouped by category.
Frequently Asked Questions
Is there a free trivia API?
Yes. Open Trivia DB is free, needs no API key and returns up to 50 multiple-choice or true/false questions per call, with a limit of one request every 5 seconds per IP. The Trivia API is free for non-commercial use without a key.
Does Open Trivia DB need an API key?
No. Open Trivia DB does not require an API key or an account. You can call https://opentdb.com/api.php?amount=10 directly. Session tokens are optional and only prevent repeated questions.
What is the Open Trivia DB rate limit?
Each IP address can access the API once every 5 seconds, and one call returns at most 50 questions. Going faster returns HTTP 429 with response code 5.
Can I use Open Trivia DB in a commercial app?
Open Trivia DB publishes its questions under the CC BY-SA 4.0 licence, which allows commercial use if you give attribution and share adapted question sets under the same licence. The site does not add separate commercial terms.
What happened to jService?
jService, the Jeopardy-style clue API at jservice.io, has shut down and its domain returns 410 Gone. The jservice.xyz successor has also stopped hosting. Open Trivia DB and The Trivia API are live alternatives.
Which trivia API supports multiple languages?
The Trivia API offers questions in 9 languages, including Spanish, French, German and Hindi, with its Complete subscription. Open Trivia DB has no language parameter.