Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dev0302/nextjs-project-1/llms.txt

Use this file to discover all available pages before exploring further.

This endpoint calls Google Gemini to produce three open-ended, audience-appropriate question suggestions that a visitor can send as anonymous messages on the platform. The questions are returned as a single pipe-delimited string, ready for the frontend to split and display as selectable prompts.

Method and URL

GET /api/suggest-messages
Authentication: None required.

Request Parameters

This endpoint accepts no query parameters, path parameters, or request body. Every call generates a fresh set of suggestions from the model.

How It Works

  1. The handler reads GOOGLE_API_KEY from the environment and initialises a GoogleGenAI client from @google/genai.
  2. It resolves the model name from process.env.GEMINI_MODEL, falling back to gemini-1.5-flash.
  3. A few-shot prompt is sent to ai.models.generateContent() requesting exactly three questions separated by ||.
  4. The response text is read from the response.text getter (a direct string property on the result object, not response.candidates[0]...).
  5. The raw text is trimmed and returned in the suggestions field.
  6. If the model returns no text (e.g., blocked by safety filters) the endpoint responds with 400.
  7. Any API-level exception (quota exceeded, invalid key, network error) is caught and returned as a 500 with the original error message.

The Prompt

The following prompt is sent verbatim to the model on every request:
const prompt = `Create a list of three open-ended and engaging questions formatted as a single string. 
        Each question should be separated by '||'. These questions are for an anonymous social messaging platform, 
        like Qooh.me, and should be suitable for a diverse audience. Avoid personal or sensitive topics. 
        For example: 'What's a hobby you've recently started?||If you could have dinner with any historical figure, who would it be?||What's a simple thing that makes you happy?'. 
        Do not include any introductory or concluding text. Output only the string.`;

Responses

200 — Success

Three AI-generated questions are returned as a ||-delimited string.
{
  "success": true,
  "suggestions": "What's a hobby you've recently started?||If you could have dinner with any historical figure, who would it be?||What's a simple thing that makes you happy?"
}

400 — No content from AI

The model returned an empty response, most likely because the safety filter blocked output.
{
  "success": false,
  "message": "AI returned no content. Check safety filters."
}

500 — Gemini API error

An error was thrown by the Gemini SDK, such as an invalid API key, exhausted quota, or a network failure.
{
  "success": false,
  "message": "API key not valid. Please pass a valid API key."
}

Response Fields

success
boolean
true when the model returned usable content; false on any error condition.
suggestions
string
Present only on a successful (200) response. Three questions joined by || with no leading or trailing whitespace. Split on || to obtain individual suggestion strings.Example value:
What's a hobby you've recently started?||If you could have dinner with any historical figure, who would it be?||What's a simple thing that makes you happy?

Example Request

curl "http://localhost:3000/api/suggest-messages"
Success response:
{
  "success": true,
  "suggestions": "What's a hobby you've recently started?||If you could have dinner with any historical figure, who would it be?||What's a simple thing that makes you happy?"
}

Parsing the Response

The frontend splits the suggestions string into an array before rendering each question as a clickable chip:
const suggestions = response.data.suggestions
  .split('||')
  .map(s => s.trim())
  .filter(Boolean);
This yields:
[
  "What's a hobby you've recently started?",
  "If you could have dinner with any historical figure, who would it be?",
  "What's a simple thing that makes you happy?"
]

Configuration

Environment variableRequiredDefaultDescription
GOOGLE_API_KEY✅ YesGoogle AI Studio API key passed to GoogleGenAI({ apiKey }).
GEMINI_MODELNogemini-1.5-flashGemini model name forwarded to ai.models.generateContent().
Requests will fail with a 500 error if GOOGLE_API_KEY is missing or invalid. Ensure the variable is set in your .env.local file and in your deployment environment before calling this endpoint.
Get a free GOOGLE_API_KEY at https://aistudio.google.com. The free tier is sufficient for development and moderate production traffic.

Build docs developers (and LLMs) love