diff --git a/.env.example b/.env.example index d441bbaf6..8c93fca2e 100644 --- a/.env.example +++ b/.env.example @@ -94,6 +94,11 @@ UPSTASH_REDIS_REST_TOKEN=your_upstash_redis_rest_token # console.groq.com → API Keys GROQ_API_KEY=your_groq_api_key +# ------------------------------------------------------- +# Gemini API Key (optional — enables the /api/ai/roast route) +# aistudio.google.com → Get API key +GEMINI_API_KEY=your_gemini_api_key + # ------------------------------------------------------- # Leaderboard Configuration # Controls concurrent user fetches during leaderboard builds diff --git a/src/app/api/ai/roast/route.ts b/src/app/api/ai/roast/route.ts index 2eb468a8c..a73950276 100644 --- a/src/app/api/ai/roast/route.ts +++ b/src/app/api/ai/roast/route.ts @@ -1,10 +1,19 @@ import { NextResponse } from 'next/server'; import { GoogleGenerativeAI } from '@google/generative-ai'; +const GEMINI_API_KEY = process.env.GEMINI_API_KEY || ''; + // Initialize the Google Generative AI SDK -const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ''); +const genAI = new GoogleGenerativeAI(GEMINI_API_KEY); export async function POST(req: Request) { + if (!GEMINI_API_KEY) { + return NextResponse.json( + { error: 'Gemini API key is not configured' }, + { status: 500 } + ); + } + try { const body = await req.json(); const { mode, stats } = body;