canonical: https://jentic.com/apis/opentdb.com/opentdb

# Opentdb Open Trivia Database API

The Open Trivia Database API serves a free, user-contributed library of trivia questions across categories like history, science, entertainment, and sports. Endpoints provide configurable question retrieval (amount, category, difficulty, type), session token management to avoid repeat questions, category metadata, and per-category and global question counts. The service is openly accessible with no authentication required and is widely used for quiz games, educational apps, and developer learning projects.

## For AI agents

Fetch trivia questions filtered by category, difficulty, and type, and manage session tokens to avoid repeats.

## Scope

Does not handle quiz scoring, user accounts, or curriculum tracking - use for fetching trivia questions and category metadata only.

## Capabilities

- Fetch up to 50 trivia questions per request via /api.php with category, difficulty, and type filters
- Request multiple-choice, true/false, or both question types from /api.php
- Generate or reset a session token with /api_token.php to avoid repeat questions across rounds
- List all available trivia categories with /api_category.php
- Get the question count for a single category via /api_count.php
- Get global question counts across the entire database with /api_count_global.php

## Use cases

### Quiz Game Question Source

Mobile and web quiz games can power their question feed from /api.php, requesting batches of 10-20 questions with the desired category, difficulty, and type. Pair with /api_token.php session tokens so the same question doesn't appear twice in a single user's run. The Open Trivia DB has thousands of community-contributed questions covering 24+ categories, eliminating the need to build and maintain a private question bank.

Example prompt: GET /api.php?amount=10&category=21&difficulty=hard&type=multiple to fetch 10 hard sports multiple-choice questions

### Educational Practice App

Learning apps that drill students on a topic can pull from /api.php with the relevant category and difficulty, then track progress per session using a token from /api_token.php. The /api_count.php endpoint exposes how many questions remain in a category so the app can warn the learner before exhausting available content. No API key is needed, simplifying classroom deployment.

Example prompt: Generate a token via /api_token.php, then loop GET /api.php?amount=20&category=18&difficulty=easy&token=... until /api_count.php is exhausted

### Trivia Bot for Chat Platforms

A Discord, Slack, or Telegram bot can post a trivia question on a schedule by calling /api.php?amount=1 and rendering the question and answers in the channel. Use /api_category.php at startup to expose category-selection commands to users. Because Open Trivia DB has no auth and no per-key rate limit, the bot can be deployed without operator configuration.

Example prompt: GET /api_category.php to list categories, then GET /api.php?amount=1&category={chosen}&type=boolean for a true/false question

### AI Agent Trivia Host

An AI agent acting as a trivia host can fetch questions from the Open Trivia DB through Jentic without managing rate limits or HTML decoding wrappers. Jentic resolves the natural-language intent ('get me a hard history question') into the right /api.php call with category and difficulty params and returns the structured JSON the agent renders to the user.

Example prompt: Through Jentic, search 'get a trivia question', resolve to GET /api.php, and execute with amount=1, category=23 (history), difficulty=hard

## Key endpoints

| Method | Path | Description |
| --- | --- | --- |
| GET | /api.php | Fetch trivia questions with filters |
| GET | /api_token.php | Create or reset a session token |
| GET | /api_category.php | List all trivia categories |
| GET | /api_count.php | Get question count for a category |
| GET | /api_count_global.php | Get global question counts |

## Key resources

- **Questions** — Fetch trivia questions with category, difficulty, type, and amount filters.
- **Session Tokens** — Create and reset session tokens to prevent repeats within a session.
- **Categories** — List trivia categories and their numeric IDs.
- **Counts** — Per-category and global question counts.

## Why Jentic

- **Setup:** Wiring the Open Trivia Database API by hand means managing its session token so you do not draw the same question twice and mapping category and count endpoints yourself. Through Jentic you install once, import the Open Trivia Database API from the API Directory, and your agent calls it directly.
- **Permission scoping:** Open Trivia DB is read-only with no credential, so scoping is by operation: you limit the agent to the operations it needs, such as fetching questions or listing categories, and leave the token and count endpoints out unless you want them. Every operation the agent can call is one you chose to allow.
- **Credential handling:** Open Trivia DB needs no credential, so nothing secret is stored for this API. Jentic routes each call directly, and no secret ever enters the agent's prompt, logs, or context.
- **Discovery method:** Agents search Jentic by intent such as 'get a trivia question' or 'list trivia categories', and Jentic returns the matching Open Trivia operation with its parameter schema so the agent calls the right endpoint without browsing the reference docs.

## Related APIs

- **API Ninjas** — API Ninjas exposes a trivia and quiz endpoint plus many other utility data APIs.
- **Numverify API** — Different domain entirely, included as a comparison point for free public-data APIs that require no auth.
- **Discord API** — Post trivia questions fetched from Open Trivia DB into Discord channels via bot integration.

## FAQ

### What authentication does the Open Trivia Database API use?

None - the API is fully open and requires no API key. Through Jentic the request is dispatched without any credential handling, so there is nothing to provision in the vault for this API.

### Can I avoid repeat questions across rounds with the Open Trivia Database API?

Yes - call /api_token.php to generate a session token, then pass token={token} on subsequent /api.php calls. The token tracks which questions have been served and the API will return a response code 4 once the category is exhausted, at which point you can reset the token.

### What are the rate limits for the Open Trivia Database API?

Open Trivia DB enforces a fair-use policy of one request every 5 seconds per IP. There are no documented hard caps for low-traffic apps. /api_count_global.php and /api_count.php can be polled less frequently to plan question budgets.

### How do I fetch a hard multiple-choice question through Jentic?

Search Jentic for 'get a trivia question', load the GET /api.php schema, and execute with amount=1, type=multiple, difficulty=hard. Jentic returns the question and shuffled answer list in JSON.

### Is the Open Trivia Database API free for commercial use?

Yes - Open Trivia DB content is licensed under Creative Commons Attribution-ShareAlike 4.0. Attribution and redistribution rules apply; check opentdb.com for the current licensing notice before shipping a commercial product.

### What categories does the Open Trivia Database API cover?

Categories include General Knowledge, Books, Film, Music, TV, Video Games, Science & Nature, Mathematics, History, Geography, Politics, Sports, and more. Call /api_category.php for the live list of category IDs and names.

### Can I limit what my agent is allowed to do with the Open Trivia Database API?

Yes. Because you run Jentic One self-hosted, your own rules decide which of this API's operations the agent may call, and the Open Trivia Database API is read-only with no credential to manage. You can allow only the operations the agent needs, such as fetching questions from /api.php or listing categories from /api_category.php, while leaving out the session-token endpoint /api_token.php and the count endpoints /api_count.php and /api_count_global.php. Every operation the agent can reach is one you explicitly chose to permit.
