◉RORK LABJP
●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SONNET 4.5 — Retires on the Claude API on 11/30, 26 days left. If your app calls it, check the migration target●SDK 58 — Moves to React Native 0.88. R8 is now on by default in Android release builds, and iOS prebuild generates a SceneDelegate●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SONNET 4.5 — Retires on the Claude API on 11/30, 26 days left. If your app calls it, check the migration target●SDK 58 — Moves to React Native 0.88. R8 is now on by default in Android release builds, and iOS prebuild generates a SceneDelegate●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…
Articles/AI Models
◉ AI Models/2026-06-13Advanced

Routing inference on-device first and escaping to the cloud only when it's worth it, in a Rork app

Build a tiered, fallback-based inference router in a Rork (Expo) app: cache to on-device to Private Cloud Compute to a remote API (Claude/Gemini). Working TypeScript covering budgets, timeouts, caching, and image routing.

Rork611On-device AIFoundation Models4React Native242Inference routerCost design

✦ Premium Article

The week WWDC26 wrapped, I was looking again at the cloud bill for a small "generate a one-line comment" feature in an app I run as an indie developer. A few hundred yen a month sounds trivial, but it scales linearly with users, and for a free app that's a quietly heavy fixed cost.

Then Apple's State of the Union landed: developers with fewer than two million first-time downloads can use Foundation Models on Private Cloud Compute for free, and the same Swift API is moving toward image input and server-side third-party models (Claude, Gemini). For the first time, "cheap things on-device for free, expensive things on a paid path" becomes a cost design you can actually build, not just talk about.

There's a catch: Rork generates production Expo (React Native) apps, and React Native can't reach Apple's on-device model directly. What you need is a single place that decides which inference goes down which path — an inference router. This article lays out that design with code you can run.

Why hitting a single API directly falls apart in production

My first naive version called a remote API with fetch per feature. It worked. The moment it hit real usage, several problems erupted at once.

  • The feature died completely offline (open the app on the subway, get an error)
  • The same input was billed every time (even for deterministic tasks like summaries)
  • Light and heavy tasks both flowed to the same expensive model
  • A sloppy retry double-billed me when a request re-fired after a timeout

A smarter model fixes none of this. The root cause is that route selection is scattered across your app logic. Pull it into one layer — the router — and fallback, budgeting, and caching all live inside that layer.

The fallback ladder

The structure I use is a ladder: try the cheap, fast path first and drop to the next rung when a path can't handle the task.

  1. Tier 0 — Cache: deterministic tasks (same input, same acceptable output) check a local cache first. A hit costs nothing and touches no network
  2. Tier 1 — On-device: short classification, summarization, and cleanup go to Foundation Models via a native module. Free, low latency, works offline
  3. Tier 2 — Private Cloud Compute: when on-device accuracy isn't enough but you don't want to pay a third party. Used within the free allowance
  4. Tier 3 — Remote API (Claude / Gemini): only the genuinely heavy work — multimodal with image input, or long high-quality generation

The concrete steps for implementing the on-device rung as a native module are covered separately in Using Apple FoundationModels in a Rork app. For framing the free allowance (PCC) as a three-tier cost design, see Rebuilding Rork AI cost as three tiers with the free Foundation Models.

The key is the assumption that each rung down is more expensive, so you try tasks from the top. Each task carries a floor — "this needs at least this rung" — and the router tries the cheapest rung at or above that floor.

✦

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
✦If you've held off on adding an AI feature because the API bill was unpredictable, you'll get a fallback design that keeps your monthly AI cost close to zero
✦You can paste in a typed router that decides what goes on-device, to PCC, or to a remote API based on task type and budget
✦You'll dodge the production-only traps — double billing on retries and races on app resume — before you hit them
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

Rork 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

◉ AI Models2026-08-07
Cutting MCP Tools Didn't Make Anything Lighter — 2,377 Bytes of Definitions vs 110,298 Bytes of Response
I wrote a minimal MCP server for a wallpaper catalog and measured the byte cost of tool definitions against the byte cost of responses. Here is which side actually matters, and the real reason to merge tools.
◉ AI Models2026-04-22
Rork × LiveKit: Production Voice Agent Infrastructure for AI-Powered Apps
Field notes on wiring LiveKit Agents into a Rork-generated React Native app: the agent server and token API, recovering from incoming calls and expired tokens, metered subscription billing, unit economics, and the monitoring queries that catch trouble before your users do.
◉ AI Models2026-10-29
Connected, but the Body Stops Halfway. Measuring Header-Only, Total, and Idle Timeouts on the Same Response
You added a timeout to fetch, yet the loading indicator never goes away. I reproduced a response whose body stalls halfway on a local server and measured header-only, total, and idle timeouts under identical conditions. Runnable test code included.