How do I use foundation models?
Asked on 2025-06-30
1 search
To use Foundation Models, you can leverage the Foundation Models framework introduced by Apple. This framework provides access to an on-device large language model with a convenient Swift API, available on macOS, iPadOS, iOS, and VisionOS. Here are some key steps and features to consider:
-
Import the Framework: Start by importing the Foundation Models framework into your project.
-
Create a Session: You need to create a session to interact with the model. This session can be customized with instructions to guide the model's behavior.
-
Prompt the Model: You can send prompts to the model to generate text or structured data. The model is optimized for tasks like text extraction, summarization, and more.
-
Use Generable and Guided Generation: For structured output, you can use the
Generable
macro to define types that the model can generate. Guided generation helps in producing structured data like JSON or CSV. -
Tool Calling: The framework supports tool calling, allowing the model to autonomously call functions you define, such as fetching data or performing actions within your app.
-
Privacy and Efficiency: Since the model runs on-device, it ensures user data privacy and can operate offline. The framework is optimized for performance using techniques like quantization and speculative decoding.
For a deeper understanding, you can explore sessions like Deep dive into the Foundation Models framework and Meet the Foundation Models framework. These sessions provide comprehensive insights into using the framework effectively.

Deep dive into the Foundation Models framework
Level up with the Foundation Models framework. Learn how guided generation works under the hood, and use guides, regexes, and generation schemas to get custom structured responses. We’ll show you how to use tool calling to let the model autonomously access external information and perform actions, for a personalized experience. To get the most out of this video, we recommend first watching “Meet the Foundation Models framework”.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

Code-along: Bring on-device AI to your app using the Foundation Models framework
Develop generative AI features for your SwiftUI apps using the Foundation Models framework. Get started by applying the basics of the framework to create an awesome feature. Watch step-by-step examples of how to complement the models with tools you build, stream results, and apply further optimizations for great performance.