API docs
Getting started
The base address is https://triviaapi.games/v1. Every endpoint is a GET and returns JSON. To try it now, use the demo key demo (5 questions per request, 10 requests a minute).
curl -H "X-API-Key: demo" "https://triviaapi.games/v1/questions?amount=3"
Your key
Send your key in the X-API-Key header. For quick tests in a browser you can also add ?api_key=YOUR_KEY to the address, but don't put your key in public web pages: anyone could copy it.
GET/v1/questions
Random questions matching your filters. A response never repeats a question.
| Parameter | What it does |
|---|---|
amount | How many questions, 1 to 50 (the free plan allows up to 10; the demo key 5). Default 10. |
category | One or more category keys, separated by commas, like sports,music-80s. Leave it out for all categories. See /v1/categories. |
difficulty | easy, medium, hard or any (the default). |
{
"count": 1,
"questions": [
{
"id": "3f9a1c2b7d4e",
"category": "sports",
"category_name": "Sports",
"difficulty": "easy",
"question": "Which team drafted Drew Bledsoe first overall in 1993?",
"correct_answer": "New England Patriots",
"incorrect_answers": ["Cincinnati Bengals", "Indianapolis Colts", "Seattle Seahawks"]
}
]
}
The right answer is always correct_answer; shuffle it in with the three incorrect_answers before you show them.
GET/v1/questions/{id}
One question by its id, in the same shape as above. Useful for showing a question again, or checking an answer on your server.
GET/v1/categories
Every category your key can use, with how many questions it has at each difficulty.
{ "categories": [ { "key": "sports", "name": "Sports", "adult": false, "questions": 3084, "easy": 1210, "medium": 1450, "hard": 424 }, … ] }
Category keys today:
sports, music, music-80s, music-90s, disco, music-2000s, movies, tv, celebrities, theater, books, history, geography, science, animals, food, general, tech, video-games, vehicles, board-games, comics, anime, art, mythology, politics, math, missing-word
The 21+ bar and nightlife category (strip-club) is turned on per key, on request.
GET/v1/health
No key needed. Returns {"status":"ok"} with the number of questions and categories, for your uptime checks.
Errors
Errors use the usual HTTP status codes, with a short code and a message you can show or log:
{ "error": { "code": "unknown_category", "message": "Unknown category: soccer. See /v1/categories for the list." } }
| Status | Code | What to do |
|---|---|---|
| 400 | bad_amount, unknown_category, bad_difficulty | Fix the parameter named in the message. |
| 401 | missing_key, invalid_key | Send a valid key in X-API-Key. |
| 403 | adult_not_enabled | Ask us to turn on the 21+ category for your key. |
| 404 | not_found | Check the id or the address. |
| 429 | rate_limited | Wait the number of seconds in the Retry-After header. |
Limits
Each key has a per-minute and a per-day limit set by its plan (see pricing). Every response includes X-RateLimit-Limit-Day and X-RateLimit-Remaining-Day, so you can see where you stand.
Tips
- Ask for a batch (say 20) at the start of a game instead of one at a time.
- Keep the ids a player has seen, and skip them when they come up again.
- Call the API from your server, not from public web pages, so your key stays private.
Questions about the API: info@sportsplay.games. Today there are 22,677 questions in the set.