Apple Foundation Models
backend-apple lets a Java 25 application use Apple’s on-device
SystemLanguageModel. The model is part of Apple Intelligence and is managed
and updated by the operating system. It is not a GGUF file and does not need a
ModelJar download.
The Java API crosses a three-function C ABI with the Foreign Function and Memory (FFM) API. A small Models-owned Swift binary calls Apple’s Foundation Models framework. No prompt or response is sent to Ollama, llama.cpp, or a hosted model provider. Every native call returns an owned result with an exact UTF-8 byte length and per-call error detail.
Requirements
-
A supported Apple Silicon Mac
-
Apple Intelligence available, enabled, and ready for the current user
-
Java 25
-
Native access enabled for the application
Always inspect availability() at runtime. Apple can report that a device is
ineligible, Apple Intelligence is disabled, or the model is not ready.
Dependency
dependencies {
implementation("com.integrallis:backend-apple:0.5.20")
}
Run the application with native access enabled:
java --enable-native-access=ALL-UNNAMED -jar application.jar
Generate Text
import com.integrallis.models.backend.apple.AppleFoundationModels;
import com.integrallis.models.backend.apple.AppleFoundationModelsRequest;
try (var client = AppleFoundationModels.create()) {
var availability = client.availability();
if (!availability.available()) {
throw new IllegalStateException(availability.reason());
}
var response = client.generate(
AppleFoundationModelsRequest.builder(
"Summarize why local inference protects private data.")
.instructions("Answer in one concise sentence.")
.maxOutputTokens(64)
.build());
System.out.println(response.text());
}
AppleFoundationModels.create() first checks macOS and Apple Silicon support,
then loads the packaged Swift bridge. The bridge checks
SystemLanguageModel.default.availability before creating a
LanguageModelSession.
Use Framework Adapters
AppleFoundationModelsClient implements Models' shared
TextGenerationModel contract. The existing LangChain4j and Spring AI
adapters therefore accept the Apple client directly.
For LangChain4j, add models-langchain4j and pass the checked client to
ModelsChatModel:
dependencies {
implementation("dev.langchain4j:langchain4j:1.17.2")
implementation("com.integrallis:backend-apple:0.5.20")
implementation("com.integrallis:models-langchain4j:0.5.20")
}
import com.integrallis.models.backend.apple.AppleFoundationModels;
import com.integrallis.models.langchain4j.ModelsChatModel;
try (var client = AppleFoundationModels.create()) {
if (!client.availability().available()) {
throw new IllegalStateException(client.availability().reason());
}
var chatModel = new ModelsChatModel(client);
String answer = chatModel.chat("Name one benefit of local inference.");
}
Spring AI uses the same contract:
dependencies {
implementation("org.springframework.ai:spring-ai-model:2.0.0")
implementation("com.integrallis:backend-apple:0.5.20")
implementation("com.integrallis:models-spring-ai:0.5.20")
}
import com.integrallis.models.backend.apple.AppleFoundationModels;
import com.integrallis.models.spring.ai.ModelsSpringAiChatModel;
try (var client = AppleFoundationModels.create()) {
if (!client.availability().available()) {
throw new IllegalStateException(client.availability().reason());
}
var chatModel = new ModelsSpringAiChatModel(client);
String answer = chatModel.call("Summarize the retrieved context.");
}
The current Apple bridge receives a complete response from
SystemLanguageModel. A framework streaming call therefore emits that response
as one event. maxTokens maps to Apple’s maximum-response-token option; Apple
owns the remaining sampling behavior.
The current bridge does not expose Apple’s guided-generation or tool-calling API. Registering Spring AI or LangChain4j tools with this backend is therefore unsupported until that native contract and its framework mapping are implemented and qualified.
Model Identity And Updates
Apple periodically updates SystemLanguageModel with operating-system
releases. That makes it different from a ModelJar, which pins one downloadable
artifact by revision, byte size, and SHA-256. Test application prompts on every
Apple model and OS version that the application supports.
The ModelJars catalog links to this backend as another local Models execution option, but it does not assign Maven model coordinates to Apple’s private, OS-managed weights.
Override The Bridge
For a source build or bridge-development run, point Models at a specific dynamic library:
bridge=/path/to/libjavamodels_apple_foundation.dylib
export MODELS_APPLE_FOUNDATION_LIBRARY="$bridge"
export MODELS_APPLE_FOUNDATION_LIBRARY_SHA256="$(
shasum -a 256 "$bridge" | cut -d ' ' -f 1
)"
The equivalent system properties are:
-Dmodels.apple.foundation.library=/path/to/libjavamodels_apple_foundation.dylib \
-Dmodels.apple.foundation.library.sha256=<64-hex-digit-sha256>
An explicit path takes precedence over the bridge packaged in
backend-apple. Models rejects the path if its SHA-256 is absent or does not
match. A bridge rebuilt during local development can opt out explicitly with
-Dmodels.apple.foundation.library.allow-unverified=true or
MODELS_APPLE_FOUNDATION_LIBRARY_ALLOW_UNVERIFIED=true.
The packaged bridge is also verified before loading. Models extracts it under a content-addressed, owner-controlled cache and rejects a configured cache root that is group or world writable.
Test Application Wiring
Stub mode exercises availability handling and Java application wiring without claiming to simulate Apple’s model output:
java \
--enable-native-access=ALL-UNNAMED \
-Dmodels.apple.foundation.mode=stub \
-jar application.jar
The real integration test still requires an eligible Apple Silicon Mac with a logged-in user session and Apple Intelligence enabled.
See Apple’s SystemLanguageModel documentation for platform availability and model-update behavior.
