BXUP Track progress & test yourself — free
Frontend & Mobile · Playbook · Advanced · ~6 min read
FRONTEND & MOBILE · PLAYBOOK · ADVANCED

On-Device AI with Hybrid Fallback: Chrome Built-In, Gemini Nano, Foundation Models

Summarization, proofreading, classification and short rewrites no longer need a server round-trip: Chrome ships built-in AI APIs, Android exposes Gemini Nano through ML Kit GenAI, and iOS 26 opens the Foundation Models framework. The architecture that ships is hybrid — detect capability, run on-device when you can, degrade gracefully to a cloud path when you cannot.

Tier: Advanced · Workflow area: AI features in the client

This playbook builds the capability-gated hybrid: private, zero-marginal-cost, offline-capable inference for supported devices, with one abstraction so product code never knows which path answered.

When to use

  • Task-shaped features on user-visible text: summarize, proofread, rewrite, translate, classify, extract, short structured generation.
  • Privacy-sensitive input (notes, messages, health-adjacent text) where "never leaves the device" is a feature you can put in the UI.
  • High-frequency, low-complexity calls where per-token cloud pricing dominates the feature's economics.

Skip it for open-ended chat quality, long-context reasoning, or anything needing tools and retrieval — small on-device models are task engines, not frontier assistants.

Prerequisites

  • Web: Chrome's built-in AI task APIs (Summarizer, Translator, Language Detector, Proofreader, Prompt API) — check current API status and origin-trial/flag requirements for each; availability is per-API, per-Chrome-version, with hardware requirements (storage, RAM/VRAM) gating the model download.
  • Android: ML Kit GenAI APIs (summarization, proofreading, rewriting, image description) over Gemini Nano via AICore — supported-device list checked, not assumed.
  • iOS/macOS: Foundation Models framework (iOS 26+) with LanguageModelSession, guided generation via @Generable, on Apple Intelligence-enabled devices.
  • Cloud fallback path: Firebase AI Logic (client SDKs with keys held server-side/proxied) or your own BFF route (pb-50) — never a raw provider key in the app.

The workflow

  1. Write the capability gate first — availability is a spectrum, not a boolean. Every platform reports more than yes/no; your gate must handle unavailable, downloadable (model not yet fetched), downloading, and ready. Web:

    const availability = await Summarizer.availability();
    // "unavailable" | "downloadable" | "downloading" | "available"
    if (availability === "downloadable") {
      summarizer = await Summarizer.create({
        monitor(m) { m.addEventListener("downloadprogress", e =>
          updateUI(e.loaded)); },
      });
    }
    

    On Android, the GenAI API's status check plays the same role (with AICore managing the Nano download); on iOS, check SystemLanguageModel.default.availability, which reports reasons like Apple Intelligence disabled or model not ready. The download states matter for UX: trigger downloads at an opportune moment (onboarding, Wi-Fi), never block a user action on a surprise multi-hundred-MB fetch.

  2. Abstract the task, not the model. Product code calls summarize(text, opts) — a small module resolves the best available engine per call: on-device if ready, cloud if allowed, "unavailable" UI otherwise. Keep the interface task-shaped (summarize/rewrite/classify) rather than chat-shaped; task APIs across all three platforms take options (length, tone, format), and a task interface lets each backend use its native strengths. Record which engine served each request in your analytics (engine name, not content) — you will need the split for quality and cost analysis.

  3. Engineer for small-model reality. On-device models are 3-4B-class: keep prompts short and directive; constrain outputs structurally — Foundation Models' @Generable guided generation gives you typed Swift structs instead of parsed prose, and the Prompt API supports JSON schema constraints; validate outputs with the same rigor as cloud calls (Zod or codable types) because small models drift more, not less; and set expectations in UX copy for generative surfaces ("quick summary" framing, with an explicit "try the fuller cloud version" affordance where policy allows).

  4. Define the fallback policy as product policy, not just error handling. Decide and document, per feature: privacy-first (on-device or nothing — the honest choice if you market "never leaves your device"; the fallback is a graceful unavailable state), quality-first (cloud when reachable, on-device offline), or cost-first (on-device whenever capable, cloud for overflow cases like inputs exceeding the on-device context window). Then implement fallback triggers uniformly: capability-unavailable, inference error, timeout, output-validation failure, and input-too-large all route to the same policy switch. If privacy claims are made, the cloud path must require explicit user consent per surface — silently "upgrading" a private feature to cloud is a trust breach, not a fallback.

  5. Test on the real capability matrix. Emulators and dev machines lie about availability. Your matrix: a supported flagship (full on-device path, including first-run download UX), an unsupported/older device (fallback or unavailable UI), airplane mode on both (offline on-device still works; cloud path degrades honestly), and mid-download states. Add a CI-able contract test for the abstraction: mock each engine state and assert the policy routes correctly — the matrix run is manual per release, the routing logic is tested forever.

Key Takeaway:

The unit of design is the task plus a capability gate plus a written fallback policy. On-device is a privacy and cost feature only if the fallback respects the promise — detect honestly, download politely, degrade explicitly.

Tool variants

  • Chrome built-in AI: task APIs (Summarizer, Translator, Proofreader, Writer/Rewriter) are the stable-ish surface; the Prompt API is the flexible one — statuses differ, so gate per API and re-check each Chrome release. Non-Chromium browsers: your abstraction's cloud path is the implementation.
  • ML Kit GenAI (Android): highest-level path to Nano — task APIs with no model management; for custom prompting beyond the task set, the lower-level AI Edge / Nano access applies on eligible devices.
  • Foundation Models (iOS 26+):LanguageModelSession with guided generation and streaming; sessions are stateful — create per task, watch context limits, and handle the guardrail-violation error as a first-class refusal state (pb-51's rubric applies on-device too).
  • Firebase AI Logic: the pragmatic hybrid backend for mobile — cloud Gemini without shipping keys, plus a supported path that can prefer on-device and fall back to cloud on capable stacks.

Verification

  • Capability gate handles all four availability states on each platform, with download progress UI and no user action blocked on an unannounced download.
  • Airplane-mode test: on-device features work offline on capable hardware; incapable devices show the designed degraded state, not a spinner or crash.
  • Output validation catches malformed small-model output and routes per policy (retry, fallback, or honest failure) — tested with forced-failure fixtures.
  • Analytics show per-engine request splits and quality signals (pb-51 events tagged with engine), so the on-device quality delta is measured, not vibes.
  • If privacy is claimed: traffic inspection during on-device inference confirms zero content egress, and the cloud consent gate is verified per surface.

Pitfalls

  • Treating availability as static. A user's device can gain (model downloaded) or lose (storage purge, settings toggle) capability between sessions; gate per session, not per install.
  • Chat-shaped abstractions over task APIs. Wrapping everything as "send prompt, get text" forfeits guided generation, task tuning and structured output — the strengths of these stacks.
  • Assuming cloud-model behavior. Prompts tuned on a frontier model often fail on Nano-class models; tune per engine and keep per-engine prompt variants in the abstraction.
  • Silent cloud fallback under a privacy banner. The single fastest way to convert a differentiator into an incident. Consent, or unavailable — nothing in between.
  • Shipping without the unsupported-device experience. A large share of your fleet will take the fallback path for years; it is the majority experience, design it as such.
  • Ignoring first-run download UX. The model fetch is the feature's real onboarding; a surprise 1-2 GB download on cellular is a one-star review generator.

Restricted-environment variant

On-device inference is the restricted environment's best friend: content never leaves the device, satisfying most data-residency and confidentiality constraints by construction. Configure the abstraction's policy to privacy-first (no cloud path) for restricted deployments — the same codebase serves both postures via configuration. Verify with egress monitoring rather than documentation, and note that OS-level features (Apple Intelligence's own cloud escalation, browser sync) are outside your app's control — scope your claims to what your code does.

Note

"On-device" claims in marketing and consent screens are compliance statements. Have the actual data flow — including fallback triggers and any OS-mediated processing — reviewed against the claim before launch, not after a user reads the network log.

Success criteria

  • Task features run on-device for the capable fleet with measured quality parity acceptable to product, and marginal inference cost for those requests is zero.
  • The capability matrix passes on every release: no crashes, blocked actions or silent failures on unsupported or offline devices.
  • Privacy-first surfaces demonstrate zero content egress under inspection, and consent gates every cloud escalation where claims are made.
  • Engine mix, fallback rates and per-engine quality signals are on a dashboard — and the fallback policy document matches what the code actually does.
This is the free reading view. Open BXUP to track your progress, run the hands-on labs, and prove it with original, exam-pattern assessments.
© Anvi Innovate · BXUP — Be Exponentially Upskilled · BXUP is an independent learning platform, not affiliated with or endorsed by AWS, Microsoft, Google, NVIDIA, IBM, Salesforce, Databricks, Oracle or Anthropic. All trademarks belong to their respective owners. · bxup.in