Skip to content

Model Configuration

SystemLanguageModel is the entry point for accessing the on-device model. It wraps Apple's Foundation Models framework and provides availability checking before you create sessions.

Creating a Model

ts
import {
  SystemLanguageModel,
  SystemLanguageModelUseCase,
  SystemLanguageModelGuardrails,
} from "tsfm-sdk";

const model = new SystemLanguageModel({
  useCase: SystemLanguageModelUseCase.GENERAL,
  guardrails: SystemLanguageModelGuardrails.DEFAULT,
});

Both options are optional and default to the values shown above.

Use Cases

ValueDescription
GENERALGeneral-purpose text generation (default)
CONTENT_TAGGINGOptimized for classification and labeling
ts
const tagger = new SystemLanguageModel({
  useCase: SystemLanguageModelUseCase.CONTENT_TAGGING,
});

Checking Availability

The model may not be available if Apple Intelligence is disabled, assets haven't been downloaded, or the device doesn't support it.

Synchronous Check

ts
const { available, reason } = model.isAvailable();
if (!available) {
  console.log("Unavailable:", reason);
}

Waiting for Availability

waitUntilAvailable() polls until the model is ready (default 30 seconds):

ts
const { available } = await model.waitUntilAvailable();
const { available } = await model.waitUntilAvailable(10_000); // custom timeout

Unavailability Reasons

When available is false, the reason field indicates why:

ReasonDescription
APPLE_INTELLIGENCE_NOT_ENABLEDApple Intelligence is turned off in Settings
MODEL_NOT_READYModel assets are still downloading
DEVICE_NOT_ELIGIBLEHardware doesn't support Foundation Models

Cleanup

Release native resources when you're done with the model:

ts
model.dispose();

Released under the Apache 2.0 License.