◉GEMINI LABJP
●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer
Articles/API / SDK
◈ API / SDK/2026-07-03Advanced

Building AI-Powered iOS and Android Apps with the Gemini API — Image Recognition, Voice Analysis, Chat, and Monetization

Architecture, working code, and monetization for adding image recognition, voice analysis, and AI chat to iOS/Android apps — rewritten in November 2026 for @google/genai and gemini-4-hydrogen, with an error triage table, a cost formula, and API key restriction checks.

gemini-api291iOS13Android12mobile-app3image-recognitionvoice-analysisAI-featuresSwift3Kotlinmonetization21

✦ Premium Article

Setup and context — Where the API Call Lives Decides Everything After

The night I tried to bolt image tagging onto my wallpaper app, I got a prototype working by calling Gemini straight from the client. The next morning I unpacked that test build to look inside, found the key sitting there as a plain string, and just stopped for a while. I'd been so relieved that it worked that I never made the placement decision at all.

Understanding images, listening to audio, holding a conversation with context — an indie developer can wire all of that up with one API today. That is exactly why the first architecture call matters: get it wrong and you rebuild for cost and security later.

When I first retrofitted AI features into one of my own apps as an indie developer, the hardest question was not the implementation itself — it was where the API call should live. Call Gemini directly from the client, or route everything through a proxy? Get that decision wrong and you end up rebuilding for both cost and security reasons later. This article works through that decision for iOS (Swift) and Android (Kotlin), then moves on to concrete code, cost optimization, privacy, and monetization, in the order you would actually build a production app. Keys live on the server; models are routed per feature. Every code sample below sits on that line.

This article assumes you have iOS or Android development experience and a basic familiarity with the Gemini API. Each code sample starts with what it solves, so you can follow along even if you've never integrated an AI API before.

Three Things to Rewrite First (as of November 2026)

I published this in July 2026 and reworked it in November. These are the three patterns you are most likely to inherit from older samples — all checked against official sources as of November 2026.

ItemOld patternCurrent patternWhy
Node.js SDKGoogleGenerativeAI from @google/generative-aiGoogleGenAI from @google/genai (ai.models.generateContent)The old repo was renamed to deprecated-generative-ai-js and is marked deprecated
Python SDKgoogle-generativeai (genai.configure)google-genai (genai.Client())Likewise moved to deprecated-generative-ai-python
Workhorse modelgemini-2.5-flashgemini-4-hydrogen (GA 2026-11-12, paid tier $1.50 / $7.50 per 1M tokens, free tier available)Gemini API changelog. Several forum reports describe 2.5 Flash returning 404 before its announced shutdown date
Firebase FunctionsrunWith via import * as functions from "firebase-functions"Import from firebase-functions/v1 if you keep the 1st-gen styleSince firebase-functions v6 the top-level default is the 2nd-gen API

One misconception worth correcting up front: swapping the model name does not finish the migration. The new SDK also changes how you read the response (result.response.text() becomes response.text) and how chat history is passed. All code below uses the new SDK.


Chapter 1: Designing Your Mobile AI Architecture

Server-Side vs. On-Device — Making the Right Call

The first design decision you'll face is whether to process AI workloads server-side via the Gemini API, or on-device using a local model like Gemma. Each has clear strengths.

Choose Gemini API (server-side) when:

  • High accuracy image, video, or audio analysis is required
  • Conversations involve long context windows (1,000+ tokens)
  • You need multimodal input (image + text combinations)
  • You want to monetize the AI feature as a premium offering
  • You need model updates to reach users instantly

Choose on-device processing when:

  • Offline functionality is non-negotiable
  • You need ultra-low latency for real-time interactions
  • Privacy requirements prevent sending data to a server
  • The task is lightweight — simple text classification, basic sentiment

Most production apps benefit from a hybrid approach: handle lightweight tasks on-device and reach out to the Gemini API only for complex analysis. This controls costs while keeping the user experience smooth.

Recommended Architecture for Indie Developers

Here is a clean, scalable architecture that works well for solo developers.

[Mobile App]
    ↓  HTTPS (certificate pinning)
[Backend API Server]  ← Firebase Functions / Cloudflare Workers
    ↓  API key (server-held — never in the app binary)
[Gemini API]
    ↓
[Response processing]
    ↓
[Mobile App (display)]

Critical rule: Never embed your API key in your app binary. Both App Store and Play Store apps can be reverse-engineered, and an exposed key will be abused. Always route through a backend proxy that validates authenticated user requests before forwarding to the Gemini API.

Firebase Backend Setup

Firebase Functions combined with Firebase Authentication gives indie developers a secure, low-cost backend that scales automatically.

// Firebase Functions: gemini-proxy.ts
// deps: npm i @google/genai firebase-functions firebase-admin
import * as functions from "firebase-functions/v1"; // v1 import keeps the 1st-gen runWith API
import * as admin from "firebase-admin";
import { GoogleGenAI } from "@google/genai";
 
admin.initializeApp();
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY! });
const MODEL = process.env.GEMINI_MODEL ?? "gemini-4-hydrogen"; // keep the model swappable via env
 
export const analyzeImage = functions
  .runWith({ memory: "512MB", timeoutSeconds: 60 })
  .https.onCall(async (data, context) => {
    // Reject unauthenticated requests
    if (!context.auth) {
      throw new functions.https.HttpsError(
        "unauthenticated",
        "Authentication required"
      );
    }
 
    const { imageBase64, prompt } = data;
 
    const response = await ai.models.generateContent({
      model: MODEL,
      contents: [
        {
          role: "user",
          parts: [
            { inlineData: { data: imageBase64, mimeType: "image/jpeg" } },
            { text: prompt },
          ],
        },
      ],
    });
 
    // The new SDK exposes text as a property, not a method
    return { text: response.text ?? "" };
  });

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Architecture decisions and working code for unifying image, voice, and chat behind a single proxy
✦A formula that turns DAU and call counts into a monthly bill, plus real numbers from routing classification calls to a lighter model
✦A five-item pre-release checklist for the mandatory API key restriction change from June 2026
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

◈ API / SDK2026-05-13
Maximizing Revenue in Indie iOS Wallpaper Apps with AdMob + Gemini API
A decade of indie app development reveals how to balance AdMob revenue against Gemini API costs. Learn architecture patterns, cost control strategies, and Freemium gate implementation for AI-powered wallpaper apps.
◈ API / SDK2026-05-15
Building an AI Chat App with Expo and Gemini API: From First Commit to App Store Approval
An implementation record of shipping an Expo + Gemini API chat app through both store reviews — measured streaming latency, the chunk-boundary JSON bug, image payload limits, cost ceilings, and the pre-release checklist I run.
◈ API / SDK2026-10-22
Before You Swap in gemini-4-argon, Search Your Own Code for What to Remove
Four habits can break or silently change when you move to gemini-4-argon: explicit caches, sampling parameters, small max_output_tokens and short timeouts. A stdlib-only script finds them in your repository, with what to check after the swap and when to stay on Flash.