Overview
The AI Tutor API provides conversational tutoring capabilities and generates various types of study materials including quizzes, flashcards, summaries, and practice questions.Chat with AI Tutor
POST /api/ai-tutor/chat
Send a message to the AI tutor and receive an intelligent response. The tutor can explain concepts, answer questions, and generate study materials.The chat session ID (optional)
The user’s message or question
Conversation history array. Each message should have
role (user/assistant) and content fields.Set to true to enable automatic generation of study materials (quizzes, flashcards, etc.)
User’s first name for personalized responses
The AI tutor’s response message
Same as message (for backwards compatibility)
Generated study material (quiz, flashcards, etc.) if requested
Session Management
GET /api/ai-tutor/sessions
Retrieve all AI tutor chat sessions for the authenticated user. ResponsePOST /api/ai-tutor/sessions
Create a new AI tutor chat session.Name for the new session (defaults to “New Chat”)
The created session object with id, session_name, created_at, and last_message_at
Session Messages
GET /api/ai-tutor/sessions/[sessionId]/messages
Retrieve all messages in a specific chat session. Path ParametersThe session ID
Generate Study Materials
POST /api/ai-tutor/generate
Generate specific types of study materials on demand.Type of content to generate:
quiz, flashcards, summary, or practiceThe topic for the study material
Optional session ID to associate the content with
The generated content structure varies by type:
- quiz: Array of question objects
- flashcards: Array of card objects with front/back
- summary: Text content with markdown formatting
- practice: Text content with practice questions
Analyze Quiz Results
POST /api/ai-tutor/analyze-quiz-results
Get personalized feedback and explanations for quiz results.The title of the completed quiz
The score as a percentage (0-100)
JSON string containing question-by-question breakdown with:
question: The question textuserAnswer: The student’s answercorrectAnswer: The correct answerisCorrect: Boolean indicating if answer was correct
Student’s first name for personalized feedback
Personalized feedback and explanations from the AI tutor
Detect Topic from Conversation
POST /api/ai-tutor/detect-topic
Analyze a conversation to detect the main study topic and validate if there’s sufficient information to create study materials.Array of conversation messages with
role and content fieldsOptional content type being requested
The detected topic (null if insufficient information)
Whether there’s enough context to create study materials
Whether the detected topic is a real educational subject
The content type (if provided in request)
Generate Session Name
POST /api/ai-tutor/generate-session-name
Generate a short, descriptive name for a chat session based on the first message.The first message in the session
A 2-4 word session title
Error Responses
All endpoints return standard error responses:400- Bad request (missing or invalid parameters)401- Unauthorized (authentication required)500- Internal server error