Back
Quizb AI Question Generation API Documentation
author: Allon
2024/11/1 09:43:43

Quizb AI Question Generation API Documentation

Note: Default API limit is 10 QPS

Request Authentication

Each API request to Quizb AI requires authentication. The user needs to generate an access token by using a Secret Key (SK) with a specific method and include it in the request header under the Authorization field, formatted as follows:

Authorization: <access_token>

1、Obtaining an access_token

Preparation: Obtain the Secret Key (SK)

You need to contact customer service to obtain your Secret Key.

Note: The Secret Key (SK) is highly sensitive and private information. Any leakage could lead to severe consequences, so do not place it directly in client applications.

Get the question generation authorization access_token The generated access_token is valid for a single use and will expire after use.

GET https://aiapi.quizb.ai/api/v2/get-token?secret=sk&count=4&grant_type=gen

Parameter Description:

  • secret: Authentication key, i.e., SK
  • count: Number of questions to generate
  • grant_type: Authorization type, options: gen for question generation, query for query generation interface

Response Example Successful Response:

{
    "access_token":"ACCESS_TOKEN",
    "expires_in":300
}
ParameterDescription
access_tokenRetrieved authentication token
expires_inToken expiration time, in seconds

Error Response:

{"status": "error","errmsg":"invalid appid"}
errmsg ValueDescription
question_limitQuestion generation limit; account has insufficient question quota for the requested count

2、Knowledge Point Generation Endpoint

Request URL:

 https://aiapi.quizb.ai/api/v2/gen-question-by-desc/multiple-types

Example Listener:

let aiServer = new SSE(url, {
    headers: {
        Authorization: 'access_token',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    payload: 'description="Please generate a multiple-choice question"&language=zh-cn&questions=[{"name":"Multiple Choice","questionType":"multiplechoise","count":1,"dfficulty":"easy"}]',
    method: 'POST'
})

//Streamed response
aiServer.addEventListener('message', function (e) {
    let data = decodeURIComponent(escape(atob(e.data)))
    console.log(data)
})

// End of stream
aiServer.addEventListener('generate_count', function (e) {
    
})

//Error message
aiServer.addEventListener('error', function (e) {
    let error = JSON.parse((e.data))
    console.log(error)
})

Authorization

Authorization: <access_token>

Payload Parameter Description:

ParameterRequiredDescription
descriptionYesKnowledge point description
languageYesLanguage for generated questions. Options: zh-cn (Simplified Chinese), zh-hk (Traditional Chinese), en (English), ja (Japanese), fr (French), de (German), ru (Russian)
questionsYesJSON array, e.g., {"questionType":"multiplechoise","count":1,"dfficulty":"easy"}

questions Parameter Description: Multiple question types can be passed

ParameterRequiredDescription
questionTypeYesOptions: multiplechoise (multiple choice), multipleresponse (multiple response), truefalse (true/false), fillblank (fill in the blank), essay (essay question)
countYesNumber of questions to generate
dfficultyYesDifficulty level of questions; options: easy, medium, hard

Response: Streamed response

3、Content Generation Endpoint

Request URL:

 https://aiapi.quizb.ai/api/v2/gen-question-by-content-direct/multiple-types

Example Listener:

let aiServer = new SSE(url, {
    headers: {
        Authorization: 'access_token',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    payload: 'content="Please generate a multiple-choice question"&language=zh-cn&questions=[{"name":"Multiple Choice","questionType":"multiplechoise","count":1,"dfficulty":"easy"}]',
    method: 'POST'
})

// Streamed response
aiServer.addEventListener('message', function (e) {
    let data = decodeURIComponent(escape(atob(e.data)))
    console.log(data)
})

// End of stream
aiServer.addEventListener('generate_count', function (e) {
    
})

// Error message
aiServer.addEventListener('error', function (e) {
    let error = JSON.parse((e.data))
    console.log(error)
})

Authorization:

Authorization: <access_token>

Payload Parameter Description:

ParameterRequiredDescription
contentYesContent to generate questions from; maximum text length: 50,000 characters
languageYesLanguage for generated questions. Options: zh-cn (Simplified Chinese), zh-hk (Traditional Chinese), en (English), ja (Japanese), fr (French), de (German), ru (Russian)
questionsYesJSON array, e.g.,{"questionType":"multiplechoise","count":1,"dfficulty":"easy"}

questions Parameter Description: Multiple question types can be passed

ParameterRequiredDescription
questionTypeYesOptions: multiplechoise (multiple choice), multipleresponse (multiple response), truefalse (true/false), fillblank (fill in the blank), essay (essay question)
countYesNumber of questions to generate
dfficultyYesDifficulty level of questions; options: easy, medium, hard

Response: Streamed response

Open Platform
Tutorials
Previous article:
No More
Next article:
An article tells you how to use Quizb to solve problems