Expand description
Safe Rust bindings for Apple’s FoundationModels on-device AI framework (Apple Intelligence).
§Overview
FoundationModels gives access to an on-device ≈3B-parameter language model that runs entirely locally — no network requests, no API keys, no data leaving the device.
This crate exposes the full session lifecycle:
- Availability checking —
is_available/availability - Single-shot generation — top-level
respond/respond_with_options - Session-based multi-turn generation —
Session::respond - Streaming —
Session::streamreturns aResponseStreamthat implementsfutures_core::Stream - Structured generation —
Session::respond_asreturns anyserde::Deserializetype - Streaming structured types —
Session::stream_structuredyields partial JSON chunks - Multimodal prompts —
Session::respond_with_attachmentsends images alongside text - Dynamic profile switching —
Session::update_profileswaps instructions mid-session - Tool calling —
Session::with_toolsregisters Rust closures the model can invoke
§Requirements
| Requirement | Value |
|---|---|
| macOS | 26 (Tahoe) or later |
| Hardware | Apple Silicon (M1 or later) |
| Setting | Apple Intelligence enabled in System Settings |
| Build tool | Xcode with the macOS 26 SDK |
On unsupported hardware or older macOS the crate still compiles and links; all APIs
return Error::Unavailable at runtime.
§Quick start
use rusty_foundationmodels::{is_available, respond};
if !is_available() {
eprintln!("Apple Intelligence not available on this device");
return Ok(());
}
let answer = respond("What is the capital of France?").await?;
println!("{answer}");§Multi-turn conversation
use rusty_foundationmodels::Session;
let session = Session::with_instructions("You are a concise Rust expert.")?;
let r1 = session.respond("What is ownership?").await?;
let r2 = session.respond("Give me a one-line example.").await?;
println!("{r1}\n{r2}");§Streaming
use rusty_foundationmodels::Session;
let session = Session::new()?;
let stream = session.stream("Tell me a short story.")?;§Structured generation
use serde::Deserialize;
use rusty_foundationmodels::{Session, Schema, SchemaProperty, SchemaPropertyType};
#[derive(Deserialize)]
struct CityInfo { name: String, population: f64, country: String }
let session = Session::new()?;
let schema = Schema::new("CityInfo")
.property(SchemaProperty::new("name", SchemaPropertyType::String))
.property(SchemaProperty::new("population", SchemaPropertyType::Double))
.property(SchemaProperty::new("country", SchemaPropertyType::String));
let info: CityInfo = session.respond_as("Describe Paris.", &schema).await?;
println!("{} has {} people", info.name, info.population);§Tool calling
use rusty_foundationmodels::{Session, ToolDefinition, Schema, SchemaProperty, SchemaPropertyType};
let tool = ToolDefinition::new(
"get_weather",
"Get current weather for a city",
Schema::new("GetWeatherArgs")
.property(SchemaProperty::new("city", SchemaPropertyType::String)
.description("City name")),
|args| {
let city = args["city"].as_str().unwrap_or("unknown");
Ok(format!("Weather in {city}: sunny, 72°F"))
},
);
let session = Session::with_tools("You are a weather assistant.", vec![tool])?;
let response = session.respond("What's the weather in Tokyo?").await?;
println!("{response}");Structs§
- Attachment
- A media attachment to include in a prompt.
- Generation
Options - Tuning parameters for a single generation request.
- Response
Stream - An async stream of text chunks produced by
Session::stream. - Response
Structured Stream - An async stream of JSON chunks produced by
Session::stream_structured. - Schema
- Describes the JSON object shape that the model must produce for structured generation.
- Schema
Property - A single property within a
Schema. - Session
- A stateful conversation session backed by a
LanguageModelSession. - Tool
Definition - A function that the model can invoke when responding to a prompt.
Enums§
- Error
- Errors returned by this crate.
- Schema
Property Type - The type of a single property in a
Schema. - Unavailability
Reason - Reasons why Apple Intelligence is not available on the current device.
Functions§
- availability
- Returns
Ok(())if Apple Intelligence is ready, or the specificUnavailabilityReason. - is_
available - Returns
trueif Apple Intelligence is available and ready on this device. - respond
- Sends a single prompt to the model and returns the response text.
- respond_
with_ options - Like
respondbut allows tuning generation viaGenerationOptions.