Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class SystemLlmClient
An LlmClient backed by the language model the operating system ships:
Apple’s Foundation Models (Apple Intelligence) on iOS and macOS, and Gemini
Nano through ML Kit GenAI on Android. Create one with LlmClient.system().
Nothing leaves the device, nothing is bundled with the application, and the OS keeps the model up to date. In exchange the model is small, and whether it exists at all depends on the device, the OS version and the user’s settings, so an application asks first:
SystemLlmClient llm = LlmClient.system();
SystemLlmStatus s = SystemLlmClient.getStatus(SystemLlmFeature.CHAT);
if (s == SystemLlmStatus.DOWNLOADABLE) {
llm.download(SystemLlmFeature.CHAT);
} else if (s.isAvailable()) {
llm.chat(ChatRequest.builder()
.addMessage(ChatMessage.user("Suggest a title for this note: ..."))
.build()).ready(r -> Log.p(r.getText()));
}Each capability is answered separately (SystemLlmFeature): a device can
summarize without accepting images in chat. Besides chat(ChatRequest),
the client has summarize(String, int), proofread(String),
rewrite(String, RewriteStyle) and [#describeImage(byte[])]. On Android
these use ML Kit’s dedicated task models; on Apple platforms they are
prompts to the same general model.
Availability
- iOS and macOS 26 or newer, on a device with Apple Intelligence turned
on. Images are not accepted. Older OS versions answer
SystemLlmStatus.UNSUPPORTED, as do applications built with an Xcode that predates Foundation Models. - Android 8 or newer, on a device AICore supports with Gemini Nano –
recent Pixel, Samsung Galaxy and other flagship phones. Using this class
raises the application’s minimum SDK to 23; older
Android versions report
SystemLlmStatus.UNSUPPORTED. - Everywhere else, the simulator included, every feature is
SystemLlmStatus.UNSUPPORTEDand requests fail withLlmException.ErrorType.INVALID_REQUEST. UseLlmClient.ollama()to develop against a local model on the desktop.
The builders add the platform bridge only to applications that call
LlmClient.system(); an application that checks the status here without
ever calling it has no bridge and is told SystemLlmStatus.UNSUPPORTED.
A request’s seed has no effect on Apple platforms, whose model takes none.
Tools, ResponseFormat.JSON_OBJECT and embeddings are not supported
and fail the request with LlmException.ErrorType.INVALID_REQUEST.
Requests run one at a time on a background thread, in the order they were made. Results and streaming callbacks arrive on the EDT.
Methods
Inherited fields
Inherited methods
Method details
isSupported
public static boolean isSupported()checkStatus(SystemLlmFeature) on the EDT.Returns
getStatus
public static SystemLlmStatus getStatus(SystemLlmFeature feature)checkStatus(SystemLlmFeature) on the EDT.Parameters
featureSystemLlmFeature- the capability
Returns
getStatusReason
public static String getStatusReason(SystemLlmFeature feature)Parameters
featureSystemLlmFeature- the capability
Returns
null when there is nothing to addcheckStatus
public static AsyncResource<SystemLlmStatus> checkStatus(SystemLlmFeature feature)Parameters
featureSystemLlmFeature- the capability
Returns
getSupportedFeatures
public static SystemLlmFeature[] getSupportedFeatures()Returns
getProvider
public String getProvider()apple-foundation-models or
gemini-nano, or none where there is none.Returns
download
public AsyncResource<Boolean> download(SystemLlmFeature feature)SystemLlmStatus.DOWNLOADABLE. On Android it completes when the
model is ready. Apple platforms download on their own: there it
completes at once, with true while the OS is still fetching the model
too, so check getStatus(SystemLlmFeature) before relying on it.Parameters
featureSystemLlmFeature- the capability
Returns
true, or fails with an LlmExceptionchat
public AsyncResource<ChatResponse> chat(ChatRequest req)chatStream with a no-op
listener but optimized – the provider skips the SSE response
and returns a single JSON object.Parameters
reqChatRequest- immutable chat request
Returns
chatStream
public AsyncResource<ChatResponse> chatStream(ChatRequest req, StreamingListener listener)listener fires for every content delta /
tool-call fragment on the EDT. The returned AsyncResource
completes with the aggregated final response once the stream
ends; cancel it to close the underlying socket.Parameters
reqChatRequest- immutable chat request
listenerStreamingListener- incremental callbacks delivered on the EDT
Returns
embed
public AsyncResource<EmbeddingResponse> embed(EmbeddingRequest req)LlmException.ErrorType.INVALID_REQUEST.Parameters
reqEmbeddingRequest- immutable embedding request
Returns
summarize
public AsyncResource<String> summarize(String text, int bullets)Parameters
textString- the text, an article or a conversation
bulletsint- how many bullet points, 1 to 3
Returns
proofread
public AsyncResource<String> proofread(String text)Parameters
textString- the text
Returns
rewrite
public AsyncResource<String> rewrite(String text, RewriteStyle style)Parameters
textString- the text
styleRewriteStyle- the style to rewrite it in
Returns
describeImage
public AsyncResource<String> describeImage(byte[] image)Parameters
imagebyte[]- an encoded PNG or JPEG
Returns
close
public void close()