The Trivia API Sessions API

The Sessions API from The Trivia API — 4 operation(s) for sessions.

GitHub OpenAPI

Operations 4

POST /session Create a new session #
GET /session/{id} Get a session by id #
GET /session/{id}/preview-questions Get a session by id #
POST /session/{id}/questions Add used questions to a session #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/the-trivia-api-com:the-trivia-api-com-sessions-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

the-trivia-api-com-sessions-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: Trivia Sessions API
  version: 1.0.0
  description: '# Introduction #


    The Trivia API is a REST API used to request multiple choice trivia questions. No API key is required to request questions, but an API key can be used to gain access to further functionality, such as searching, quizzes, and sessions.


    An API key is also required if you would like to use data from the API commercially.'
servers:
- url: https://the-trivia-api.com/v2
tags:
- name: Sessions
paths:
  /session:
    post:
      operationId: createSession
      summary: Create a new session
      description: (Requires Regular subscription)
      tags:
      - Sessions
      security:
      - ApiKeyAuth: []
      responses:
        '200':
          description: The session id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Session'
        '400':
          description: Invalid request
  /session/{id}:
    get:
      operationId: getSession
      summary: Get a session by id
      description: (Requires Regular subscription)
      tags:
      - Sessions
      security:
      - ApiKeyAuth: []
      parameters:
      - in: path
        name: id
        schema:
          type: string
          description: The id of the session to return
          example: '1234567890'
      responses:
        '200':
          description: A session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Session'
        '400':
          description: Invalid request
        '404':
          description: No session found with the given id
  /session/{id}/preview-questions:
    get:
      operationId: previewSessionQuestions
      summary: Get a session by id
      description: Preview a session's questions. This is used to get a set of new questions for a session without marking them as 'used'. Questions generated in this way could be generated again on the same session unless they are manually marked as 'used'.
      tags:
      - Sessions
      security:
      - ApiKeyAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
        description: The id of the session to preview questions for
        example: '1234567890'
      - $ref: '#/components/parameters/limitQueryParam'
      - $ref: '#/components/parameters/categoriesQueryParam'
      - $ref: '#/components/parameters/difficultiesQueryParam'
      - $ref: '#/components/parameters/regionQueryParam'
      - $ref: '#/components/parameters/tagsQueryParam'
      - $ref: '#/components/parameters/typesQueryParam'
      - $ref: '#/components/parameters/sessionQueryParam'
      responses:
        '200':
          description: A list of questions
          content:
            application/json:
              schema:
                type: array
                items:
                  anyOf:
                  - $ref: '#/components/schemas/TextChoiceQuestion'
                  - $ref: '#/components/schemas/ImageChoiceQuestion'
  /session/{id}/questions:
    post:
      operationId: markQuestionsAsUsed
      summary: Add used questions to a session
      description: 'Is used to manually add questions to a session''s array of ''used'' questions, so that they won''t be asked for this session.


        Ordinarily, questions are automatically added to this array, but sometimes (e.g.) when previewing questions, you may want to manually add questions.'
      tags:
      - Sessions
      security:
      - ApiKeyAuth: []
      parameters:
      - in: path
        name: id
        schema:
          type: string
        description: The id of the session to add questions to
        example: '1234567890'
      requestBody:
        description: A list of questions to add to the session
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                questionIds:
                  type: array
                  items:
                    type: string
                  description: The ids of the questions to add to the session
                  example:
                  - '1234567890'
                  - 0987654321
      responses:
        '204':
          description: Questions added to session
components:
  schemas:
    ImageOption:
      type: object
      properties:
        url:
          type: string
          description: Full URL of the image
          example: https://example.com/images/12345/an-interesting-image.jpg
        height:
          type: number
          description: Height of the image in pixels
          example: 400
        width:
          type: number
          description: Width of the image in pixels
          example: 300
        size:
          type: number
          description: Size of the image in bytes
          example: 256612
        author:
          type: object
          properties:
            name:
              type: string
              description: The author's name
              example: John Smith
            url:
              type:
              - string
              - 'null'
              description: URL to the author's website or social media profile
              example: https://john-smith.example.com
        source:
          type: object
          properties:
            url:
              type:
              - string
              - 'null'
              description: Where the image is originally credited
              example: https://example.com/some-source-gallery
        description:
          type: string
          description: Description of what the image is showing, can be used as alt text.
          example: A picture of a cat
        license:
          type: object
          properties:
            url:
              type:
              - string
              - 'null'
              description: URL to the license of the image
              example: https://creativecommons.org/licenses/by/4.0/
            name:
              type: string
              description: Name of the license
              example: Creative Commons Attribution 4.0 International
      required:
      - url
      - height
      - width
      - size
      - author
      - source
      - description
      - license
    TextChoiceQuestion:
      allOf:
      - $ref: '#/components/schemas/BaseQuestion'
      - type: object
        properties:
          question:
            type: object
            properties:
              text:
                type: string
                description: String formulation of the questions
                example: What is the capital of France?
            required:
            - text
          correctAnswer:
            type: string
            description: The correct answer
            example: Paris
          incorrectAnswers:
            type: array
            description: Array of incorrect answers
            example:
            - London
            - Berlin
            - Brussels
            items:
              type: string
              description: An incorrect answer
          hint:
            type: string
            description: 'A one-sentence clue to show before the player answers, if they ask for one. It points towards the answer without giving it away. Optional: not every question has one yet, and it is currently only returned for English requests.'
            example: Think of a city famous for a tower built for the 1889 World's Fair.
          explanation:
            type: string
            description: 'One or two sentences to show after the player answers, saying why the correct answer is right or adding a related fact. It names the correct answer, so do not show it before the player has answered. Optional: not every question has one yet, and it is currently only returned for English requests.'
            example: Paris is France's capital and largest city; London, Berlin and Brussels are the capitals of the UK, Germany and Belgium.
          type:
            type: string
            enum:
            - text_choice
            example: text_choice
        required:
        - question
        - correctAnswer
        - incorrectAnswers
        - type
    BaseQuestion:
      type: object
      properties:
        category:
          type: string
          $ref: '#/components/schemas/Category'
        id:
          type: string
          description: Unique identifier for the question
          example: 5f9f1b9b0e1b9c0017a5f1a5
        tags:
          type: array
          description: Secondary categories for the question. More freeform than category (can take any value), and can have multiple tags per question.
          items:
            type: string
          example:
          - france
          - geography
          - capital_cities
          - cities
        difficulty:
          type: string
          enum:
          - easy
          - medium
          - hard
          description: How difficult the question is perceived to be by the moderators of the API.
        regions:
          type: array
          items:
            type: string
          description: 'If the question is regional (i.e. only reasonable to ask people from a particular set of countries), then the ISO 3166-1 alpha-2 country codes for those countries are specified here.


            For most questions, this will be an empty array, meaning that the question is suitable to ask to people from anywhere in the world.'
        isNiche:
          type: boolean
          description: Will be true if the question is a niche question, i.e. if it is considered too difficult to return unless the tag is specifically requested.
      required:
      - category
      - id
      - tags
      - isNiche
      - difficulty
    Session:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the session
        totalQuestions:
          type: number
          description: Total questions available to the session
        remainingQuestions:
          type: number
          description: Remaining questions left in the session
        createdAt:
          type: string
          format: date-time
          description: Timestamp that the session was created
        updatedAt:
          type: string
          format: date-time
          description: Timestamp that the session was last updated
      required:
      - id
      - totalQuestions
      - remainingQuestions
      - createdAt
      - updatedAt
    Category:
      type: string
      enum:
      - music
      - sport_and_leisure
      - film_and_tv
      - arts_and_literature
      - history
      - society_and_culture
      - science
      - geography
      - food_and_drink
      - general_knowledge
    ImageChoiceQuestion:
      allOf:
      - $ref: '#/components/schemas/BaseQuestion'
      - type: object
        properties:
          question:
            type: object
            properties:
              text:
                type: string
                description: String formulation of the questions
                example: Which of these photos shows The Eiffel Tower?
            required:
            - text
          correctAnswer:
            type: array
            items:
              $ref: '#/components/schemas/ImageOption'
          incorrectAnswers:
            type: array
            items:
              type: array
              items:
                $ref: '#/components/schemas/ImageOption'
          type:
            type: string
            enum:
            - image_choice
            example: image_choice
        required:
        - question
        - correctAnswer
        - incorrectAnswers
        - type
  parameters:
    tagsQueryParam:
      in: query
      name: tags
      schema:
        type: string
      description: Comma separated list of tags to return questions from. If not provided, all tags will be used.
      example: science,film_and_tv
    regionQueryParam:
      in: query
      name: region
      schema:
        type: string
      description: 'Some questions are regional, i.e. only reasonable to ask people from a particular set of countries.


        If not provided, all questions will be suitable to ask to people from anywhere in the world. If provided, you could also receive questions that are only suitable to ask to ask to people from the specified region, but not to people from all regions.


        The region should be provided as an ISO 3166-1 alpha-2 country code.'
      example: GB
    limitQueryParam:
      in: query
      name: limit
      description: 'The number of questions to return. Must be a whole number of at least 1, otherwise the request returns a 400. A value above the maximum is capped to it: the maximum is 50 without an API key, or the number of questions per request that your subscription allows.'
      schema:
        type: integer
        minimum: 1
        default: 10
      example: 5
    difficultiesQueryParam:
      in: query
      name: difficulties
      description: Comma separated list of difficulties of questions to return. If not provided, all difficulties will be used.
      schema:
        type: string
        default: easy,medium,hard
      example: medium,hard
    sessionQueryParam:
      in: query
      name: session
      schema:
        type: string
      description: The session id to return questions from. If not provided, questions will not come from a session, so could be duplicates of questions received on previous requests.
      example: '1234567890'
    typesQueryParam:
      in: query
      name: types
      schema:
        type: string
        default: text_choice
      description: 'Comma separated list of the types of questions to return. If not provided, only text choice questions will be used.

        A Complete subscription is required to receive image questions.'
      example: text_choice,image_choice
    categoriesQueryParam:
      in: query
      name: categories
      description: Comma separated list of categories to return questions from. If not provided, all categories will be used. An unrecognised category returns a 400.
      schema:
        type: string
      example: science,film_and_tv
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key