The built-in OS model
Rules
- The OS owns the weights, but the model is still installed — as an identity:
fileType: ModelFileType.builtIn with .fromBundled(...). The app downloads nothing.
- Call
BuiltInAi.ensureReady() before getActiveModel(), from a user action: the first call downloads the model and can take minutes, and on web the browser refuses to start that download without a user gesture. Call it straight from the tap handler, with no slow await in front of it. It throws TimeoutException after timeout — 10 minutes by default.
- On web,
ensureReady called outside a user gesture throws a BuiltInAiUnavailableException whose status is BuiltInAiAvailability.downloadable — in the log, LocalAiUserActivationRequiredException: Chrome only starts the Gemini Nano download inside a user gesture…, a subclass. The browser can run the model; it is waiting for a tap. Check e.status == BuiltInAiAvailability.downloadable first, ask the user to tap, and call ensureReady again from that tap handler. Do not fall back to a download here — the fallback below would fetch gigabytes the browser was about to provide.
- Catch
BuiltInAiUnavailableException with any other status and fall back to a downloadable model.
- Android apps need
minSdk 26, or the manifest merge fails, and Kotlin 2.3.21. The native layer, flutter_local_ai, no longer applies the Kotlin Gradle Plugin itself (since 0.2.0), so it does not block built-in Kotlin on AGP 9; other plugins in the app still may.
- Linux has no built-in model:
BuiltInAiModels.forCurrentPlatform is null there and BuiltInAi.availability() reports BuiltInAiAvailability.unavailableDeviceUnsupported. Windows runs Phi Silica through Windows AI Foundry on Copilot+ hardware, in a packaged app; a Windows build that could not resolve the Windows App SDK reports the same unavailable state, so the fallback below covers it.
Setup with a fallback
flutter pub add flutter_edge_ai flutter_edge_ai_builtin_ai flutter_edge_ai_litertlm
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter_edge_ai/flutter_edge_ai.dart';
import 'package:flutter_edge_ai_builtin_ai/flutter_edge_ai_builtin_ai.dart';
import 'package:flutter_edge_ai_litertlm/flutter_edge_ai_litertlm.dart';
await FlutterEdgeAi.initialize(
inferenceEngines: [BuiltInAiEngine(), LiteRtLmEngine()],
);
final spec = BuiltInAiModels.forCurrentPlatform; // null on Linux
Future<InferenceModel> downloadGemma() async {
// 2.6 GB (2.34 GB on web, which needs
// FlutterEdgeAi.initialize(webStorageMode: WebStorageMode.streaming)) — ask
// first. The catalog build is pinned to a Hugging Face commit; natively its
// size is checked before activation.
await FlutterEdgeAi.installModelFromCatalog(
kIsWeb
? LiteRtLmModels.gemma4E2bIt.webGpu
: LiteRtLmModels.gemma4E2bIt.generic,
).install();
return FlutterEdgeAi.getActiveModel(maxTokens: 1024);
}
InferenceModel model;
if (spec == null) {
model = await downloadGemma();
} else {
try {
// The first await in the tap handler: on web the browser starts the
// download only inside a user gesture, so nothing slow may run before it.
// onProgress reports real percentages on Android and the web; Apple
// downloads nothing and reports none — ensureReady just waits.
await BuiltInAi.ensureReady(onProgress: (int percent) => print('$percent%'));
await FlutterEdgeAi.installModel(
modelType: ModelType.general,
fileType: ModelFileType.builtIn,
).fromBundled(spec.name).install();
model = await FlutterEdgeAi.getActiveModel(maxTokens: 4096);
} on BuiltInAiUnavailableException catch (e) {
if (e.status == BuiltInAiAvailability.downloadable) {
// Web, called outside a user gesture. The browser can run the model:
// show an "Enable AI" button and call ensureReady from its handler.
return;
}
model = await downloadGemma();
} on TimeoutException {
model = await downloadGemma();
}
}
The latest install is the one getActiveModel loads, so the fallback replaces the built-in model. Sessions and chats then work as in the flutter-edge-ai-inference skill.
Checking before offering the feature
final availability = await BuiltInAi.availability();
final usable = availability == BuiltInAiAvailability.available ||
availability == BuiltInAiAvailability.downloadable ||
availability == BuiltInAiAvailability.downloading;
downloadable and downloading mean "not yet" — ensureReady finishes the job. The unavailable* states describe the device now, not forever:
| State | Meaning |
|---|
BuiltInAiAvailability.unavailableDeviceUnsupported | the hardware cannot run it — and on web, that the browser exposes no Prompt API at all, including desktop Chrome before 148 with neither the flag nor an origin-trial token |
BuiltInAiAvailability.unavailableOsTooOld | an OS update would enable it; on Apple the floor is OS 26 |
BuiltInAiAvailability.unavailableDisabled | the user can turn it on in system settings (Apple Intelligence on Apple devices) |
BuiltInAiAvailability.unavailableOther | anything else: a probe that timed out after 20 seconds, or Chrome's reasonless "unavailable", which in practice is its disk and VRAM floor — worth asking again later |
| Platform | Model | Needs |
|---|
| Android | Gemini Nano (AICore) | a device on Google's Prompt API device list; minSdk 26 |
| iOS, macOS | Apple Foundation Models | iOS 26+ / macOS 26+ on an iPhone 15 Pro or newer, or an Apple Silicon Mac, with Apple Intelligence on; below OS 26 it reports unavailableOsTooOld. flutter_local_ai builds from iOS 13 / macOS 12; with core the app needs iOS 15.0 and a macOS 12.0 deployment target — 14.0 with flutter_edge_ai_litertlm, as in the fallback above |
| Windows | Phi Silica (Windows AI Foundry) | Windows 11 25H2+ on a Copilot+ PC or a supported GPU, in a packaged app. Streams one final chunk and ignores maxOutputTokens |
| Web | Gemini Nano (Chrome Prompt API) | desktop Chrome 148+ — not mobile browsers, Firefox or Safari |
| Web | Phi-4-mini (Edge Prompt API) | Microsoft Edge with the Prompt API flag on; Edge Dev 154–155 exposes the API but cannot run the model |
Images work on Android, one per message, and only when asked for: pass supportImage: true to getActiveModel (getActiveModel(maxTokens: 4096, supportImage: true)); chats from openChat and sessions inherit it. An image sent to a model loaded without it throws UnsupportedError. Windows and web are text-only, and Apple is text-only on OS 26: supportImage: true there fails when getActiveModel creates the model, not mid-conversation — so do not build an image path there.
Web
There is no script to add: the Prompt API is part of the browser.
- Chrome — since Chrome 148 the Prompt API is available to ordinary web pages: no origin-trial token and no
chrome://flags entry.
- Microsoft Edge — enable
edge://flags → "Prompt API for on-device language model" and restart. Both browsers use BuiltInAiModels.chromePromptApi, which is what forCurrentPlatform returns on web: the spec names the API, and the browser picks the model.
- Sampling — on web,
topP and maxOutputTokens are ignored (warned once); on web pages Chrome ignores temperature and topK too (they work in Chrome Extensions only) and logs a deprecation warning, so a topK: 1 there is not greedy.
Trade-offs
No choice of weights, no LoRA, and capabilities that vary by OS version. The right pick when zero download and zero disk matter more than choosing the model.
Tool calls go through the prompt on every platform. The flutter_edge_ai
responseFormat path is implemented but no built-in platform is qualified in
this release: model.structuredOutputSupport.isSupported is false and
openSession / openChat(responseFormat: ...) throw
ResponseFormatUnsupportedException on Apple, Chrome, Windows and Android.
Android has no bridged runtime-schema API; Apple, Chrome and Windows remain
gated until their own runs pass. Platform-native tool and structured APIs that
flutter_local_ai exposes remain reachable through
BuiltInAiModel.localAiModel / BuiltInAiSession.localAiSession
(@experimental).
When a built-in platform is eventually enabled, its flutter_edge_ai structured
reply is buffered as one final chunk and supports only the keywords reported by
structuredOutputSupport; model.refusalFor(format) can still reject a
particular schema. On Apple, responseFormat together with maxOutputTokens is
also refused at openSession / openChat even if refusalFor(format) returns
null, because the platform cannot report that the cap cut the value.