class

Fm::SystemLanguageModel

Inherits Reference < Object

The system language model provided by Apple Intelligence.

This is the main entry point for using on-device AI capabilities.

model = Fm::SystemLanguageModel.new
if model.available?
  puts "Model is ready!"
end

You can also specify use case and guardrails:

model = Fm::SystemLanguageModel.new(
  use_case: Fm::UseCase::ContentTagging,
  guardrails: Fm::Guardrails::PermissiveContentTransformations
)

Constructors

new(*, use_case : UseCase = UseCase::General, guardrails : Guardrails = Guardrails::Default)
Source

Instance methods

availability

Gets the current availability status of the model.

Source
available?

Checks if the model is available for use.

Source
ensure_available!

Raises an error if the model is not available.

Source
finalize
Source
to_unsafe

Returns the raw pointer to the underlying Swift object. :nodoc:

Source
token_usage_for(prompt : String) : Int64 | Nil

Returns the token usage for a given prompt string.

Requires macOS 26.4+ at runtime. Returns nil if the API is unavailable on the current OS version.

if tokens = model.token_usage_for("Hello, world!")
  puts "Tokens: #{tokens}"
end
Source
token_usage_for_tools(instructions : String, tools_json : String | Nil = nil) : Int64 | Nil

Returns the token usage for instructions and tools configuration.

Requires macOS 26.4+ at runtime. Returns nil if the API is unavailable on the current OS version.

if tokens = model.token_usage_for_tools("Be helpful.", tools_json)
  puts "Tokens: #{tokens}"
end
Source
wait_until_available(timeout : Time::Span) : Nil

Blocks until the model becomes available or the timeout expires. Useful when the model is still downloading (ModelNotReady).

Raises TimeoutError if the model is still not available after the given timeout.

model = Fm::SystemLanguageModel.new
model.wait_until_available(timeout: 60.seconds)
puts "Model is ready!"
Source