Native Tauri commands for Apple Intelligence (Foundation Models) with streaming, tool calling, Private Cloud Compute, reasoning, multimodal image input, and live token/context usage.
Companion JS transport: https://github.com/entro314-labs/apple-intelligence-sdk
[dependencies]
tauri-apple-intelligence = "0.6"| Capability | Command(s) | Notes |
|---|---|---|
| Availability (on-device) | apple_ai_check_availability |
Device eligible + Apple Intelligence enabled + model ready |
| Availability (Private Cloud Compute) | apple_ai_pcc_check_availability |
macOS 27+; larger, reasoning-capable, still private (no API key/bill) |
| Generate / stream | apple_ai_generate, apple_ai_stream, apple_ai_cancel_stream |
Basic, tools, and structured modes; model: "on-device" | "private-cloud", reasoningLevel, sampling (temperature incl. 0, topP, topK, seed), toolChoice (macOS 27), and per-message images |
| Context window | apple_ai_context_info |
Real contextSize per model (4k on-device, ~32k PCC) — stop hardcoding |
| Token counting | apple_ai_token_count |
Real tokenizer counts (tokenCount(for:), macOS 26.4+) for budgeting prompts against contextSize |
| Supported languages | apple_ai_supported_languages |
Live BCP-47 tags from SystemLanguageModel.supportedLanguages |
| Prewarm | apple_ai_prewarm |
Lower first-token latency; optional promptPrefix eagerly processes a known prompt prefix |
Generation results and streams carry a usage object (inputTokens, cachedInputTokens,
outputTokens, reasoningTokens) on macOS 27+.
Generation failures carry a stable machine-readable code mirroring the FoundationModels error
cases — context-window-exceeded, guardrail-violation, refusal, rate-limited,
concurrent-requests, and more. Non-streaming commands reject with
{ type: "generation", code, message, contextSize?, tokenCount? }; streams emit an error event
with the same fields. context-window-exceeded includes the model's contextSize and the
offending tokenCount (macOS 27+), so hosts can condense the conversation and retry — Apple's
documented recovery strategy for the context window.
Then register the commands in your tauri::Builder:
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
tauri_apple_intelligence::apple_ai_check_availability,
tauri_apple_intelligence::apple_ai_pcc_check_availability,
tauri_apple_intelligence::apple_ai_generate,
tauri_apple_intelligence::apple_ai_stream,
tauri_apple_intelligence::apple_ai_cancel_stream,
tauri_apple_intelligence::apple_ai_context_info,
tauri_apple_intelligence::apple_ai_token_count,
tauri_apple_intelligence::apple_ai_supported_languages,
tauri_apple_intelligence::apple_ai_prewarm,
])For the JavaScript side, use the companion npm package:
import {
createAppleIntelligenceProvider,
createTauriAppleIntelligenceTransport,
} from "@entro314labs/apple-intelligence-sdk";This crate ships a prebuilt libappleai.dylib in the prebuilt/ directory. You must bundle it into your Tauri app resources so the linker and runtime can find it.
Recommended flow in your Tauri app:
- Copy the prebuilt dylib into your app's
src-tauri/resources/folder during the build. - Reference it in
tauri.conf.jsonunderbundle.resources.
There are two common ways to automate the copy step:
- App build script: use your app's
src-tauri/build.rs(not this crate) to copyprebuilt/libappleai.dylibintosrc-tauri/resources/. - Before-build hook: add a small script (Node/Bash) and call it from
tauri.conf.json'sbuild.beforeBuildCommandor your package manager's build pipeline.
If you want, the copy script can locate this crate via cargo metadata and copy the dylib from the Cargo registry to your app's resources folder.
This crate expects a libappleai.dylib (Foundation Models bridge) to be linked into your Tauri app.
Make sure the dylib is bundled as a resource and that the linker can resolve it at runtime.
The JS transport expects apple_ai_* command names by default. If you rename the commands or use a different prefix, update the JS transport's commandPrefix option.
- ✅ macOS 26+ on Apple Silicon (on-device model, streaming, tools, structured output, sampling modes, typed error codes)
- ✅ macOS 26.4+ adds
apple_ai_token_count(tokenCount(for:)) - ✅ macOS 27+ adds Private Cloud Compute, reasoning levels, multimodal image input, per-call
token usage, native
toolChoiceenforcement, and context-size details oncontext-window-exceedederrors — all gated behind@available, so the crate still runs on macOS 26 with those features simply unavailable - ❌ Other platforms (returns
UnsupportedPlatform)
MIT