I put together a small Flask example that turns any article, blog post, documentation page, or training note into a multiple-choice quiz using Telnyx AI Inference.
Code:
https://github.com/team-telnyx/telnyx-code-examples/tree/main/quiz-generator-python
The idea is simple: send the source text to an LLM, ask for structured JSON, and return a quiz your app can render, store, or export.
What it generates
The app returns:
- a quiz title
- a short description
- multiple-choice questions
- A/B/C/D choices
- one correct answer per question
- explanations for the answer key
The main endpoint is:
POST /quiz/generate
Example request:
curl -X POST http://localhost:5000/quiz/generate \
-H "Content-Type: application/json" \
-d '{
"text": "The Telnyx Call Control API allows developers to programmatically control phone calls. You can answer, hangup, transfer, bridge, and record calls. The API is event-driven, meaning you receive webhooks when call events happen.",
"num_questions": 5,
"difficulty": "medium"
}'
Example response shape:
{
"id": "quiz-1750280400",
"title": "Telnyx Call Control API Fundamentals",
"description": "Test your understanding of the Telnyx Call Control API.",
"difficulty": "medium",
"questions": [
{
"id": 1,
"question": "What setup is required to receive event notifications?",
"choices": {
"A": "Assign a number to a Call Control Application",
"B": "Enable SMS",
"C": "Install a softphone",
"D": "Register with SIP"
},
"correct_answer": "A",
"explanation": "You need a phone number assigned to a Call Control Application with a webhook URL."
}
]
}
How it works
The app calls:
POST /v2/ai/chat/completions
The default model is:
moonshotai/Kimi-K2.6
In .env:
TELNYX_API_KEY=your_telnyx_api_key
AI_MODEL=moonshotai/Kimi-K2.6
HOST=127.0.0.1
The prompt asks the model to return JSON only, with 4 choices per question and short explanations.
Routes included
The sample includes:
POST /quiz/generateGET /quizzesGET /quizzes/<id>GET /quizzes/<id>/answersGET /health
I like the separate answer-key route because it maps nicely to real learning apps. The student view and instructor view usually need different fields.
Production ideas
The example stores quizzes in memory so the core flow is easy to see.
For production, I would add:
- persistent storage
- authentication
- review workflows
- long-document chunking
- exports to JSON, CSV, or LMS formats
- support for true/false or short-answer questions
- stronger JSON validation
This is a starter pattern, but it is a useful one: the LLM is not just returning prose. It is generating structured app data.
Resources:
- Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/quiz-generator-python
- Telnyx AI Inference docs: https://developers.telnyx.com/docs/inference
- Chat Completions API: https://developers.telnyx.com/api/inference/chat-completions
- Telnyx AI skills and toolkits: https://github.com/team-telnyx/ai
Top comments (0)