Local Means Local: Testing Firebase AI Fallback Before Dispatch
A testing pattern that proves a Firebase AI Logic 'Run on this device' button stays local and never silently escalates to a remote Gemini call.
Radar snapshot
Firebase AI Logic rides Google's distribution and billing rails, so the model is solid but gives indie builders little pricing leverage. The technique itself is highly actionable for solo devs shipping hybrid AI features with tight cost and privacy constraints. How we score
Business breakdown
Firebase AI Logic is Google's monetized gateway to Gemini models, billed through Firebase Blaze pay-as-you-go once free Spark quota runs out. The article targets teams shipping hybrid on-device/cloud AI UX, where trust depends on verifiable local execution, an increasingly important selling point for privacy-sensitive apps.
Pricing at a glance
| Tier | Price | Limits |
|---|---|---|
| Spark (free) | $0 | Limited daily Gemini requests via Firebase AI Logic; no billing account |
| Blaze (pay-as-you-go) | Usage-based per token/model | Higher quotas, on-device inference still free since it runs on the user's hardware |
Use it if…
Web and TypeScript developers shipping hybrid on-device/cloud AI features who must guarantee a 'local' button never leaks data remotely.
Skip it if…
Teams with no on-device inference path or those already fully committed to a single cloud LLM with no privacy guarantees to prove.
Alternatives & competitors
| Option | Positioning | Pricing |
|---|---|---|
| Vercel AI SDK | Provider-agnostic streaming layer; no built-in on-device fallback semantics or local-execution verification | Free open-source library; you pay model providers directly |
| Transformers.js / WebLLM | Pure in-browser inference with no cloud escalation path at all | Free and open source; cost is the user's GPU and download size |
| Direct Gemini API | Skips Firebase abstraction and gives explicit control over when a request leaves the device | Free tier plus per-token paid usage |
What an indie dev can do with this
- Instrument the dispatch layer with a test that asserts zero network calls when the on-device path is selected.
- Mock the remote client and fail the test if it is invoked, so regressions surface in CI rather than in a privacy incident.
- Surface the execution path in the UI (local vs remote) so users can verify the promise the button makes.
FAQ
- Is Firebase AI Logic free to use?
- On the Spark plan you get a limited no-cost Gemini quota without a billing account; heavier usage requires the Blaze pay-as-you-go plan. On-device inference costs nothing on Google's side because it r
- Can I guarantee a request never leaves the device?
- Only if you assert it in code: stub the remote client, dispatch through the local path, and fail the test if any outbound call occurs. A UI label alone is not a guarantee.
- What is the cheapest way to add on-device AI to a web app?
- Pair a browser inference runtime like Transformers.js or WebLLM with a cloud fallback, and gate the fallback behind an explicit, tested condition. That avoids token spend on requests that could run lo