Back

Making requests

Use the official SDK to send a prompt and get a response. Run it on the server (an API route) so your key stays secret.

// app/api/ask/route.ts
import { GoogleGenAI } from "@google/genai"

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY })

export async function POST(request: Request) {
  const { question } = await request.json()

  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash",
    contents: question,
  })

  return Response.json({ answer: response.text })
}

Roadmap