# Claude for Foundation Models

> Drive Claude through Apple's Foundation Models APIs, with the same session code you use for the on-device model

- Category: App Orchestration / App Frameworks
- Language: Swift
- Licence: Apache-2.0
- Repository: https://github.com/anthropics/ClaudeForFoundationModels
- Canonical page: https://ai-tldr.dev/tools/claude-for-foundation-models/
- Updated: 2026-06-08

## In short

Claude for Foundation Models is Anthropic's Swift package that makes Claude a server-side language model inside Apple's Foundation Models framework. It sits in the App Frameworks category of the App Orchestration tools and is open-source, written in Swift and licensed Apache-2.0. To get started: add the Swift Package Manager dependency.

## 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.

1. Add the Swift Package Manager dependency

   Add it to Package.swift, or use File ▸ Add Package Dependencies… in Xcode and paste the repository URL.

```swift
dependencies: [
  .package(url: "https://github.com/anthropics/ClaudeForFoundationModels.git", from: "0.1.0")
]
```

2. 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.

```swift
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)
```

3. 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.

```swift
let model = ClaudeLanguageModel(name: .sonnet5, auth: .appAttest(clientID: "clid_..."))
try await model.authenticateIfNeeded()
```

4. Ask for a typed result

   Annotate a type with @Generable and pass it to `generating:`; the response content is a value of that type.

```swift
@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)
```

5. 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.

```bash
ANTHROPIC_API_KEY=<key> swift run ClaudeExample "What should I see in Kyoto?"
```

## 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

## Version history

- 2026-06-08: Anthropic published the package: Claude conforms to Apple's Foundation Models LanguageModel protocol for iOS, macOS, iPadOS, watchOS and visionOS 27, with streaming, @Generable structured output, server-side web search and code execution.
