Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class SystemLlmClient

  1. Object
  2. LlmClient
  3. 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.UNSUPPORTED and requests fail with LlmException.ErrorType.INVALID_REQUEST. Use LlmClient.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

public static boolean isSupported()Whether this device can chat with an OS model, now or after a download.
public static SystemLlmStatus getStatus(SystemLlmFeature feature)Asks the OS what it can do for a feature.
public static String getStatusReason(SystemLlmFeature feature)Explains the status of a feature: why it is unsupported or disabled.
public static AsyncResource<SystemLlmStatus> checkStatus(SystemLlmFeature feature)Asks the OS what it can do for a feature without blocking the caller.
public static SystemLlmFeature[] getSupportedFeatures()Every feature this device supports, now or after a download.
public String getProvider()The model behind this client, such as apple-foundation-models or gemini-nano, or none where there is none.
public AsyncResource<Boolean> download(SystemLlmFeature feature)Asks the OS to download the model behind a feature, for a status of SystemLlmStatus.DOWNLOADABLE.
public AsyncResource<ChatResponse> chat(ChatRequest req)Non-streaming chat.
public AsyncResource<ChatResponse> chatStream(ChatRequest req, StreamingListener listener)Streaming chat.
public AsyncResource<EmbeddingResponse> embed(EmbeddingRequest req)Embeddings are not offered by OS models; always fails with LlmException.ErrorType.INVALID_REQUEST.
public AsyncResource<String> summarize(String text, int bullets)Summarizes a text.
public AsyncResource<String> proofread(String text)Corrects grammar and spelling, keeping the meaning and the voice.
public AsyncResource<String> rewrite(String text, RewriteStyle style)Rewrites a text in another style.
public AsyncResource<String> describeImage(byte[] image)Describes an image in a sentence or two, for example as alternative text.
public void close()Stops the worker thread.

Inherited fields

Inherited methods

Method details

isSupported

public static boolean isSupported()
Whether this device can chat with an OS model, now or after a download. Blocks briefly while the OS is asked; prefer checkStatus(SystemLlmFeature) on the EDT.

Returns

getStatus

public static SystemLlmStatus getStatus(SystemLlmFeature feature)
Asks the OS what it can do for a feature. Blocks briefly while the OS answers; prefer checkStatus(SystemLlmFeature) on the EDT.

Parameters

feature SystemLlmFeature
the capability

Returns

its status on this device

getStatusReason

public static String getStatusReason(SystemLlmFeature feature)
Explains the status of a feature: why it is unsupported or disabled.

Parameters

feature SystemLlmFeature
the capability

Returns

a human readable reason, or null when there is nothing to add

checkStatus

public static AsyncResource<SystemLlmStatus> checkStatus(SystemLlmFeature feature)
Asks the OS what it can do for a feature without blocking the caller.

Parameters

feature SystemLlmFeature
the capability

Returns

the status, delivered on the EDT

getSupportedFeatures

public static SystemLlmFeature[] getSupportedFeatures()
Every feature this device supports, now or after a download. Blocks briefly while the OS is asked.

Returns

the supported features, in declaration order

getProvider

public String getProvider()
The model behind this client, such as apple-foundation-models or gemini-nano, or none where there is none.

Returns

stable provider family id

download

public AsyncResource<Boolean> download(SystemLlmFeature feature)
Asks the OS to download the model behind a feature, for a status of 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

feature SystemLlmFeature
the capability

Returns

completes with true, or fails with an LlmException

chat

public AsyncResource<ChatResponse> chat(ChatRequest req)
Non-streaming chat. Equivalent to chatStream with a no-op listener but optimized – the provider skips the SSE response and returns a single JSON object.

Parameters

req ChatRequest
immutable chat request

Returns

asynchronous normalized provider response

chatStream

public AsyncResource<ChatResponse> chatStream(ChatRequest req, StreamingListener listener)
Streaming chat. 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

req ChatRequest
immutable chat request
listener StreamingListener
incremental callbacks delivered on the EDT

Returns

asynchronous aggregated response

embed

public AsyncResource<EmbeddingResponse> embed(EmbeddingRequest req)
Embeddings are not offered by OS models; always fails with LlmException.ErrorType.INVALID_REQUEST.

Parameters

req EmbeddingRequest
immutable embedding request

Returns

asynchronous normalized embedding response

summarize

public AsyncResource<String> summarize(String text, int bullets)
Summarizes a text.

Parameters

text String
the text, an article or a conversation
bullets int
how many bullet points, 1 to 3

Returns

the summary

proofread

public AsyncResource<String> proofread(String text)
Corrects grammar and spelling, keeping the meaning and the voice.

Parameters

text String
the text

Returns

the corrected text

rewrite

public AsyncResource<String> rewrite(String text, RewriteStyle style)
Rewrites a text in another style.

Parameters

text String
the text
style RewriteStyle
the style to rewrite it in

Returns

the rewritten text

describeImage

public AsyncResource<String> describeImage(byte[] image)
Describes an image in a sentence or two, for example as alternative text.

Parameters

image byte[]
an encoded PNG or JPEG

Returns

the description

close

public void close()
Stops the worker thread. Requests already queued still run first.