The Gemini API lets you access the latest generative models from Google. This API reference provides detailed information for the classes and methods available in the Gemini API SDKs. Pick a language and follow the setup steps to get started building.
Install the Gemini API library
Using Node.js v18+, install the GoogleGenerativeAI
package
using the following npm command:
npm install @google/generative-ai
Make your first request
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
If you're just getting started, check out the following guides, which will help you understand the Gemini API programming model:
You might also want to check out the capabilities guides, which introduce different Gemini API features and provide code examples: