BYTETOOLS

Open Trivia Database API

Free trivia and quiz API with no key: 24 categories, three difficulty levels, multiple choice and true/false questions. Tested curl example and live JSON.

No API key requiredCORS enabledHTTPSFree tier

Endpoint tested and returned HTTP 200 on 2026-08-19

What is the Open Trivia Database API?

The Open Trivia Database is a free quiz question API requiring no API key. It serves multiple choice and true/false questions across 24 categories and three difficulty levels, with over 4,000 verified questions.

Open Trivia DB is the standard choice for building a quiz app, and it is genuinely well designed for the purpose: you control category, difficulty, question type and count, so a single request returns exactly the round you want to render.

Two details matter when integrating. Question text is HTML-encoded by default, so `"` and `'` will appear literally unless you decode it or request `encode=url3986` and decode yourself. And incorrect answers arrive in a separate array, so you must merge and shuffle them with the correct answer yourself — the API deliberately does not pre-shuffle.

Quick facts

Base URL
https://opentdb.com
Authentication
No key. Optional session tokens prevent repeat questions within a session.
Rate limit
One request every 5 seconds per IP.
Pricing
Free, CC BY-SA 4.0 licensed.
CORS
Enabled — callable directly from browser JavaScript
Official docs
Read the docs

How to use the Open Trivia Database API

Every request below was executed against the live API on 2026-08-19, and the response shown is the real body it returned — not an illustration.

1. Fetch one multiple-choice trivia question

GET https://opentdb.com/api.php?amount=1&type=multiple

curl
curl 'https://opentdb.com/api.php?amount=1&type=multiple'
JavaScript (fetch)
const res = await fetch("https://opentdb.com/api.php?amount=1&type=multiple");
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
const data = await res.json();
console.log(data);
Python (requests)
import requests

res = requests.get("https://opentdb.com/api.php?amount=1&type=multiple", timeout=20)
res.raise_for_status()
print(res.json())
Response — HTTP 200
{
  "response_code": 0,
  "results": [
    {
      "type": "multiple",
      "difficulty": "medium",
      "category": "History",
      "question": "Joseph Smith was the founder of what religion?",
      "correct_answer": "Mormonism",
      "incorrect_answers": [
        "Buddhism",
        "Christianity",
        "Hinduism"
      ]
    }
  ]
}

Parameters

ParameterTypeRequiredDescription
amountintegerRequiredNumber of questions, 1 to 50. 10
categoryintegerOptionalCategory id from /api_category.php. 18
difficultystringOptionaleasy, medium or hard. medium
typestringOptionalmultiple or boolean. multiple
encodestringOptionalurl3986 or base64 to control text encoding. url3986

Response fields

response_codeinteger
0 means success. 1 means not enough questions matched your filters.
results[].questionstring
Question text, HTML-encoded unless you set `encode`.
results[].correct_answerstring
The right answer.
results[].incorrect_answersarray
Wrong answers — you must merge and shuffle these yourself.
results[].category / difficultystring
Category name and difficulty level.

What you can build with the Open Trivia Database API

  • Build a full quiz or trivia game with category and difficulty selection
  • Generate pub quiz rounds programmatically
  • Add a trivia command to a Discord or Slack bot
  • Practise array shuffling and HTML decoding in a real scenario

Common errors and how to fix them

response_code: 1

Not enough questions match the requested filters.

Fix: Reduce `amount` or loosen category/difficulty — narrow combinations often have very few questions.

response_code: 5

Rate limited: more than one request per 5 seconds.

Fix: Throttle to one request per 5 seconds, or fetch a whole round at once instead of question by question.

" visible in question text

Text is HTML-encoded by default.

Fix: Decode the HTML entities, or request `encode=url3986` and decode with decodeURIComponent.

Open Trivia Database API — frequently asked questions

Is there a free trivia API for building a quiz app?

Yes. The Open Trivia Database provides over 4,000 questions across 24 categories and three difficulty levels with no API key required.

Why does the question text contain " and '?

Questions are HTML-encoded by default. Decode the entities before rendering, or pass `encode=url3986` and use decodeURIComponent.

How do I shuffle the answers?

The API returns the correct answer separately from the incorrect ones, deliberately. Merge the arrays and shuffle them yourself, otherwise the right answer is always in the same position.

What is the Open Trivia DB rate limit?

One request every 5 seconds per IP. Fetch an entire quiz round in one call rather than requesting each question individually.

Tools that pair with this API

Open Trivia Database is an independent third-party service and is not affiliated with ByteTools or ByteVancer. Details on this page were verified on 2026-08-19; always check the official documentation before relying on this API in production, as terms and limits can change.