使用 Gemini API 构建应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
虽然您可以使用 App Prototyping agent 通过 Gemini API 自动创建新的应用原型,但您也可以通过点击一个按钮,使用 Gemini 开发者 API 启动空白画布。使用包含您所需的所有 Gemini API 基础设施的模板,开始在您的应用中使用 Google 的最新生成式 AI 模型。您只需添加您的 Gemini API 密钥,然后开始编写代码即可!
构建一个预加载了 Gemini API 的新应用
从模板信息中心访问 Firebase Studio Gemini API 模板,借助 AI 强大能力进行构建。
- 从 Firebase Studio 模板信息中心打开 Gemini API 的 Firebase Studio 模板。
- 选择适合您环境的语言和框架。Firebase Studio 中提供的 Gemini API 模板支持 JavaScript(使用 Vite 或 Genkit)和 Python(基于 Flask 的笔记本或 Web 应用),后续还将支持更多语言和框架。
- (可选)如果您想将 LangChain 框架添加到您的应用中,请选择使用 LangChain 选项。
- 工作区加载后,打开
main.js
或 main.py
文件,并使用 Google AI Studio 中的 Gemini API 密钥更新 API_KEY
变量。
- 在 Web 预览面板中测试基础应用,以查看 Gemini API 的操作,并相应地修改您的新 Gemini API 应用。
将 Gemini API 添加到现有应用
您还可以直接从 Firebase Studio 将 Gemini API 添加到现有应用中。
打开 Firebase Studio。
点击导航窗格中的 Firebase Studio 图标以打开 Firebase Studio 面板。
展开 Google 集成部分,然后点击添加 Gemini API。
按照提示对您的账号进行身份验证,并向您的应用添加 Gemini API 密钥。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-22。
[null,null,["最后更新时间 (UTC):2025-08-22。"],[],[],null,["While you can use [the App Prototyping agent](/docs/studio/get-started-ai)\nto automatically create a new app prototype with the Gemini API, you can\nalso launch a blank canvas with the\n[Gemini Developer API](https://ai.google.dev/) through one click of\na button. Start using the latest generative AI models from Google in your\napp with a template that includes all the Gemini API infrastructure you\nneed. All you need to do is add your\n[Gemini API key](https://ai.google.dev/tutorials/setup) and get coding!\n\nBuild a new app with the Gemini API pre-loaded\n\nAccess the Firebase Studio Gemini API template from the\ntemplates dashboard and build with the power of AI.\n\n1. Open the [Firebase Studio template for the Gemini API](https://studio.firebase.google.com//new/gemini) from the Firebase Studio template dashboard.\n2. Select the language and framework for your environment. The Gemini API template in Firebase Studio is available in JavaScript (with Vite or Genkit) and Python (notebook or web app with Flask), with more languages and frameworks coming soon.\n3. *(Optional)* If you want to add the [LangChain](https://www.langchain.com/) framework to your app, select the **Use LangChain** option.\n4. When your workspace loads, open the `main.js` or `main.py` file and update the `API_KEY` variable with your Gemini API key from [Google AI Studio](https://aistudio.google.com/app/apikey).\n5. Test the base app in the web preview panel to watch the Gemini API in action, and modify your new Gemini API app accordingly.\n\nAdd the Gemini API to an existing app\n\nYou can also add the Gemini API to your existing app directly from\nFirebase Studio.\n\n1. Open [Firebase Studio](https://studio.firebase.google.com/).\n\n2. Click the Firebase Studio icon from the navigation pane to open the\n Firebase Studio panel.\n\n3. Expand the **Google Integrations** section and click **Add Gemini API**.\n\n4. Follow the prompts to authenticate your account and add a Gemini API key\n to your app."]]