如果您直接从移动应用或 Web 应用调用 API(例如,允许访问生成式 AI 模型的 API),则该 API 容易受到未经授权的客户端的滥用。为了帮助保护这些 API,您可以使用 Firebase App Check 验证所有传入的 API 调用是否来自您的实际应用。
Firebase AI Logic 提供了一个代理网关,可让您与 Firebase App Check 集成,并保护移动应用和 Web 应用调用的生成式 AI 模型 API。当您使用 Firebase AI Logic SDK 时,Gemini Developer API 和 Vertex AI Gemini API 均支持与 App Check 集成。
您可以保护 Gemini 和 Imagen 模型。
[null,null,["最后更新时间 (UTC):2025-08-19。"],[],[],null,["\u003cbr /\u003e\n\nWhen you call an API directly from a mobile or web app (for example, the APIs\nthat allow access to generative AI models), the API is vulnerable to abuse by\nunauthorized clients. To help protect these APIs, you can use\n[Firebase App Check](/docs/app-check) to verify that all incoming API calls\nare from your actual app.\n\nFirebase AI Logic provides a proxy gateway that lets you integrate with\nFirebase App Check and protect the generative AI model APIs called by your\nmobile and web apps. **Integrating with App Check is supported for both the\nGemini Developer API and the Vertex AI Gemini API\n*when you use the Firebase AI Logic SDKs* .\nYou can protect both Gemini and Imagen models.**\n| We strongly recommend implementing Firebase App Check into your app as early as possible, even during development, so that every version of your app is protected from API abuse.\n\nHigh-level summary of how App Check works\n\nWith App Check, devices running your app use an app or device attestation\nprovider that verifies one or both of the following:\n\n- Requests originate from your authentic app\n- Requests originate from an authentic, untampered device\n\nThis attestation is attached to every request your app makes using a\nFirebase AI Logic SDK. When you enable App Check enforcement,\nrequests from clients without a valid attestation will be rejected, as will any\nrequest originating from an app or platform you haven't authorized.\n\nFind detailed information in the\n[Firebase App Check documentation](/docs/app-check).\n\nAvailable providers and implementation instructions\n\nApp Check has built-in support for using the following services as\nattestation providers. **Click a provider's link to view the App Check\ndocumentation for that provider, including descriptions and implementation\ninstructions.**\n\n- Apple platforms: [DeviceCheck](/docs/app-check/ios/devicecheck-provider) or [App Attest](/docs/app-check/ios/app-attest-provider)\n- Android: [Play Integrity](/docs/app-check/android/play-integrity-provider)\n- Web: [reCAPTCHA Enterprise](/docs/app-check/web/recaptcha-enterprise-provider)\n\n| **Note:** Flutter and Unity support all the providers listed above. View specific App Check implementation instructions in the [Flutter](/docs/app-check/flutter/default-providers) and [Unity](/docs/app-check/unity/default-providers) pages. Additionally, for Flutter, see below for [required special instantiation](#instantiation-flutter).\n\nIf these providers are insufficient for your needs, you can also implement your\nown service that uses either a third-party attestation provider or your own\nattestation techniques\n(for more details, see the [App Check documentation](/docs/app-check)).\n\nSpecial instantiation required for Flutter\n\n|-------------------------------------------------------------------------------------------------------------------------------------|\n| *Click your Gemini API provider to view provider-specific content and code on this page.* Gemini Developer API Vertex AI Gemini API |\n\nWhen using App Check with Firebase AI Logic in Flutter apps, you need to\nexplicitly pass in App Check during instantiation, like so: \n\n final ai = await FirebaseAI.googleAI(appCheck: FirebaseAppCheck.instance)\n .generativeModel(model: '\u003cvar translate=\"no\"\u003eMODEL_NAME\u003c/var\u003e');\n\nAdditional information about App Check\n\n- Learn about [quotas and limits](/docs/app-check#quotas_limits) for\n App Check.\n\n- Make sure that you\n [enable enforcement of App Check](/docs/app-check/enable-enforcement)\n before you release your app to real users.\n\nUnderstand how Firebase AI Logic integrates with App Check\n\nTo use the Firebase AI Logic SDKs, the\n[Firebase AI Logic API (`firebasevertexai.googleapis.com`)](https://console.cloud.google.com/apis/library/firebasevertexai.googleapis.com?project=_)\nmust be enabled in your Firebase project. This is because requests made by the\nFirebase AI Logic SDKs are first sent to the Firebase AI Logic\nserver, which acts as a proxy gateway where Firebase App Check verification\ntakes place *before* the request is allowed to proceed to your chosen\n\"Gemini API\" provider's backend and the APIs to access the Gemini\nand Imagen models."]]