Foundation Models Framework
Run Apple’s on-device language model from Swift — private, offline and free of API costs.
LanguageModelSession gives you a conversation with the on-device model. Instructions set the behavior; each respond(to:) call adds to the session transcript.
Always check SystemLanguageModel.default.availability — the model is unavailable on unsupported devices or when Apple Intelligence is turned off.
1import FoundationModels
2
3@MainActor
4@Observable
5final class SummaryModel {
6 var output = ""
7 private let session = LanguageModelSession(
8 instructions: "You summarize journal entries in two friendly sentences."
9 )
10
11 func summarize(_ text: String) async {
12 guard case .available = SystemLanguageModel.default.availability else {
13 output = "Apple Intelligence is not available on this device."
14 return
15 }
16 do {
17 let response = try await session.respond(to: text)
18 output = response.content
19 } catch {
20 output = "Could not summarize: \(error.localizedDescription)"
21 }
22 }
23}Common pitfalls
- The on-device model has a limited context window — summarize or trim long inputs.
- Design a graceful fallback UI for devices without Apple Intelligence.
Still unclear? Ask BeeAI about Foundation Models Framework.
Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.
Related topics
Get typed Swift structs back from the model instead of parsing free-form text.
Expose app actions to Siri, Spotlight, Shortcuts and Apple Intelligence with a small Swift type.
The modern replacement for ObservableObject/@Published — fine-grained updates with less boilerplate.
Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.
See Pro Plans