Use the
generateContent method
to send a request to the Gemini API.
const{GoogleGenerativeAI}=require("@google/generative-ai");constgenAI=newGoogleGenerativeAI("YOUR_API_KEY");constmodel=genAI.getGenerativeModel({model:"gemini-1.5-flash"});constprompt="Explain how AI works";constresult=awaitmodel.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:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-11 UTC."],[],[]]