Quiz Generation API
Generate individual quiz questions using AI.
Single Generation
POST /api/generate-quiz
Content-Type: application/jsonRequest Body
json
{
"targetLanguage": "ja",
"proficiencyLevel": "N5",
"difficulty": "easy",
"questionType": "multiple-choice"
}| Field | Type | Description |
|---|---|---|
targetLanguage | "ja" | "zh-TW" | Target language |
proficiencyLevel | string | JLPT level (N5-N1) or TOCFL level (A1-C2) |
difficulty | "easy" | "medium" | "hard" | Difficulty within the level |
questionType | string | Type 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:
- Teacher has pro plan + credits → platform-managed Gemini
- Teacher has stored BYOK keys → teacher's preferred provider
- 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