Over 14,800 approved questions

The Trivia API

An HTTP API that returns random trivia questions as JSON. You don't need a key for non-commercial use.

request
curl "https://the-trivia-api.com/v2/questions?categories=science&limit=1"
200 application/json
[
  {
    "category": "science",
    "id": "63adbd6704c68cc1e14b8e2b",
    "correctAnswer": "Metamorphic Rocks",
    "incorrectAnswers": [
      "Igneous Rocks",
      "Sedimentary Rocks",
      "Fossils"
    ],
    "question": {
      "text": "What type of rock is formed when existing rocks are subjected to extreme heat and pressure?"
    },
    "tags": ["geology", "science"],
    "type": "text_choice",
    "difficulty": "medium",
    "regions": [],
    "isNiche": false
  }
]

Filtering questions

Without a key you get multiple choice questions only, up to 50 per request. A subscription key raises the per-request limit to 1,000.

  • categories: 10 of them, from music to food and drink
  • difficulties: easy, medium or hard
  • tags: free-form, such as geology or capital_cities
  • region: a country code, which also lets in questions that only make sense in that country
  • limit: 10 if you leave it out
request.js
const res = await fetch(
  "https://the-trivia-api.com/v2/questions?categories=history,geography&difficulties=hard&limit=20",
  { headers: { "x-api-key": process.env.TRIVIA_API_KEY } }
);
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);

const questions = await res.json();
console.log(questions[0].question.text);

A multiple choice question

8,907 of the questions are text_choice: one correct answer and three wrong ones, which you shuffle yourself.

ScienceMediumText Choice

What is the chemical symbol for gold?

Built with The Trivia API

Real apps and games shipping with our questions today.

It was the only API I found that offered text-input questions. Players now see new questions every round, which saves me hours of work every week.

Kwizaa, built on top of The Trivia API, provides a way to run automated trivia leagues - Quizzes drop on a schedule and results post to Discord or email.

Will
Creator, kwizaa.com

Translations

Questions are translated into Spanish, French, German, Dutch, Turkish, Hindi, Russian and Portuguese when they are approved. An LLM writes the translations.

Available with Complete subscription
  • Add language=es (or fr, de, nl, tr, hi, ru, pt) to a questions request
  • Text input answers can be validated in the same language
arts and literatureSpanish (es)

question.text

¿A qué movimiento artístico pertenece la pintura 'Gótico americano' de Grant Wood?

Modernismo
Puntillismo
Primitivismo
Ukiyo-e

Image questions

1,094 questions where the four options are photos instead of text. Each option includes the image at several sizes, plus the author and source you need for attribution.

Available with Complete subscription

People

Which of these is a picture of Phil Collins?

Places

Which of these pictures shows New York's Grand Central Station?

Flags, food and maps

Which of these is the flag of Thailand?

film and tvhardImage

Which of these actresses is Sharon Stone?

Text input questions

Thousands of our questions have no multiple choice options. The player types an answer, you send it to POST /v2/question/:id/validate, and an LLM decides whether it is right. Each check costs 50 credits, and a key can make up to 300 a minute.

Available with Complete subscription
scienceText Input

Which planet has the most moons?

  • Typos, alternative names and grammatical variants are accepted, so "Mupet" counts for "Muppets"
  • Answers can be checked in English or any of the 8 translated languages
Available with Regular and Complete subscriptions

Sessions

Create a session for each player and pass its id when you ask for questions. The API records what that session has been sent and won't send it again.

  • GET /v2/session/:id returns how many questions the session has left
  • Add preview=true to look at questions without using them up
1

Create a session

POST /v2/session
{ "id": "abc123", "remainingQuestions": ... }
2

Request questions

GET /v2/questions?session=abc123

First request: 10 questions

Second request: 10 more, none from the first batch

quiz.js
const res = await fetch("https://the-trivia-api.com/v2/quiz", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": process.env.TRIVIA_API_KEY,
  },
  body: JSON.stringify({
    title: "Friday Trivia",
    questionIds: ["622a1c347cc59eab6f94fa49", "63adbd6704c68cc1e14b8e2b"],
  }),
});
const { id } = await res.json();

const quiz = await fetch(`https://the-trivia-api.com/v2/quiz/${id}`).then((r) => r.json());
Available with any subscription

Quizzes

A quiz is a title and a list of question IDs. You need a key to create one, but fetching it by id doesn't, so every player in a league or a leaderboard can load the same questions.

Value plans can keep 5 quizzes of up to 20 questions. Regular allows 100 quizzes and Complete 1,000, each with up to 100 questions.

Available with Complete subscription

Semantic Search
find questions by meaning

Let players search for questions using natural language. Semantic search understands intent and returns relevant questions even when the exact keywords don't match.

  • Find questions by meaning, not keywords
  • Handles synonyms and different phrasing
  • Topic-random questions via GET /v2/questions?query=...

Powered by embeddings + vector search.

semantic-search.js
// Search questions by meaning
const res = await fetch(
  'https://the-trivia-api.com/v2/questions/search',
  {
    method: 'POST',
    headers: {
      'content-type': 'application/json',
      'x-api-key': 'your-api-key'
    },
    body: JSON.stringify({
      mode: 'semantic',
      query: 'greek mythology'
    }),
  }
);

// Topic-random questions about a query
const topicRes = await fetch(
  'https://the-trivia-api.com/v2/questions?query=greek%20mythology&limit=10',
  {
    headers: {
      'x-api-key': 'your-api-key'
    }
  }
);

Frequently Asked Questions

Everything you need to know about The Trivia API

Ready to build something fun?

Start building with our free, public API. No account required.

License

Information about the Creative Commons license for The Trivia API.

The API and all data returned from it are licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Creative Commons License

This means that the API and the questions it returns are free for noncommercial use. If you have somewhere suitable in your app, then please credit the API somewhere discreet — we love having our hard work shared!

If you would like to use the API commercially, or would like enhanced functionality, this service is offered through a paid subscription.

Sign in

Sign in to access your API key and manage your account.

or continue with email