AI · 23 November 2026 · 6 min read

Adding On-Device AI to an iOS App with Apple’s Foundation Models Framework

Apple’s Foundation Models framework gives Swift apps direct access to the on-device language model behind Apple Intelligence. It runs on the device, so there is no server to build for basic features. This guide, based on Apple’s documentation, explains what the model is good at, how guided generation and tool calling work, and the limits you should design around before you promise an AI feature.

What the framework actually gives you

The Foundation Models framework lets an app prompt the large language model that powers Apple Intelligence. According to Apple, the on-device model suits text generation and understanding tasks such as summarization, entity extraction, text refinement, classification, tag generation and dialog for games. When a task needs more reasoning or a larger context, Apple points to Private Cloud Compute or any server model provider.

This is a different decision from the one we cover in our guide to on-device versus cloud AI. The framework is not a replacement for a large cloud model. It is a small, fast, private model that is already on the phone, which makes it a good fit for features that should feel instant and keep user content on the device.

Good tasks and bad tasks for the on-device model

Apple is unusually direct about what the model should not be used for. Its documentation lists basic math, code generation and logical reasoning as capabilities to avoid. Complex tasks can still work if you use guided generation or tool calling, but you should test them instead of assuming.

A useful way to scope a feature is to ask whether a short, bounded text transformation solves the user’s problem. If it does, the model is probably a good fit.

  • Good fit: summarize a note, extract people and places from text, suggest tags, rewrite a message in another tone, generate a line of game dialog.
  • Poor fit: calculate a total, write code, answer questions that need world knowledge, or reason through multi-step logic.
  • Always provide a non-AI path, because the model is not available on every device.

Check availability before you show the feature

Model availability depends on whether the device and the region support Apple Intelligence. Apple’s guidance is to check availability first and plan a fallback experience. The availability status reports why the model cannot be used: the device is not eligible, Apple Intelligence is not enabled, or the model is not ready. The last case matters, because the model can take time to download after a person turns Apple Intelligence on.

In practice this means three different screens or states. A person with an ineligible device should simply not see the feature, or see a conventional alternative. A person who has not enabled Apple Intelligence may need a short explanation. A person whose model is still downloading should see a temporary state, not an error.

Sessions, instructions and prompts

You talk to the model through a session. For a single-turn interaction Apple recommends creating a new session each time. For a multi-turn conversation you reuse the same session so the model keeps context. A session handles one request at a time, and calling it again before the previous request finishes causes a runtime error, so you need to check whether it is still responding.

Instructions and prompts have different jobs. Instructions set the role, the task and the style, and the model follows them at a higher priority than the prompt. Apple recommends using only trusted content in instructions. Prompts should be conversational, focus on one specific task and, when you want speed, say how much to produce. Asking for three sentences or a single sentence shortens generation time compared with an open request that produces an essay.

Guided generation: typed output instead of parsing strings

Raw model output is a string, and parsing strings is where many AI features break. Guided generation lets you describe the output as a Swift type. You mark the type as generable and add short descriptions or constraints to its properties. The framework uses constrained sampling, so the model cannot produce malformed output for that type, and you receive an instance of your own struct instead of text to parse.

Two details from Apple’s documentation are worth remembering. Properties are generated in the order you declare them, so put the information that later fields depend on first. And descriptions should be as short as possible, because long descriptions use context and add latency. If you only know the shape of the output at runtime, for example a restaurant whose menu is loaded from a server, a dynamic schema lets you build the structure on the fly.

Tool calling: connect the model to your app’s data

The model only knows what is in its training and in the session. Tools let it fetch current information or perform actions in your app, for example querying your local database or changing a setting. You define a tool with the arguments it accepts and a method the model can call. When the model decides a tool will help, it calls it, receives the result and uses it in the final answer. The model may call tools several times in parallel.

By default the model decides whether to call a tool. Apple also documents a way to control this per request: allow tools, require at least one call before answering, or forbid tools entirely. Requiring a call is useful when an answer must always come from your data, such as a search over your own content.

The 4,096-token limit shapes your design

The system model supports up to 4,096 tokens per session. Instructions, every prompt and every output all count toward that total. A token is roughly three or four characters in English, Spanish or German and about one character in Japanese, Chinese or Korean. If a session exceeds the limit, the framework throws a context size error.

Apple’s advice is to remove entries from the transcript and retry, or to split large inputs into chunks, process each in a separate session and combine the results. For a notes or journaling app that means summarizing long entries in pieces, not in one request. It also means a long-running chat feature needs a plan for trimming history from the start.

Safety, refusals and model updates

The on-device model has built-in guardrails that check both the input prompt and the output, and the session throws an error when a check fails. The model can also refuse a request with a message such as an apology. Apple tells developers to design for both: explain guardrail errors clearly when the prompt came from a user, and present refusal messages instead of hiding them. Because some harms can bypass the built-in layers, Apple recommends adding safety layers specific to your app, audience and culture.

Finally, the model changes over time. Apple documents three model versions today, aligned with OS versions 26.0 to 26.3, 26.4 and 27.0, and publishes guidance on updating prompts for new versions. Treat your prompts like code that needs regression tests, because an OS update can change the wording or quality of results.

A practical checklist before you build

We suggest answering these questions before writing any code. If the answers are vague, prototype the feature on a handful of real inputs first. If you want a second opinion on scope, an AI app development team can help you decide what belongs on the device and what belongs on a server.

  • Which single, bounded text task does the feature perform?
  • What does a person without Apple Intelligence see?
  • Which output type do you need, and can guided generation produce it?
  • Which data must the model reach through tools?
  • How will you stay inside 4,096 tokens in the longest realistic session?
  • What will the screen show on a guardrail error or a refusal?

Questions

Does the Foundation Models framework work offline?

The model runs on the device, so generation does not need a server. The model must be downloaded and ready first, which is why Apple tells developers to check availability before offering the feature.

What is the context window of the on-device model?

Apple documents a limit of 4,096 tokens per session. Instructions, prompts and outputs all count toward it, and exceeding it throws a context size error.

Can the model write code or do math reliably?

Apple lists basic math, code generation and logical reasoning as capabilities to avoid for the on-device model. Use it for summarizing, extracting, classifying and rewriting text instead.

What is guided generation?

It is a way to describe the output as a Swift type so the framework returns a typed object with guaranteed structure, instead of a string you must parse.

Sources

  1. Apple Developer Documentation: Foundation Models
  2. Apple Developer Documentation: Generating content and performing tasks with Foundation Models
  3. Apple Developer Documentation: Generating Swift data structures with guided generation
  4. Apple Developer Documentation: Expanding generation with tool calling
  5. Apple Developer Documentation: Improving the safety of generative model output
  6. Apple Developer Documentation: SystemLanguageModel

Have a project in mind?

Tell us about it. Our team in Istanbul replies within one business day with next steps and a free intro call.

Start a project