Developer Tools & APIs

ClaudeForFoundationModels: Anthropic's Swift package brings Claude into Apple's Foundation Models framework

Anthropic's new Swift package lets iOS/macOS 27 developers use Claude as a drop-in server-side model via Apple's LanguageModelSession API.

developer tools apis category

Apple’s Foundation Models framework has, until now, been a one-model show. You got Apple’s on-device model, full stop. With iOS 27, that changes. Apple introduced a LanguageModel protocol that turns the framework into a shared interface any provider can implement, and Anthropic has shipped the first thing most iOS developers will want to use: ClaudeForFoundationModels, a Swift package that makes Claude a fully conforming server-side language model inside that framework.

The short version: you write the same Swift code you already write for Apple’s on-device model, and you can point it at Claude instead, or route between them depending on what the task needs.

What the package actually does

Apple’s Foundation Models framework centers on LanguageModelSession. You create a session, pass it a model, and use respond(to:) to get back typed Swift values. The @Generable macro handles structured output, tool calling works through a tools: array, and streaming is built in.

ClaudeForFoundationModels conforms ClaudeLanguageModel to the same LanguageModel protocol Apple’s on-device model uses. That means your session code does not change. You swap the model, not the architecture around it.

import FoundationModels
import ClaudeForFoundationModels

let model = ClaudeLanguageModel(model: .sonnet4_6, authentication: .apiKey("your-key"))
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: "Summarise these notes: \(notes)")

That is roughly it. Streaming, tool calls, and @Generable structured output all carry over from the framework’s existing API.

Routing between on-device and Claude

The practical pattern most developers will reach for is split-model routing. Apple’s on-device model is fast, private, and free to call. Claude handles the tasks that need more depth. Because both conform to the same protocol, your session logic accepts either one.

A journaling app can generate a daily prompt locally, then pass months of entries to Claude to surface patterns the on-device model would struggle with. A study tool can define a term on-device in milliseconds, then hand off to Claude when the student asks a follow-up that needs multi-step reasoning. One user experience, two models working in their respective lanes.

The routing decision is entirely yours, written in ordinary Swift. There is no middleware, no configuration file, no proprietary orchestration layer. You decide which model each session gets.

Privacy: Apple is not in the request path

This is worth being explicit about. When your app calls Claude through this package, the request goes directly from the app to the Anthropic API. Apple is not in the request path and does not see prompts or responses. Usage is billed to your Anthropic account at standard API pricing.

That is a meaningful difference from some other AI integrations, and worth communicating clearly to users, particularly in privacy-sensitive categories like health, finance, or personal journaling.

Tool calling and server-side tools

Standard tool calling works exactly as the Foundation Models framework documents it. Conform your types to Tool, pass them in the tools: array, and the framework invokes them on-device when Claude requests them.

Server-side tools are separate. Web search, web fetch, and code execution all run on Anthropic’s infrastructure within a single round trip. Nothing happens on the device for those. You configure them per model via serverTools: in the initializer. The included example project has a --search flag that demonstrates server-side web search if you want to see it working before you wire it into your own app.

Prompt caching is handled automatically by the package. Cache TTL and breakpoint placement are not configurable, which keeps the API surface clean.

Getting started

Add the package via Swift Package Manager:

.package(url: "https://github.com/anthropics/ClaudeForFoundationModels.git", from: "0.1.0")

Then add ClaudeForFoundationModels to your target dependencies, import it alongside FoundationModels, and you are ready. You will need a Claude API key from the Claude Console.

Model identifiers are values of ClaudeModel. Constants like .sonnet4_6 and .opus4_8 map to the underlying API model IDs and carry capability metadata, so the package knows which request fields are valid for each model. Sending a field a model does not support is a hard error, and the package avoids that for you automatically.

The repository includes Examples/ClaudeExample, a command-line target that streams a chat turn to the terminal. It requires a macOS 27 host to run.

The beta caveat

The package targets the server-side language model API introduced in the OS 27 betas. APIs may change before general availability. This is genuinely early. If you are building for a production release, treat it as exploratory for now. If you are already working in the OS 27 betas, it is worth integrating into a prototype today so you understand how the routing patterns feel in practice before the APIs stabilise.

Platform requirements are iOS 27, iPadOS 27, macOS 27, visionOS 27, and watchOS 27. The package is Apache 2.0 licensed.

The bigger picture

Apple’s decision to make LanguageModel a public protocol is the part of this story that extends beyond any single package. It means Claude, Gemini, open-source models via MLXLanguageModel, and any future provider that ships a conforming Swift package all become first-class options inside the Foundation Models framework. Apple supplies the on-device layer and the unified Swift API. Developers choose what runs where.

For iOS and macOS developers, that is a genuinely useful arrangement. You get the speed and privacy of on-device inference for lightweight tasks, and you can reach out to a frontier model without leaving the framework or rewriting the plumbing around your sessions.

Full documentation is at platform.claude.com, and the Anthropic blog post covers the integration in more detail.