Gemini API quickstart

This quickstart shows you how to install your SDK of choice and then make your first Gemini API request.

Install the Gemini API library

Using GoogleGenerativeAI package using the following npm command:

npm install @google/generative-ai

Make your first request

Get a Gemini API key in Google AI Studio

Use the generateContent method to send a request to the Gemini API.

const { GoogleGenerativeAI } = require("@google/generative-ai");

const genAI = new GoogleGenerativeAI("YOUR_API_KEY");
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const prompt = "Explain how AI works";

const result = await model.generateContent(prompt);
console.log(result.response.text());

What's next

Now that you made your first API request, you might want to explore the following guides which showcase Gemini in action: