Skip to main content
The /process_question endpoint processes quiz questions from either text input or uploaded images. It uses Google’s Gemini AI to analyze the question and provide accurate answers.

Endpoint

POST /process_question

Authentication

Requires a valid Gemini API key provided via:
  • Recommended: X-API-Key header
  • Alternative: apiKey in request body
See Authentication for details.

Request parameters

Headers

X-API-Key
string
required
Your Google Gemini API key (recommended method)
Content-Type
string
  • application/json for text questions
  • multipart/form-data for image uploads

Body parameters

question
string
The quiz question text (for text-based questions)
image
file
Image file containing the quiz question (for image-based questions)Constraints:
  • Maximum size: 5MB
  • Supported formats: PNG, JPEG
  • MIME type validation enforced
apiKey
string
Your Gemini API key (alternative to header, not recommended)
Provide either question (text) or image (file), not both.

Response

answers
array
Array of answer strings extracted from the AI responseEach answer is:
  • Trimmed of whitespace
  • Filtered to remove empty lines
  • Cleaned of markdown formatting (lines starting with * or #)

Examples

Text question

curl -X POST http://localhost:3000/process_question \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_GEMINI_API_KEY" \
  -d '{"question": "What is 2 + 2?"}'

Image question

curl -X POST http://localhost:3000/process_question \
  -H "X-API-Key: YOUR_GEMINI_API_KEY" \
  -F "[email protected]"

Response format

Success Response (200)
{
  "answers": [
    "Paris",
    "The capital of France is Paris"
  ]
}

Error responses

Missing required data
{
  "error": "No question or image provided"
}
Missing API key
{
  "error": "API key is required"
}
Invalid file type (from multer)
{
  "error": "Only image files are allowed!"
}
Processing failure
{
  "error": "Failed to process question",
  "message": "Detailed error message from AI service"
}

Implementation details

Text processing (server.js:174-194)

Text questions are processed using this optimized prompt:
const prompt = `Quiz question: "${question}"
Provide ONLY the correct answer(s). If there are choices, only pick from them. Be extremely concise.`;

Image processing (server.js:197-231)

Images are:
  1. Converted to base64 format
  2. Sent to Gemini’s vision model with MIME type (PNG or JPEG)
  3. Processed with a concise prompt for faster responses
  4. Automatically deleted after processing

Answer formatting (server.js:297-299)

The API cleans AI responses by:
  1. Splitting on newlines
  2. Trimming whitespace
  3. Filtering empty lines
  4. Removing markdown formatting (lines starting with * or #)

Rate limiting

This endpoint is subject to:
  • Global rate limit: 100 requests per 15 minutes per IP
  • Internal quota: 50 API calls per minute
See Rate Limiting for handling strategies.

Best practices

For better performance, use gemini-2.0-flash-lite (default model) instead of gemini-2.0-flash unless you need higher accuracy.
Uploaded images are temporarily stored and then deleted. Ensure your images don’t contain sensitive information beyond the quiz question.
The API uses automatic retry logic with exponential backoff for transient errors. See Error Handling for details.

Build docs developers (and LLMs) love