Overview
Claude for Foundation Models is Anthropic's Swift package that makes Claude a server-side language model inside Apple's Foundation Models framework. It conforms Claude to the framework's `LanguageModel` protocol, so an app talks to it through `LanguageModelSession` — `respond(to:)`, `streamResponse(to:)`, guided generation and tool calling — exactly as it would talk to Apple's on-device model. Swapping providers is an edit to which model you hand the session, not a rewrite of the call sites around it.
The entry point is `ClaudeLanguageModel`. Model identifiers are values of `ClaudeModel`, shipped as compiled-in constants that mirror the API model IDs and carry each model's capabilities — which sampling parameters, effort levels, thinking modes, structured output and image input it accepts. The package uses those capabilities to decide which request fields to send, because sending a field a model rejects is a hard error. An ID that is not compiled in yet can be constructed by declaring what it accepts.
Three authentication modes cover the shapes an Apple app actually takes: App Attest (the recommended one, where each install proves it is a genuine copy and usage bills to your Anthropic workspace, so the app ships no key and needs no backend), a plain API key for simulator iteration, and a proxied mode that points at your own relay. Server-side tools — web search and code execution — surface on the transcript as activity you can render inline while a response streams. The package targets the OS 27 betas, is Apache-2.0 licensed, and Anthropic maintains it on a best-effort basis without accepting external contributions.
What it does
- Conforms Claude to Apple's Foundation Models `LanguageModel` protocol — the same `LanguageModelSession` API as the on-device model
- Capability-aware requests: each `ClaudeModel` constant declares the sampling parameters, effort levels and modalities it accepts, so unsupported fields are never sent
- App Attest authentication — the app ships no API key and needs no developer backend; API-key and proxied modes are there for simulator work and custom relays
- Streaming via `streamResponse(to:)`, with each element a cumulative snapshot
- Typed structured output through `@Generable` types and `@Guide` annotations
- Server-side web search and code execution rendered as inline transcript activity, with thinking signatures and citations replayed across turns
Getting started
The package needs Xcode 27 and an OS 27 target (iOS, macOS, visionOS or watchOS), plus a credential — an App Attest client ID from the Anthropic console, or an API key for the simulator.
Add the Swift Package Manager dependency
Add it to Package.swift, or use File ▸ Add Package Dependencies… in Xcode and paste the repository URL.
dependencies: [
.package(url: "https://github.com/anthropics/ClaudeForFoundationModels.git", from: "0.1.0")
]Create a model and run a turn
ClaudeLanguageModel is the entry point. Hand it to LanguageModelSession and use the session as you would with any Foundation Models provider.
import FoundationModels
import ClaudeForFoundationModels
let model = ClaudeLanguageModel(
name: .sonnet5,
auth: .apiKey(ProcessInfo.processInfo.environment["ANTHROPIC_API_KEY"] ?? "")
)
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: "Plan a 4-day trip to Buenos Aires.")
print(response.content)Switch to App Attest for a shipping app
Register the app's team and bundle ID in the Anthropic console, add the App Attest entitlement, and front the one-time attestation cost at launch rather than on the first prompt. A physical device is required.
let model = ClaudeLanguageModel(name: .sonnet5, auth: .appAttest(clientID: "clid_..."))
try await model.authenticateIfNeeded()Ask for a typed result
Annotate a type with @Generable and pass it to `generating:`; the response content is a value of that type.
@Generable
struct Trip {
@Guide(description: "Destination city") var destination: String
@Guide(description: "Length in days") var days: Int
}
let response = try await session.respond(to: "Plan a trip to Tokyo.", generating: Trip.self)
print(response.content.destination)Try the bundled example
Examples/ClaudeExample streams one chat turn to the terminal and prints token usage; --search enables server-side web search for the turn. Running it needs a macOS 27 host.
ANTHROPIC_API_KEY=<key> swift run ClaudeExample "What should I see in Kyoto?"Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Prototype an Apple-platform feature against the on-device model, then move it to Claude without rewriting the session code
- Ship a Claude-backed iOS or macOS app that carries no extractable API key, using App Attest instead of a bundled secret
- Get typed values out of a model with @Generable instead of parsing free text
- Render web-search and code-execution activity inline in a streaming chat UI
How Claude for Foundation Models compares
Claude for Foundation Models alongside other open-source app frameworks tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| LangChain | ★ 147k | A widely used Python and JavaScript framework for building LLM applications by composing models, prompts, tools, retrievers, and memory into chains. |
| LlamaIndex | ★ 52.2k | A data framework for connecting language models to your own documents and data sources, with built-in agent and retrieval (RAG) tooling. |
| Haystack | ★ 26.5k | An orchestration framework from deepset for building modular LLM pipelines and agents for search, RAG, and question answering. |
| Jina | ★ 21.9k | Jina-serve is a Python framework for building, scaling, and deploying AI services and multi-step pipelines that communicate over gRPC, HTTP, and WebSockets. |
| LLM | ★ 12.5k | Simon Willison's plugin-extensible CLI and Python library for prompting remote and local models, logging every prompt and response to SQLite, and generating embeddings. |
| Prompt Flow | ★ 11.2k | Microsoft's toolkit for building LLM apps as executable flows that link prompts, Python code, and tools, with tracing, batch evaluation, and deployment. |
| Rig | ★ 8.7k | A Rust library for building LLM-powered applications, giving one unified interface over 20+ model providers and 10+ vector stores plus an agent runtime with streaming, tools, and OpenTelemetry GenAI tracing. |
| Claude for Foundation Models | ★ 297 | Drive Claude through Apple's Foundation Models APIs, with the same session code you use for the on-device model |