Skip to content

Quiz Generation API

Generate individual quiz questions using AI.

Single Generation

POST /api/generate-quiz
Content-Type: application/json

Request Body

json
{
  "targetLanguage": "ja",
  "proficiencyLevel": "N5",
  "difficulty": "easy",
  "questionType": "multiple-choice"
}
FieldTypeDescription
targetLanguage"ja" | "zh-TW"Target language
proficiencyLevelstringJLPT level (N5-N1) or TOCFL level (A1-C2)
difficulty"easy" | "medium" | "hard"Difficulty within the level
questionTypestringType of quiz question

Response

json
{
  "content": {
    "question": "次の文の( )に入る言葉はどれですか。",
    "stem": "私は毎日学校に( )。",
    "options": ["行きます", "食べます", "飲みます", "読みます"],
    "answer": 0,
    "explanation": "..."
  }
}

AI Provider Resolution

The API uses the AI Gateway to select the provider:

  1. Teacher has pro plan + credits → platform-managed Gemini
  2. Teacher has stored BYOK keys → teacher's preferred provider
  3. Fallback order: Gemini → OpenAI → Anthropic → OpenRouter

Vocab Sampling

Each generation request samples vocabulary and grammar from official JLPT/TOCFL lists to ensure the AI stays within the target level scope:

  • 20 vocabulary entries (stratified by POS)
  • 10 grammar points (random sample)
  • Difficulty affects sampling window: easy = top 50%, medium = top 75%, hard = full range

TechTrans Lab