Nhận khoá API Gemini và tạo yêu cầu API đầu tiên trong vài phút.
Python
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"}] }] }'
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-03-19 UTC."],[],[]]