Skip to main content
Desarrollo con AI

On-Device or Cloud AI for Your Mobile App? Gemini Nano vs a Server-Side Claude Call

Decide per feature whether your Android app should use Gemini Nano on-device or a server-side Claude call, with real costs and a hybrid router.

11 min
Tiempo de lectura
2,005
Palabras
Publicado
Engr Mejba Ahmed

Escrito por

Engr Mejba Ahmed

Compartir Artículo

On-Device or Cloud AI for Your Mobile App? Gemini Nano vs a Server-Side Claude Call

You have a list of AI features for an Android app, such as message summaries, smart replies, ticket classification, a chat assistant and an agent that calls your APIs, and for each one you have to decide whether it runs on the phone or on a server. For most teams the useful answer is per feature. Short, private, latency-sensitive tasks fit Gemini Nano through ML Kit GenAI. Long-context, multi-tool and cross-platform work fits a server-side Claude call. Then put a router in front of both so the app keeps working when the on-device model is missing, slow or not allowed to fall back.

The sections below map each feature to a side, work out the per-request cost of the cloud path, and give a router sketch that defines what happens when things fail.

Gemini Nano or a server-side Claude call: a feature-by-feature table

The two options differ along five dimensions. Gemini Nano lets you deliver generative AI features "without needing a network connection or sending data to the cloud" (Android Developers: Gemini Nano). Claude runs in the cloud, but every current Claude model supports text and image input, vision and tool use, with a 1M-token context window and up to 128K output tokens (Claude models overview).

The verdicts in the last column are my suggested defaults. Adjust them after you test on your own target devices.

Feature Nano API on Android Claude fit Works offline Data leaves device Suggested default
Summaries of messages or short articles Summarization task API Good Nano only Nano: no On-device, cloud fallback
Smart replies, proofreading, tone rewrite Proofreading / Rewriting task APIs Good Nano only Nano: no On-device
Classification and routing GenerativeModel with typed structured output Haiku 5.5 is positioned for it Nano only Nano: no Hybrid
Long-form chat over long documents GenerativeModel, constrained by token limits 1M context No Yes Cloud
Tool use / agent loops AgentRunner Tool use on all current models Nano only Nano: no Hybrid; cloud for many tools or long histories

Two constraints shape the table. First, the Proofreading and Rewriting APIs are documented for "short chat messages", so do not route a 20-page contract through them. Second, Android lists "token limits, device hardware limitations, and model capability boundaries" as on-device constraints and recommends hybrid inference for those cases (Android Developers: Gemini Nano). Treat any token budget you set for Nano as a number you measured on devices, not one you copied from a spec.

For a related build, see I Built a Niche Mobile App With Claude Code in a Weekend.

What Gemini Nano via ML Kit GenAI covers on Android

Gemini Nano runs inside AICore, an Android system service that "leverages device hardware to enable low inference latency and keeps the model up-to-date." AICore also manages distribution of the model and its future updates, so your APK never downloads or ships the weights (Android Developers: Gemini Nano).

ML Kit groups the Nano capabilities in a way that maps onto app features:

  • Task APIs for summarization (articles or conversations as a bulleted list), proofreading and rewriting short chat messages, image description, and embeddings for semantic search.
  • GenerativeModel for custom text-only or multimodal prompts, typed structured output, and multi-turn chat you manage yourself with a List<Content> and a sessionId.
  • AgentRunner, built on GenerativeModel, which automates multi-turn session management and "multi-step tool-calling loops" on-device.

A practical mapping looks like this:

  • Inbox digest → Summarization API
  • "Fix my message" button → Proofreading API
  • "Make it friendlier" → Rewriting API
  • Ticket category as an enum → GenerativeModel with structured output
  • "Find my order and reschedule it" → AgentRunner with two local tools

The privacy story is strong. On-device execution keeps sensitive data on the phone, and AICore "is built to isolate each request and doesn't store any record of the input data or the resulting outputs after processing them." Speed depends on the phone, though: on-device inference removes network latency, but "inference speed depends on device hardware" (Android Developers: Gemini Nano).

That dependency is the main tradeoff. You cannot assume every user's phone has Nano ready, so check availability at runtime for every request and confirm the supported device list in the ML Kit GenAI documentation before you promise a feature in your store listing.

When a server-side Claude call is the right choice

Send a feature to the cloud when the input is long, when the task needs several tools or a long conversation history, or when the same feature must behave identically on Android, iOS and web. Claude's 1M-token window and tool use on every current model cover those cases (Claude models overview).

Cost is per token, so you can estimate it per request. From the Claude pricing page:

  • Claude Haiku 5.5 is listed for classification, extraction and routing. It costs $0.10/MTok input and $0.50/MTok output for prompts up to 100,000 tokens, and $0.50/MTok input and $2.50/MTok output above that threshold.
  • Claude Sonnet 5.5 costs $2/MTok input and $10/MTok output.
  • Tool use adds a system prompt to your input tokens. On Haiku 5.5 that is 286 tokens with tool choice auto or none, and 406 tokens with any or tool.

Here is the arithmetic for a typical fallback request of 1,000 input tokens and 100 output tokens, at list prices with no caching or batch discounts:

  • Haiku 5.5: 1,000 × $0.10/1M + 100 × $0.50/1M = $0.00015. At one million such requests, that is $150.
  • Haiku 5.5 with one tool and auto: 1,286 input tokens, so about $0.00018.
  • Sonnet 5.5: 1,000 × $2/1M + 100 × $10/1M = $0.003, which is $3,000 per million requests.
  • Haiku 5.5 with a 120,000-token prompt and 1,000 output tokens: 120,000 × $0.50/1M + 1,000 × $2.50/1M = $0.0625. The pricing page notes the step applies per request and counts all input tokens, including cache reads and writes. At the lower rate the same request would cost $0.0125.

This gives you a usable rule. Classification and short fallbacks on Haiku cost fractions of a cent, so the cloud path is cheap enough to serve users without Nano. Long-document chat is where costs grow, so cap prompt size or summarize history before you cross 100,000 tokens on Haiku.

The tradeoff is that every cloud call needs a network connection and sends user data off the device. Both affect the router below.

For billing detail, see Reduce Claude API Costs: A Per-Feature Audit with Batches, Model Routing and Caching.

Two stacked coin columns of very different heights for Haiku and Sonnet requests, with a visible step at the 100,000-token threshold, showing how per-request cost grows.

Hybrid router with failure, privacy and offline paths

Android documents one hybrid option. The Firebase AI Logic Hybrid API can "automatically route requests to Gemini Flash or Gemini Pro models in the cloud when Gemini Nano is unavailable or unsupported." It can also protect cloud inference with Firebase App Check and keep sensitive system prompts server-side (Android Developers: Gemini Nano). If cloud Gemini is an acceptable fallback, start there.

If your cloud model is Claude, you need your own router. The documented hybrid behaviour also leaves three product decisions to you:

  1. What happens when the on-device call fails or hangs after you have already chosen it.
  2. Whether data the user expects to stay on the phone may fall back to the cloud.
  3. What the app shows when it is offline and Nano is unavailable.

A safe default is to give each feature a data policy:

  • LOCAL_ONLY: never leaves the device. Use it for journaling, health notes and anything you marketed as private.
  • CLOUD_OK: may fall back silently. Use it for public content and non-sensitive classification.
  • ASK: needs explicit user consent before the first cloud fallback.

The sketch below shows only the decision logic. LOCAL_TOKEN_BUDGET and LOCAL_TIMEOUT_MS are placeholders to replace with values you measure on your slowest supported device. They are not documented limits.

enum class Policy { LOCAL_ONLY, CLOUD_OK, ASK }

const val LOCAL_TOKEN_BUDGET = 3_000   // measure on target devices
const val LOCAL_TIMEOUT_MS = 8_000L    // measure on slowest supported device

suspend fun route(req: AiRequest): AiResult {
    // 1. Try on-device first when the model is ready and the input fits.
    if (onDeviceReady() && req.estTokens <= LOCAL_TOKEN_BUDGET) {
        val local = withTimeoutOrNull(LOCAL_TIMEOUT_MS) {
            runCatching { runOnDevice(req) }.getOrNull()
        }
        if (local != null) return local
    }
    // 2. On-device unavailable, too large, failed or timed out.
    when (req.policy) {
        Policy.LOCAL_ONLY -> return AiResult.LocalUnavailable   // fail closed
        Policy.ASK -> if (!hasCloudConsent(req.feature)) return AiResult.NeedsConsent
        Policy.CLOUD_OK -> Unit
    }
    // 3. Cloud path: the backend proxy holds the Claude key.
    if (!isOnline()) {
        return if (req.feature.queueable) AiResult.Queued(enqueue(req))
               else AiResult.Offline
    }
    return runCatching { backend.complete(req) }   // one attempt, no retry loop
        .getOrElse { AiResult.Failed(it) }
}

Each branch maps to a UI state:

  • On-device succeeds: show the result. Nothing left the phone.
  • On-device fails or times out, CLOUD_OK: one attempt goes to your backend. If that fails too, return Failed and show a retry button. Do not loop, because a stuck request should not burn tokens.
  • ASK without consent: return NeedsConsent. The UI explains that this request will be processed on a server and offers "Send" or "Cancel". Store consent per feature, not globally.
  • LOCAL_ONLY: return LocalUnavailable and say plainly that the feature needs a supported device or a moment for the model to become ready. Never send this data to the cloud as a fallback.
  • Offline with no on-device result: queueable work, such as tagging saved notes, goes into a queue that drains when connectivity returns. Interactive work, such as a chat reply, returns Offline so the UI can disable the send button instead of spinning.

Keep the Claude API key on your backend only. The app authenticates to your own endpoint, and the backend adds the key, chooses Haiku or Sonnet, enforces a max prompt size below the 100,000-token price step, and logs cost per feature. The same proxy is where you keep system prompts server-side.

On the key-handling risk, see Is Your OpenAI or Claude API Key in the Browser? Fixing NEXT_PUBLIC_ Leaks in AI-Built Next.js MVPs.

A branching track diagram where a request beam reaches a gate and splits into a sealed local lane, a consent gate toward the cloud, and a queue lane for offline work.

If you also ship iOS: what to check before adding Apple's on-device model

Treat Apple's Foundation Models framework as a third provider behind the same route() contract, with the same policies and UI states. Before you assign any feature to it, confirm three things in Apple's developer documentation:

  • which devices and OS versions are supported;
  • what context limit applies;
  • how to check on-device model availability at runtime.

Then measure latency on your oldest supported iPhone, as you would on Android. Until those answers are in place, a safe default is to route iOS requests through the backend Claude proxy. CLOUD_OK and consented ASK features then work on day one, and LOCAL_ONLY features stay hidden on iOS rather than leaking data.

FAQ

Does Gemini Nano work offline? Yes. Android documents that Nano delivers generative AI "without needing a network connection or sending data to the cloud" (Android Developers: Gemini Nano). Your app still has to handle phones where the model is unavailable.

Can an on-device model call tools? On Android, yes. ML Kit's AgentRunner automates multi-step tool-calling loops on top of GenerativeModel. For iOS, confirm tool support in Apple's documentation before designing around it.

What does a cloud fallback cost? At list prices, a 1,000-in / 100-out request on Claude Haiku 5.5 costs $0.00015. The same request on Sonnet 5.5 costs $0.003. Haiku prompts over 100,000 tokens pay the higher rate (Claude pricing).

Can the app call the Claude API directly? Avoid it. Any key shipped in an APK can be extracted. Call your own backend and keep the key there.

What if users need guaranteed local-only processing? Mark the feature LOCAL_ONLY. The router then fails closed and shows an unavailable state instead of sending data to a server.

Classify every AI feature before writing code

List every AI feature in the app and assign each one to on-device, cloud or hybrid. Give each feature a data policy (LOCAL_ONLY, CLOUD_OK or ASK), a measured token budget, a timeout and a defined offline state. Stand up the backend proxy before the first cloud call, and estimate cost per feature with the Haiku and Sonnet arithmetic above. Once that table exists, the router is short and the remaining decisions concern product behaviour, not plumbing.

For a related project, see MeetVerse AI — Mobile App.

Planning this for a production app? See AI Integration for Your App — ChatGPT, Claude & RAG.

Coffee cup

¿Te gustó este artículo?

Tu apoyo me ayuda a crear más contenido técnico detallado, herramientas de código abierto y recursos gratuitos para la comunidad de desarrolladores.

Temas Relacionados

Engr Mejba Ahmed

Engr Mejba Ahmed

Engr. Mejba Ahmed builds AI-powered applications and secure cloud systems for businesses worldwide. With 8+ years shipping production software in Laravel, Python, and AWS, he's helped companies automate workflows, reduce infrastructure costs, and scale without security headaches. He writes about practical AI integration, cloud architecture, and developer productivity.

Artículos Relacionados

Ver Todos

Comments

Leave a Comment

Share a question or add to the discussion.

Comments are moderated before appearing.

Learning Resources

Expand Your Knowledge

Accelerate your growth with structured courses, verified certificates, interactive flashcards, and production-ready AI agent skills.

Sample Certificate of Completion

Sample certificate — complete any course to earn yours

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by Claude

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support