{
  "openapi": "3.1.0",
  "info": {
    "title": "Trivia API",
    "version": "1.0.0",
    "description": "5,298 multiple-choice and true-or-false trivia questions in 24 categories and three difficulties.\n\nMultiple-choice and true/false trivia questions across ~24 categories and three difficulty levels. Pull random questions, filter by category/difficulty/type, or page through the full set. Powered by the Open Trivia Database (CC BY-SA 4.0).",
    "contact": {
      "name": "Data and APIs",
      "url": "https://dataandapis.com/contact"
    },
    "termsOfService": "https://dataandapis.com/terms-of-service",
    "license": {
      "name": "Data and APIs Terms of Service",
      "url": "https://dataandapis.com/terms-of-service"
    },
    "x-logo": {
      "url": "https://dataandapis.com/images/trivia.webp"
    }
  },
  "externalDocs": {
    "description": "Documentation, live tester and pricing",
    "url": "https://dataandapis.com/apis/trivia"
  },
  "servers": [
    {
      "url": "https://api-trivia.dataandapis.com"
    }
  ],
  "tags": [
    {
      "name": "Entertainment",
      "description": "Trivia API belongs to the Entertainment category of the Data and APIs catalog."
    }
  ],
  "paths": {
    "/v1/trivia/{id}": {
      "get": {
        "operationId": "getTriviaById",
        "summary": "Get Trivia By Id",
        "description": "Get Trivia By Id endpoint of the Trivia API. Costs 2 tokens per call.",
        "externalDocs": {
          "url": "https://dataandapis.com/apis/trivia/get-trivia-by-id"
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "142"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "id": 142,
                  "category": "Entertainment: Comics",
                  "type": "multiple",
                  "difficulty": "hard",
                  "question": "In the Batman comics, by what other name is the villain Dr. Jonathan Crane known?",
                  "correct_answer": "Scarecrow",
                  "incorrect_answers": [
                    "Bane",
                    "Calendar Man",
                    "Clayface"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Subscription past due; the response carries a payment_url"
          },
          "429": {
            "description": "Monthly token allowance exhausted"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/trivia/categories": {
      "get": {
        "operationId": "listCategories",
        "summary": "List Categories",
        "description": "List Categories endpoint of the Trivia API. Costs 2 tokens per call.",
        "externalDocs": {
          "url": "https://dataandapis.com/apis/trivia/list-categories"
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "count": 24,
                  "categories": [
                    {
                      "category": "Entertainment: Film",
                      "count": 251
                    },
                    {
                      "category": "General Knowledge",
                      "count": 469
                    },
                    {
                      "category": "Science & Nature",
                      "count": 215
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Subscription past due; the response carries a payment_url"
          },
          "429": {
            "description": "Monthly token allowance exhausted"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/trivia": {
      "get": {
        "operationId": "listTrivia",
        "summary": "List Trivia",
        "description": "List Trivia endpoint of the Trivia API. Costs 2 tokens per call.",
        "externalDocs": {
          "url": "https://dataandapis.com/apis/trivia/list-trivia"
        },
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "History"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "20"
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "1"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "total": 411,
                  "page": 1,
                  "limit": 20,
                  "count": 20,
                  "attribution": "Questions from the Open Trivia Database (opentdb.com), CC BY-SA 4.0",
                  "results": [
                    {
                      "id": 4082,
                      "category": "History",
                      "type": "multiple",
                      "difficulty": "medium",
                      "question": "When was the United States National Security Agency established?",
                      "correct_answer": "November 4, 1952",
                      "incorrect_answers": [
                        "July 26, 1908",
                        " July 1, 1973",
                        " November 25, 2002"
                      ]
                    },
                    {
                      "id": 4083,
                      "category": "History",
                      "type": "multiple",
                      "difficulty": "hard",
                      "question": "After the 1516 Battle of Marj Dabiq, the Ottoman Empire took control of Jerusalem from which sultanate?",
                      "correct_answer": "Mamluk",
                      "incorrect_answers": [
                        "Ayyubid",
                        "Ummayyad",
                        "Seljuq"
                      ]
                    },
                    "... 18 more questions omitted from this example"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Subscription past due; the response carries a payment_url"
          },
          "429": {
            "description": "Monthly token allowance exhausted"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/trivia/random": {
      "get": {
        "operationId": "randomTrivia",
        "summary": "Random Trivia",
        "description": "Random Trivia endpoint of the Trivia API. Costs 2 tokens per call.",
        "externalDocs": {
          "url": "https://dataandapis.com/apis/trivia/random-trivia"
        },
        "parameters": [
          {
            "name": "amount",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "1"
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "Entertainment: Film"
          },
          {
            "name": "difficulty",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "easy"
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "multiple"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "count": 1,
                  "results": [
                    {
                      "id": 142,
                      "category": "Entertainment: Comics",
                      "type": "multiple",
                      "difficulty": "hard",
                      "question": "In the Batman comics, by what other name is the villain Dr. Jonathan Crane known?",
                      "correct_answer": "Scarecrow",
                      "incorrect_answers": [
                        "Bane",
                        "Calendar Man",
                        "Clayface"
                      ]
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Subscription past due; the response carries a payment_url"
          },
          "429": {
            "description": "Monthly token allowance exhausted"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Create a free key at https://dataandapis.com/sign-up. 500 tokens a month on the Free plan; this API costs 2 tokens per call."
      }
    }
  },
  "security": [
    {
      "ApiKey": []
    }
  ]
}