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.
Writers’ block is the biggest enemy of anonymous messaging. AnonMessage solves it with a Suggest Messages button on every public profile page. One click calls the Google Gemini API and returns three ready-to-send, open-ended questions that senders can use as-is or as inspiration.
What It Does
When a visitor lands on a public profile page at /u/[username], they see a Suggest Messages button below the message input. Clicking it fires a GET /api/suggest-messages request. The server queries Gemini, and the three returned questions appear as clickable chips. Clicking any chip instantly populates the message input field.
How It Works
The route uses the @google/genai SDK. A single GoogleGenAI instance is initialised at module level using the GOOGLE_API_KEY environment variable:
// src/app/api/suggest-messages/route.ts
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY });
The GET handler reads the model name from the optional GEMINI_MODEL environment variable, falling back to gemini-1.5-flash, then calls ai.models.generateContent():
export async function GET(req: Request) {
try {
const modelName = process.env.GEMINI_MODEL || "gemini-1.5-flash";
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.`;
const response = await ai.models.generateContent({
model: modelName,
contents: [{ role: "user", parts: [{ text: prompt }] }],
});
const rawText = response.text;
if (!rawText) {
return NextResponse.json(
{ success: false, message: "AI returned no content. Check safety filters." },
{ status: 400 }
);
}
const cleanText = rawText.trim();
return NextResponse.json(
{ success: true, suggestions: cleanText },
{ status: 200 }
);
} catch (error: any) {
const errorMessage =
error.message || "An unexpected error occurred with the AI service.";
return NextResponse.json(
{ success: false, message: errorMessage },
{ status: 500 }
);
}
}
The Prompt
The prompt uses few-shot prompting — it gives Gemini a concrete example of the expected output format so the model reliably produces three questions separated by || with no surrounding text:
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.
Key constraints embedded in the prompt:
- Questions must be open-ended and engaging
- Suitable for a diverse, anonymous audience
- No personal or sensitive topics
- No intro or outro text — raw
||-delimited string only
The API returns a JSON object where suggestions is the raw ||-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?"
}
The frontend splits this string on || and trims each part to produce the array rendered as clickable chips:
// SendMessageProfile.tsx — parsing suggestions
const allSuggestions = response.data.suggestions
.split("||")
.map((s) => s.trim())
.filter(Boolean);
setSuggestions(allSuggestions);
Selecting a Suggestion
Each rendered suggestion chip has an onClick handler that calls onSelectSuggestion, which sets the message content state to the suggestion text and smoothly scrolls the page back to the top so the sender can review what they’re about to send:
// SendMessageProfile.tsx — selection handler
const onSelectSuggestion = (text: string) => {
setContent(text);
window.scrollTo({ top: 0, behavior: "smooth" });
};
The selected text appears in the main message input field and can be edited before sending.
Configuration
Two environment variables control the AI integration:
# Required — your Google AI Studio or Vertex AI API key
GOOGLE_API_KEY=your_api_key_here
# Optional — override the default model (defaults to gemini-1.5-flash)
GEMINI_MODEL=gemini-1.5-flash
You can get a free GOOGLE_API_KEY from
Google AI Studio in seconds — no
billing setup required for the free tier. gemini-1.5-flash is a fast,
cost-efficient model that works well for short text generation tasks like this
one. If you need higher quality output, set GEMINI_MODEL=gemini-1.5-pro in
your environment variables.