Voice AI

Build an AI Quiz Generator with Telnyx AI Inference

One of the most useful things you can do with an LLM is turn existing content into something interactive.

A blog post becomes a study guide.

Documentation becomes onboarding material.

A training note becomes a quick knowledge check.

That is the idea behind this example: a small Flask app that turns any article or text into a multiple-choice quiz with an answer key and explanations using Telnyx AI Inference.

Code:

The app is intentionally simple, but the pattern is useful: send source text to an LLM, ask for structured JSON, and return something your application can store, render, export, or grade.

What the app does

The core endpoint is:

POST /quiz/generate

You send it text, a question count, and a difficulty:

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"
  }'

The response is structured JSON:

{
  "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."
    }
  ]
}

That structure matters.

If the model returned a paragraph, a person could read it. But if the model returns JSON, your app can render it as a quiz UI, store it in a database, export it to a learning platform, or show the answer key separately.

Using Telnyx AI Inference

The app calls Telnyx AI Inference through:

POST /v2/ai/chat/completions

The default model is:

moonshotai/Kimi-K2.6

You configure it in .env:

TELNYX_API_KEY=your_telnyx_api_key
AI_MODEL=moonshotai/Kimi-K2.6
HOST=127.0.0.1

The helper function sends the system prompt and user prompt to Telnyx, strips markdown code fences if the model adds them, and parses the result as JSON.

The generation prompt asks for:

  • a short quiz title
  • a one-sentence description
  • multiple-choice questions
  • four choices per question
  • one correct answer
  • short explanations
  • plausible distractors

That last point is important. A useful quiz should test understanding, not just ask the model to copy sentences from the source text.

API routes included

The sample includes a few routes around the generated quiz:

POST /quiz/generate
GET /quizzes
GET /quizzes/<id>
GET /quizzes/<id>/answers
GET /health

GET /quizzes returns a lightweight list of generated quizzes.

GET /quizzes/<id> returns the full quiz.

GET /quizzes/<id>/answers returns just the answer key and explanations.

That separation is useful if you are building a real app. The learner view and instructor view probably should not expose the same fields.

Where this can be useful

This pattern is not limited to education products.

You could use it for:

  • documentation comprehension checks
  • developer onboarding
  • support team enablement
  • internal training modules
  • course content generation
  • certification practice questions
  • workshop follow-up quizzes
  • product release education

For example, a docs team could turn a new API guide into a quick internal quiz before a launch. A support team could turn troubleshooting docs into weekly knowledge checks. A developer advocate could turn a tutorial into a quiz for a workshop.

Production considerations

The example keeps generated quizzes in memory so the workflow is easy to follow.

For production, I would add:

  • persistent storage for quizzes
  • authentication
  • author/reviewer workflows
  • export formats like JSON, CSV, or SCORM
  • chunking for long documents
  • support for more question types
  • moderation or review of generated questions
  • stronger validation for the returned JSON
  • controls for difficulty and topic coverage

I would also review generated quizzes before using them in high-stakes settings. LLMs are useful for drafting questions, but humans still need to decide whether the questions are accurate, fair, and aligned with the learning goal.

Why I like this example

It is a good starter pattern for AI app builders because it shows a practical structured generation flow.

The model is not just chatting.

It is producing application data.

That is where AI starts to feel less like a text box and more like part of a product workflow.

Resources

  • Code:
  • Telnyx AI Inference docs:
  • Chat Completions API:
  • Available models:
  • Telnyx AI skills and toolkits:
  • Telnyx Portal:

Ready to build with low-latency voice AI?

Join developers building the future of real-time conversations