fromgoogleimportgenaiclient=genai.Client(api_key="YOUR_API_KEY")response=client.models.generate_content(model="gemini-2.0-flash",contents="Explain how AI works",)print(response.text)
Node.js
const{GoogleGenerativeAI}=require("@google/generative-ai");constgenAI=newGoogleGenerativeAI("YOUR_API_KEY");constmodel=genAI.getGenerativeModel({model:"gemini-2.0-flash"});constprompt="Explain how AI works";constresult=awaitmodel.generateContent(prompt);console.log(result.response.text());
REST
curl"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=YOUR_API_KEY"\-H'Content-Type: application/json'\-XPOST\-d'{ "contents": [ { "parts": [ { "text": "Explain how AI works in a few words" } ] } ] }'