现在,您可以使用 Gemini 2.0 Flash Experimental 生成原生图片了!
了解详情
发送反馈
Gemini API 快速入门
本快速入门将向您介绍如何安装所选 SDK,然后发出您的第一个 Gemini API 请求。
Python
Node.js
REST
Go
安装 Gemini API 库
使用 Node.js v18+ ,使用以下 npm 命令 安装 GoogleGenerativeAI
软件包 :
npm install @google/generative-ai
提交第一个请求
在 Google AI Studio 中获取 Gemini API 密钥
使用 generateContent
方法向 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 ());
后续步骤
现在,您已发出第一个 API 请求,不妨探索以下指南,了解 Gemini 的运作方式:
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-02-28。
需要向我们提供更多信息?
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-02-28。"],[],[]]