Skip to main content

@stewmore/expo-ai-apple-foundation-models

Apple Foundation Models provider for the Expo AI Runtime: the on-device model (iOS 26+) and, opt-in, Apple Private Cloud Compute (iOS 27+).

Install & use​

import { ExpoAI } from '@stewmore/expo-ai-core';
import '@stewmore/expo-ai-apple-foundation-models'; // registers the iOS adapters (side-effect import)

const caps = await ExpoAI.getCapabilities();
if (caps.available && caps.provider === 'apple-foundation-models') {
const result = await ExpoAI.generate({ prompt: 'Write a haiku about Swift.' });
console.log(result.text); // privacy: on-device
}

Config plugin​

The native module autolinks on its own, but add the config plugin so expo prebuild also sets the iOS deployment target the pod needs:

app.json
{
"expo": {
"plugins": [
[
"@stewmore/expo-ai-apple-foundation-models",
{ "iosDeploymentTarget": "16.4", "privateCloudCompute": true }
]
]
}
}
  • iosDeploymentTarget — optional; defaults to 15.1, the pod minimum.
  • privateCloudCompute — optional; opts in to Private Cloud Compute.

Requirements​

  • iOS / iPadOS 26+ on an Apple Intelligence–capable device with Apple Intelligence enabled.
  • A development build (custom native code — not Expo Go): npx expo prebuild && npx expo run:ios.

On unsupported OS/devices the adapter reports available: false with a reason (unsupported_os_version, unsupported_device, apple_intelligence_disabled, model_initializing, unsupported_locale), so the runtime can fall back per the app's policy. Availability also reports supportedLanguages and the model's real contextWindow (only in apps built with the iOS 27 SDK, Xcode 27+), and is re-checked when the app returns to the foreground, firing ExpoAI.onAvailabilityChange for both the on-device and PCC providers.

What it maps​

RuntimeFoundation Models
generateLanguageModelSession.respond(to:options:)
streamLanguageModelSession.streamResponse(...) (cumulative snapshots → token deltas)
generateObjectguided generation: respond(to:schema:) with a DynamicGenerationSchema
createSessionnative stateful LanguageModelSession (generateInSession / resetSession / disposeSession)
signal (abort)cancels the native task
prewarmLanguageModelSession.prewarm(promptPrefix:)
capability detectionSystemLanguageModel.availability, supportedLanguages, contextSize
usageprovider token counts on iOS 27+; source: 'unavailable' below
errorsGenerationError / LanguageModelError → ExpoAIError

Guided generation supports a subset of JSON Schema; see structured output. With the default structuredOutput: 'auto', an unsupported schema falls back to the JSON prompt. Summarize, rewrite, and proofread are provided by the core runtime over generate.

Token counting​

import { countTokens } from '@stewmore/expo-ai-apple-foundation-models';

const tokens = await countTokens(longText); // number, or null where unsupported

countTokens returns null below iOS 26.4, and on any iOS version in an app built with a pre-iOS 27 SDK (Xcode 26.x). contextWindow is likewise omitted from those builds.

Private Cloud Compute​

Apple Private Cloud Compute (PCC) runs a larger Apple model off-device. It registers as the apple-private-cloud-compute provider and is opt-in:

app.json
{
"expo": {
"plugins": [["@stewmore/expo-ai-apple-foundation-models", { "privateCloudCompute": true }]]
}
}

The plugin adds the PCC entitlement and an ExpoAIPrivateCloudCompute Info.plist marker. Without the option, PCC reports entitlement_missing.

Unverified entitlement

The entitlement key (com.apple.developer.private-cloud-compute) has not yet been confirmed on a device. Check it against Apple's current documentation before you ship.

PCC requires iOS 27+. It is off-device, so the router uses it only when requested explicitly or when fallback is not 'none'. Unlike a third-party cloud, it stays permitted for sensitive prompts:

const result = await ExpoAI.generate({
provider: 'apple-private-cloud-compute',
prompt: 'Draft a detailed project plan.',
reasoningLevel: 'deep', // 'light' | 'moderate' | 'deep'; PCC only
});
result.privacy.privacyMode; // 'apple-private-cloud-compute'

PCC has a usage quota. When it runs out, availability reports quota_exhausted. With fallback: 'none' requests then fail with QUOTA_EXHAUSTED. With another fallback the router skips PCC and tries the next allowed provider, as it does for any unavailable provider.

import { getPCCQuota, showPCCLimitIncrease } from '@stewmore/expo-ai-apple-foundation-models';

const quota = await getPCCQuota();
// { status: 'below_limit' | 'limit_reached', isApproachingLimit, resetDate (ms) | null,
// canRequestLimitIncrease } — or null when PCC isn't configured or supported
if (quota?.status === 'limit_reached' && quota.canRequestLimitIncrease) {
await showPCCLimitIncrease(); // presents Apple's sheet; resolves false if it can't be shown
}

PCC-specific errors: QUOTA_EXHAUSTED, NETWORK_UNAVAILABLE, SERVICE_UNAVAILABLE, and ENTITLEMENT_MISSING. None of them recommend fallback: thrown mid-request, they stop routing. A quota or entitlement problem caught at the availability check only skips PCC.