API Directory › 🎮 Games › Open Trivia DB
No authHTTPSCORS

Open Trivia DB API

Free trivia questions across many categories and difficulties — no key.

Category
Auth
No auth needed
HTTPS
Yes
CORS
Yes
Open Open Trivia DB docs ↗

What it does

The Open Trivia Database (OpenTDB) is a free API of user-contributed, verified multiple-choice and true/false trivia questions across ~24 categories and three difficulty levels, licensed CC BY-SA.

Base URL

https://opentdb.com

Authentication

None. /api.php?amount=10 is the core call, with optional category, difficulty, type (multiple/boolean) and encode. /api_category.php lists categories with their ids.

Code examples

curl
curl -s "https://opentdb.com/api.php?amount=5&category=18&difficulty=medium&type=multiple"
Python (with a session token to avoid repeats)
import requests

tok = requests.get("https://opentdb.com/api_token.php",
                   params={"command": "request"}, timeout=10).json()["token"]
r = requests.get("https://opentdb.com/api.php",
                 params={"amount": 10, "token": tok}, timeout=10).json()
for q in r["results"]:
    print(q["question"], "->", q["correct_answer"])

Rate limits & quotas

One request every 5 seconds per IP — faster returns response_code 5. A single call returns at most 50 questions. Use a session token so you never get the same question twice until the pool is exhausted (then reset the token).

Key response fields

response_code0 success, 1 no results, 2 bad parameter, 3 token not found, 4 token empty, 5 rate limited
results[].question / correct_answer / incorrect_answers[]The question and options (HTML-encoded by default)
results[].category / difficulty / typeMetadata

Common errors

response_code 1Not enough questions for that category/difficulty combination — ask for fewer.
response_code 4The session token has returned every available question — call api_token.php?command=reset.
response_code 5You called within 5 seconds of the last request — wait.
(HTML entities)Questions come URL/HTML-encoded — decode, or pass encode=base64 and decode that.

When to use it (and alternatives)

The default for quiz and trivia games, Discord/Slack trivia bots and pub-quiz generators. Respect the 5-second limit — fetch a batch of up to 50 at the start of a round rather than one question at a time. For number facts see Numbers API.

FAQ

Why do I keep getting response_code 5?

The rate limit is one request per 5 seconds per IP. Batch: request amount=50 once per quiz session instead of one question per call.

How do I stop questions repeating?

Request a session token (api_token.php?command=request) and pass it on every call. OpenTDB then excludes questions you have already seen until you reset the token.

Why is the text full of " and '?

The default encoding is HTML entities. Decode client-side, or request encode=base64 / encode=url3986 and decode that format instead.

New to APIs?

Short guides for working with this API — and any other.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

JSON Formatter

Related Games APIs

← Back

More Games APIs · All 196 APIs