Firebase AI Logic
Firebase AI Logic is a Firebase-specific integration and therefore uses models and backends supported by Firebase. Be model-version neutral within that product: verify current support and choose from requirements instead of automatically selecting a named model or a latest alias.
Non-Negotiable Safety Rules
- Inspect the platform, existing Firebase app, SDK version, lockfiles, selected project, billing plan, and current backend before changing anything.
- Do not globally install Firebase CLI or run
npx -y ...@latest. Prefer an existing project-local CLI; otherwise propose a pinned version and obtain authorization for the dependency change.
- Project creation,
firebase use, API enablement, billing changes, App Check enforcement, Remote Config publishing, and deployment alter external state. Preview the target project and get confirmation unless the user explicitly requested that exact action.
- Never expose service-account credentials or API keys. Do not put a privileged server credential in client code.
- Do not assume a model is available because its name sounds recent. Verify it against the current official Firebase AI Logic model page and the chosen backend.
- Prefer an explicit stable production model. Preview or experimental models require an explicit prototyping reason and retirement plan.
Decide the Backend
Firebase AI Logic supports a Gemini Developer API backend and a Vertex AI Gemini API backend. Choose using current documentation and project requirements:
| Requirement |
Verify |
| Prototype or simple Firebase client |
plan, regional availability, quotas, supported models |
| Enterprise IAM, region, or Vertex controls |
Blaze requirements, location, quotas, supported models |
| Existing production project |
preserve its backend unless migration is requested |
Do not claim one backend is universally the default. Record the selected backend and why.
Model Policy
At implementation time:
- open the official supported models page;
- filter by the selected backend, platform, capability, region, billing, and release stage;
- prefer a current explicit stable model for production;
- verify text, image, audio, video, PDF, tool/function calling, structured output, and streaming support independently;
- place the model name behind configuration rather than scattering it through code.
For deployed applications, use Firebase Remote Config for the model name and other safe-to-vary generation settings. Give it a known-good client default, validate fetched values against an allowlist, and roll changes out gradually. Remote Config is not a substitute for server-side authorization or secret storage.
Conceptual configuration:
model_name = remote_config("model_name", known_good_stable_default)
assert model_name in approved_model_allowlist
Do not copy a model identifier from this skill; use the currently verified value.
Workflow
1. Inspect without mutation
- identify web, Android, Apple, Flutter, or Unity;
- inspect Firebase SDK/BoM and lockfile versions;
- read
.firebaserc and firebase.json without changing the selected project;
- confirm Firebase app initialization order;
- identify current backend, model configuration, App Check, Remote Config, analytics, and consent requirements;
- capture the project's existing test and emulator workflow.
2. Plan dependencies
Use the platform's official Firebase SDK package and the existing package manager. Keep versions governed by the project's lockfile or Firebase BoM. Present the exact proposed diff before adding or upgrading dependencies.
Use a local CLI invocation such as the project's package script or pinned firebase-tools dev dependency. Never let an unreviewed latest CLI mutate a production project.
3. Initialize the service
Follow the current platform-specific getting started guide. Keep Firebase app initialization before AI Logic model creation. Choose the backend explicitly. Use a model name sourced from validated configuration.
4. Add the smallest capability
Start with one request and explicit error handling. Then add only the requested features:
- streaming with cancellation and partial-state handling;
- structured output with a schema plus application-side validation;
- multimodal inputs with MIME/type, size, privacy, and storage controls;
- chat with bounded history and a clear reset policy;
- tool/function calling with a server-authorized execution layer;
- image generation only after checking current model and billing support.
Treat all model output and tool arguments as untrusted. The model never grants authorization.
5. Production hardening
- Configure App Check in monitor mode before enforcement when appropriate.
- Apply per-user and per-feature quotas and abuse controls.
- Keep sensitive operations on a trusted backend.
- Avoid logging prompts, media, tokens, or personal data by default.
- Define data retention, deletion, consent, and geographic requirements.
- Add Remote Config rollback values and staged rollout.
- Instrument latency, errors, quota exhaustion, safety outcomes, and cost without recording raw sensitive content.
6. Verify
Run:
- platform build/typecheck;
- initialization-order test;
- configuration fallback and allowlist tests;
- structured-output validation tests;
- tool authorization tests;
- App Check/emulator checks where supported;
- one bounded live request only when credentials, billing, and external use are authorized.
Report exact SDK/CLI versions, target Firebase project, backend, model source, test results, and skipped external checks.
Common Failure Triage
| Symptom |
Check first |
| permission denied |
target project, service provisioning, backend, App Check, IAM, billing |
| model not found |
current Firebase-supported model list, backend, location, retirement status |
| quota or billing error |
plan, quotas, selected API backend, request size |
| startup crash |
Firebase app configured before model construction |
| schema mismatch |
selected model capability and application-side validation |
| released app breaks after retirement |
Remote Config fallback, approved model rollout, rollback |
Completion Gate
- No global or unpinned auto-install command was introduced.
- Target project and external mutations were explicit.
- Model choice was verified from current Firebase documentation.
- Production uses an explicit stable model and a safe remote migration path.
- App Check, authorization, privacy, quotas, and rollback were addressed.
- Platform build and focused tests pass, or skipped checks are clearly stated.
1---2name: firebase-ai-logic-basics3description: Integrate Firebase AI Logic safely across web, Android, Apple, Flutter, or Unity; choose the Firebase-supported Gemini API backend and a verified model.4---56# Firebase AI Logic78Firebase AI Logic is a Firebase-specific integration and therefore uses models and backends supported by Firebase. Be model-version neutral within that product: verify current support and choose from requirements instead of automatically selecting a named model or a `latest` alias.910## Non-Negotiable Safety Rules1112- Inspect the platform, existing Firebase app, SDK version, lockfiles, selected project, billing plan, and current backend before changing anything.13- Do not globally install Firebase CLI or run `npx -y ...@latest`. Prefer an existing project-local CLI; otherwise propose a pinned version and obtain authorization for the dependency change.14- Project creation, `firebase use`, API enablement, billing changes, App Check enforcement, Remote Config publishing, and deployment alter external state. Preview the target project and get confirmation unless the user explicitly requested that exact action.15- Never expose service-account credentials or API keys. Do not put a privileged server credential in client code.16- Do not assume a model is available because its name sounds recent. Verify it against the current official Firebase AI Logic model page and the chosen backend.17- Prefer an explicit stable production model. Preview or experimental models require an explicit prototyping reason and retirement plan.1819## Decide the Backend2021Firebase AI Logic supports a Gemini Developer API backend and a Vertex AI Gemini API backend. Choose using current documentation and project requirements:2223| Requirement | Verify |24|---|---|25| Prototype or simple Firebase client | plan, regional availability, quotas, supported models |26| Enterprise IAM, region, or Vertex controls | Blaze requirements, location, quotas, supported models |27| Existing production project | preserve its backend unless migration is requested |2829Do not claim one backend is universally the default. Record the selected backend and why.3031## Model Policy3233At implementation time:34351. open the [official supported models page](https://firebase.google.com/docs/ai-logic/models);362. filter by the selected backend, platform, capability, region, billing, and release stage;373. prefer a current explicit stable model for production;384. verify text, image, audio, video, PDF, tool/function calling, structured output, and streaming support independently;395. place the model name behind configuration rather than scattering it through code.4041For deployed applications, use [Firebase Remote Config](https://firebase.google.com/docs/ai-logic/solutions/remote-config) for the model name and other safe-to-vary generation settings. Give it a known-good client default, validate fetched values against an allowlist, and roll changes out gradually. Remote Config is not a substitute for server-side authorization or secret storage.4243Conceptual configuration:4445```text46model_name = remote_config("model_name", known_good_stable_default)47assert model_name in approved_model_allowlist48```4950Do not copy a model identifier from this skill; use the currently verified value.5152## Workflow5354### 1. Inspect without mutation5556- identify web, Android, Apple, Flutter, or Unity;57- inspect Firebase SDK/BoM and lockfile versions;58- read `.firebaserc` and `firebase.json` without changing the selected project;59- confirm Firebase app initialization order;60- identify current backend, model configuration, App Check, Remote Config, analytics, and consent requirements;61- capture the project's existing test and emulator workflow.6263### 2. Plan dependencies6465Use the platform's official Firebase SDK package and the existing package manager. Keep versions governed by the project's lockfile or Firebase BoM. Present the exact proposed diff before adding or upgrading dependencies.6667Use a local CLI invocation such as the project's package script or pinned `firebase-tools` dev dependency. Never let an unreviewed latest CLI mutate a production project.6869### 3. Initialize the service7071Follow the current platform-specific [getting started guide](https://firebase.google.com/docs/ai-logic/get-started). Keep Firebase app initialization before AI Logic model creation. Choose the backend explicitly. Use a model name sourced from validated configuration.7273### 4. Add the smallest capability7475Start with one request and explicit error handling. Then add only the requested features:7677- streaming with cancellation and partial-state handling;78- structured output with a schema plus application-side validation;79- multimodal inputs with MIME/type, size, privacy, and storage controls;80- chat with bounded history and a clear reset policy;81- tool/function calling with a server-authorized execution layer;82- image generation only after checking current model and billing support.8384Treat all model output and tool arguments as untrusted. The model never grants authorization.8586### 5. Production hardening8788- Configure App Check in monitor mode before enforcement when appropriate.89- Apply per-user and per-feature quotas and abuse controls.90- Keep sensitive operations on a trusted backend.91- Avoid logging prompts, media, tokens, or personal data by default.92- Define data retention, deletion, consent, and geographic requirements.93- Add Remote Config rollback values and staged rollout.94- Instrument latency, errors, quota exhaustion, safety outcomes, and cost without recording raw sensitive content.9596### 6. Verify9798Run:991001. platform build/typecheck;1012. initialization-order test;1023. configuration fallback and allowlist tests;1034. structured-output validation tests;1045. tool authorization tests;1056. App Check/emulator checks where supported;1067. one bounded live request only when credentials, billing, and external use are authorized.107108Report exact SDK/CLI versions, target Firebase project, backend, model source, test results, and skipped external checks.109110## Common Failure Triage111112| Symptom | Check first |113|---|---|114| permission denied | target project, service provisioning, backend, App Check, IAM, billing |115| model not found | current Firebase-supported model list, backend, location, retirement status |116| quota or billing error | plan, quotas, selected API backend, request size |117| startup crash | Firebase app configured before model construction |118| schema mismatch | selected model capability and application-side validation |119| released app breaks after retirement | Remote Config fallback, approved model rollout, rollback |120121## Completion Gate122123- No global or unpinned auto-install command was introduced.124- Target project and external mutations were explicit.125- Model choice was verified from current Firebase documentation.126- Production uses an explicit stable model and a safe remote migration path.127- App Check, authorization, privacy, quotas, and rollback were addressed.128- Platform build and focused tests pass, or skipped checks are clearly stated.