コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Firebase AI Logic を使用する Gemini API
plat_ios
plat_android
plat_web
plat_flutter
plat_unity
Firebase AI Logic を使用して、Gemini モデルと Imagen モデルで AI を活用したモバイルアプリ、ウェブアプリ、機能を構築する
Firebase AI Logic を使用すると、Google の最新の生成 AI モデル(Gemini モデルと Imagen モデル)にアクセスできます。
サーバーサイドではなく、モバイルアプリやウェブアプリから Gemini API または Imagen API を直接呼び出す必要がある場合は、Firebase AI Logic クライアント SDK を使用できます。これらのクライアント SDK は、モバイルアプリとウェブアプリでの使用を目的として特別に構築されており、不正なクライアントに対するセキュリティ オプションと、他の Firebase サービスとの統合を提供します。
これらのクライアント SDK は、Apple プラットフォーム用の Swift、Android 用の Kotlin と Java、ウェブ用の JavaScript、Flutter 用の Dart、Unity で利用できます。
これらのクライアント SDK を使用すると、アプリに AI パーソナライズ機能を追加したり、AI チャット エクスペリエンスを構築したり、AI による最適化と自動化を作成したりできます。
始めましょう
柔軟性やサーバーサイドの統合が必要な場合
Genkit は、Google、OpenAI、Anthropic などのモデルに幅広くアクセスできる、高度なサーバーサイド AI 開発用の Firebase のオープンソース フレームワークです。高度な AI 機能と専用のローカル ツールが含まれています。
主な機能
仕組み
Firebase AI Logic は、クライアント SDK、プロキシ サービス、その他の機能を提供します。これらの機能を使用すると、Google の生成 AI モデルにアクセスして、モバイルアプリやウェブアプリに AI 機能を構築できます。
Google モデルと「Gemini API」プロバイダのサポート
Google Cloud では、最新の Gemini モデルと Imagen 3 モデルをすべてサポートしています。これらのモデルにアクセスするには、優先する「Gemini API」プロバイダを選択します。Gemini Developer API と Vertex AI Gemini API の両方をサポートしています。2 つの API プロバイダの使用の違いについて学習する。
Gemini Developer API を使用する場合は、その「無料枠」を利用して、迅速に運用を開始できます。
モバイル クライアント SDK とウェブ クライアント SDK
Apple プラットフォーム用の Swift、Android 用の Kotlin と Java、ウェブ用の JavaScript、Flutter 用の Dart、Unity で利用可能な Firebase AI Logic クライアント SDK を使用して、モバイルアプリまたはウェブアプリからモデルに直接リクエストを送信します。
Firebase プロジェクトで Gemini API プロバイダの両方が設定されている場合は、もう一方の API を有効にして初期化コードを数行変更するだけで、API プロバイダを切り替えることができます。
また、ウェブ用のクライアント SDK では、パソコンの Chrome で実行されるウェブアプリのハイブリッド推論とオンデバイス推論への試験運用版アクセスが提供されています。この構成により、アプリはオンデバイス モデルが使用可能な場合はそれを使用し、必要に応じてクラウドホスト モデルにシームレスにフォールバックできます。
プロキシ サービス
Google のプロキシ サービスは、クライアントと選択した Gemini API プロバイダ(および Google のモデル)間のゲートウェイとして機能します。モバイルアプリとウェブアプリにとって重要なサービスと統合を提供します。たとえば、Firebase App Check を設定して、選択した API プロバイダとバックエンド リソースを未承認のクライアントによる不正使用から保護できます。
Gemini Developer API を使用することを選択した場合は、特に重要です。これは、プロキシ サービスとこの App Check 統合により、Gemini API キーがサーバーに残り、アプリのコードベースに埋め込まれないようにするためです。
実装パス
|
Firebase プロジェクトを設定し、アプリを Firebase に接続する |
Firebase コンソールの Firebase AI Logic ページのガイド付きワークフローを使用して、プロジェクトを設定し(選択した Gemini API プロバイダに必要な API を有効にするなど)、Firebase プロジェクトにアプリを登録してから、Firebase 構成をアプリに追加します。 |
|
SDK をインストールして初期化する |
アプリのプラットフォームに固有の Firebase AI Logic SDK をインストールし、アプリでサービスを初期化してモデル インスタンスを作成します。 |
|
Gemini モデルと Imagen モデルにプロンプト リクエストを送信する |
SDK を使用して、テキストのみのプロンプトまたはマルチモーダル プロンプトを Gemini モデルに送信し、テキストとコード、構造化された出力(JSON など)、画像を生成します。または、Imagen モデルに画像を生成するように求めることもできます。 マルチターンのチャット、テキストと音声の双方向ストリーミング、関数呼び出しを使用して、よりリッチなエクスペリエンスを構築します。
|
|
本番環境の準備 |
Firebase App Check を使用して API を不正使用から保護する、Firebase Remote Config を使用してコード内のパラメータ(モデル名など)をリモートで更新するなど、モバイルアプリとウェブアプリの重要な統合を実装します。 |
次のステップ
モバイルアプリまたはウェブアプリからモデルにアクセスする
スタートガイドに移動
サポートされているモデルの詳細
さまざまなユースケースで利用可能なモデルとその
割り当てと
料金について学習します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-28 UTC。
[null,null,["最終更新日 2025-08-28 UTC。"],[],[],null,["Gemini API using Firebase AI Logic \nplat_ios plat_android plat_web plat_flutter plat_unity \nBuild AI-powered mobile and web apps and features with the Gemini and Imagen models using Firebase AI Logic \n\nFirebase AI Logic gives you access to the latest generative AI models from\nGoogle: the Gemini models and Imagen models.\n\nIf you need to call the Gemini API or Imagen API directly\nfrom your mobile or web app --- rather than server-side --- you can use the\nFirebase AI Logic client SDKs. These client SDKs are built\nspecifically for use with mobile and web apps, offering security options against\nunauthorized clients as well as integrations with other Firebase services.\n\n**These client SDKs are available in\nSwift for Apple platforms, Kotlin \\& Java for Android, JavaScript for web,\nDart for Flutter, and Unity.**\n\n\n| **Firebase AI Logic and its client SDKs were\n| formerly called \"Vertex AI in Firebase\".** In May 2025, we [renamed and\n| repackaged our services into Firebase AI Logic](/docs/ai-logic/faq-and-troubleshooting#renamed-product) to better reflect our expanded services and features --- for example, we now support the Gemini Developer API!\n\n\u003cbr /\u003e\n\nWith these client SDKs, you can add AI personalization to apps, build an AI chat\nexperience, create AI-powered optimizations and automation, and much more!\n\n[Get started](/docs/ai-logic/get-started)\n\n\u003cbr /\u003e\n\n**Need more flexibility or server-side integration?** \n\n[Genkit](https://genkit.dev/) is Firebase's open-source\nframework for sophisticated server-side AI development with broad access to\nmodels from Google, OpenAI, Anthropic, and more. It includes more advanced AI\nfeatures and dedicated local tooling.\n\nKey capabilities\n\n|---------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Multimodal and natural language input | The [Gemini models](/docs/ai-logic/models) are multimodal, so prompts sent to the Gemini API can include text, images, PDFs, video, and audio. Some Gemini models can also generate multimodal *output* . Both the Gemini and Imagen models can be prompted with natural language input. |\n| Growing suite of capabilities | With the SDKs, you can call the Gemini API or Imagen API directly from your mobile or web app to [build AI chat experiences](/docs/ai-logic/chat), [generate images,](/docs/ai-logic/generate-images-imagen) use tools (like [function calling](/docs/ai-logic/function-calling) and [grounding with Google Search](/docs/ai-logic/grounding-google-search)), [stream multimodal input and output (including audio)](/docs/ai-logic/live-api), and more. |\n| Security and abuse prevention for production apps | Use [Firebase App Check](/docs/ai-logic/app-check) to help protect the APIs that access the Gemini and Imagen models from abuse by unauthorized clients. Firebase AI Logic also has [rate limits per user](/docs/ai-logic/faq-and-troubleshooting#rate-limits-per-user) *by default*, and these per-user rate limits are fully configurable. |\n| Robust infrastructure | Take advantage of scalable infrastructure that's built for use with mobile and web apps, like [managing files with Cloud Storage for Firebase](/docs/ai-logic/solutions/cloud-storage), managing structured data with Firebase database offerings (like [Cloud Firestore](/docs/firestore)), and dynamically setting run-time configurations with [Firebase Remote Config](/docs/ai-logic/solutions/remote-config). |\n\nHow does it work?\n\nFirebase AI Logic provides client SDKs, a proxy service, and other features\nwhich allow you to access Google's generative AI models to build AI features in\nyour mobile and web apps.\n\nSupport for Google models and \"Gemini API\" providers\n\nWe support all the latest Gemini models and Imagen 3 models,\nand you choose your preferred \"Gemini API\" provider to access these models.\nWe support both the Gemini Developer API and\nVertex AI Gemini API. Learn about the\n[differences between using the two API providers](/docs/ai-logic/faq-and-troubleshooting#differences-between-gemini-api-providers).\n\nAnd if you choose to use the Gemini Developer API, you can take\nadvantage of their \"free tier\" to get you up and running fast.\n\nMobile \\& web client SDKs\n\nYou send requests to the models directly from your mobile or web app using our\nFirebase AI Logic client SDKs, available in\nSwift for Apple platforms, Kotlin \\& Java for Android, JavaScript for Web,\nDart for Flutter, and Unity.\n\nIf you have both of the Gemini API providers set up in your Firebase\nproject, then you can switch between API providers just by enabling the other\nAPI and changing a few lines of initialization code.\n\nAdditionally, our client SDK for Web offers experimental access to\n[hybrid and on-device inference for web apps](/docs/ai-logic/hybrid-on-device-inference)\nrunning on Chrome on desktop. This configuration allows your app to use the\non-device model when it's available, but fall back seamlessly to the\ncloud-hosted model when needed.\n\nProxy service\n\nOur proxy service acts as a gateway between the client and your chosen\nGemini API provider (and Google's models). It provides services and\nintegrations that are important for mobile and web apps. For example, you can\n[set up Firebase App Check](/docs/ai-logic/app-check) to help protect your\nchosen API provider and your backend resources from abuse by unauthorized\nclients.\n\nThis is particularly critical if you chose to use the\nGemini Developer API because our proxy service and this App Check\nintegration make sure that your Gemini API key stays on the server and\nis *not* embedded in your apps' codebase.\n\nImplementation path\n\n|---|---------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Set up your Firebase project and connect your app to Firebase | Use the guided workflow in the [**Firebase AI Logic** page](https://console.firebase.google.com/project/_/ailogic) of the Firebase console to set up your project (including enabling the required APIs for your chosen Gemini API provider), register your app with your Firebase project, and then add your Firebase configuration to your app. |\n| | Install the SDK and initialize | Install the Firebase AI Logic SDK that's specific to your app's platform, and then initialize the service and create a model instance in your app. |\n| | Send prompt requests to the Gemini and Imagen models | Use the SDKs to send text-only or multimodal prompts to a Gemini model to generate [text and code](/docs/ai-logic/generate-text), [structured output (like JSON)](/docs/ai-logic/generate-structured-output) and [images](/docs/ai-logic/generate-images-gemini). Alternatively, you can also prompt an Imagen model to [generate images](/docs/ai-logic/generate-images-imagen). Build richer experiences with [multi-turn chat](/docs/ai-logic/chat), [bidirectional streaming of text and audio](/docs/ai-logic/live-api), and [function calling](/docs/ai-logic/function-calling). |\n| | Prepare for production | Implement important integrations for mobile and web apps, like protecting the API from abuse with [Firebase App Check](/docs/ai-logic/app-check) and using [Firebase Remote Config](/docs/ai-logic/solutions/remote-config) to update parameters in your code remotely (like model name). |\n\nNext steps\n\nGet started with accessing a model from your mobile or web app\n\n[Go to Getting Started guide](/docs/ai-logic/get-started)\n\n\nLearn more about the supported models Learn about the [models available for various use cases](/docs/ai-logic/models) and their [quotas](/docs/ai-logic/quotas) and [pricing](/docs/ai-logic/pricing).\n\n\u003cbr /\u003e"]]