firebase-ai-logic by firebase/agent-skills
npx skills add https://github.com/firebase/agent-skills --skill firebase-ai-logicFirebase AI Logic 是 Firebase 的一款产品,允许开发者使用客户端 SDK 为其移动和 Web 应用添加生成式 AI。您可以直接从您的应用中调用 Gemini 模型,而无需管理专用后端。Firebase AI Logic,之前被称为 "Vertex AI for Firebase",代表了谷歌为移动和 Web 开发者打造的 AI 集成平台的演进。
它支持两种 Gemini API 提供商:
默认使用 Gemini Developer API,仅在应用需要时才使用 Vertex AI Gemini API。
该库是标准 Firebase Web SDK 的一部分。
npm install -g firebase@latest
如果您在 firebase 目录中(包含 firebase.json 文件),可以使用此命令查看当前选定的项目,标记为 "current":
npx -y firebase-tools@latest projects:list
确保当前项目至少关联了一个应用
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
npx -y firebase-tools@latest apps:list使用 init 命令初始化 AI logic SDK
npx -y firebase-tools@latest init # 选择 AI logic
这将在 Firebase 控制台中自动启用 Gemini Developer API。
更多信息请参阅 Firebase AI Logic 入门指南
Firebase AI Logic 允许 Gemini 模型直接从您的应用中分析图像文件。这支持诸如创建标题、回答关于图像的问题、检测对象和分类图像等功能。除了图像,Gemini 还可以通过以内联数据形式传递其他媒体类型(如音频、视频和 PDF)及其 MIME 类型来分析它们。对于大于 20 兆字节的文件(作为内联数据可能导致 HTTP 413 错误),请将它们存储在 Firebase Cloud Storage 中,并将其 URL 传递给 Gemini Developer API。
使用 startChat 自动维护历史记录。
为了通过显示部分结果(如打字效果)来改善用户体验,请使用 generateContentStream 而不是 generateContent,以便更快地显示结果。
支持的平台和框架包括用于 Android 的 Kotlin 和 Java,用于 iOS 的 Swift,用于 Web 应用的 JavaScript,用于 Flutter 的 Dart,以及用于 Unity 的 C Sharp。
为响应强制执行特定的 JSON 模式。
适用于 Web 应用的混合设备端推理,Firebase Javascript SDK 会自动检查 Gemini Nano 的可用性(安装后),并在设备端或云端托管的提示执行之间切换。这需要在 Chrome 浏览器中启用模型使用的特定步骤,更多信息请参阅混合设备端推理文档。
推荐:开发者必须启用 Firebase App Check,以防止未经授权的客户端使用其 API 配额。请参阅 App-check recaptcha enterprise。
请注意,您无需硬编码模型名称(例如 gemini-flash-lite-latest)。使用 Firebase Remote Config 可以动态更新模型版本,而无需部署新的客户端代码。请参阅远程更改模型名称
| 语言、框架、平台 | Gemini API 提供商 | 上下文 URL |
|---|---|---|
| Web 模块化 API | Gemini Developer API (Developer API) | firebase://docs/ai-logic/get-started |
除非文档或用户请求其他模型,否则始终使用最新版本的 Gemini (gemini-flash-latest)。请勿使用 gemini-1.5-flash
每周安装量
2.4K
代码仓库
GitHub Stars
182
首次出现
2026年2月17日
安全审计
安装于
gemini-cli2.3K
codex1.5K
opencode1.5K
github-copilot1.5K
amp1.5K
kimi-cli1.5K
Firebase AI Logic is a product of Firebase that allows developers to add gen AI to their mobile and web apps using client-side SDKs. You can call Gemini models directly from your app without managing a dedicated backend. Firebase AI Logic, which was previously known as "Vertex AI for Firebase", represents the evolution of Google's AI integration platform for mobile and web developers.
It supports the two Gemini API providers:
Use the Gemini Developer API as a default, and only Vertex AI Gemini API if the application requires it.
The library is part of the standard Firebase Web SDK.
npm install -g firebase@latest
If you're in a firebase directory (with a firebase.json) the currently selected project will be marked with "current" using this command:
npx -y firebase-tools@latest projects:list
Ensure there's at least one app associated with the current project
npx -y firebase-tools@latest apps:list
Initialize AI logic SDK with the init command
npx -y firebase-tools@latest init # Choose AI logic
This will automatically enable the Gemini Developer API in the Firebase console.
More info in Firebase AI Logic Getting Started
Firebase AI Logic allows Gemini models to analyze image files directly from your app. This enables features like creating captions, answering questions about images, detecting objects, and categorizing images. Beyond images, Gemini can analyze other media types like audio, video, and PDFs by passing them as inline data with their MIME type. For files larger than 20 megabytes (which can cause HTTP 413 errors as inline data), store them in Cloud Storage for Firebase and pass their URLs to the Gemini Developer API.
Maintain history automatically using startChat.
To improve the user experience by showing partial results as they arrive (like a typing effect), use generateContentStream instead of generateContent for faster display of results.
Supported Platforms and Frameworks include Kotlin and Java for Android, Swift for iOS, JavaScript for web apps, Dart for Flutter, and C Sharp for Unity.
Enforce a specific JSON schema for the response.
Hybrid on-device inference for web apps, where the Firebase Javascript SDK automatically checks for Gemini Nano's availability (after installation) and switches between on-device or cloud-hosted prompt execution. This requires specific steps to enable model usage in the Chrome browser, more info in the hybrid-on-device-inference documentation.
Recommended: The developer must enable Firebase App Check to prevent unauthorized clients from using their API quota. see App-check recaptcha enterprise.
Consider that you do not need to hardcode model names (e.g., gemini-flash-lite-latest). Use Firebase Remote Config to update model versions dynamically without deploying new client code. See Changing model names remotely
| Language, Framework, Platform | Gemini API provider | Context URL |
|---|---|---|
| Web Modular API | Gemini Developer API (Developer API) | firebase://docs/ai-logic/get-started |
Always use the most recent version of Gemini (gemini-flash-latest) unless another model is requested by the docs or the user. DO NOT USE gemini-1.5-flash
Web SDK code examples and usage patterns
Weekly Installs
2.4K
Repository
GitHub Stars
182
First Seen
Feb 17, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
gemini-cli2.3K
codex1.5K
opencode1.5K
github-copilot1.5K
amp1.5K
kimi-cli1.5K
99,500 周安装