anthropics/ClaudeForFoundationModels

Claude support for Apple Foundation Models

What it solves

This package allows developers to use Claude as a server-side language model within Apple's Foundation Models framework. It bridges the gap between Anthropic's API and Apple's standardized LanguageModel protocol, enabling developers to swap between on-device models and Claude using the same LanguageModelSession API.

How it works

The library provides ClaudeLanguageModel, which conforms to the LanguageModel protocol. By passing this model to a LanguageModelSession, developers can perform tasks like streaming, guided generation, and tool calling using Apple's native APIs. It supports multiple authentication methods, including App Attest for secure, keyless production deployments on physical devices, API keys for development, and proxied requests through a custom backend.

Who it’s for

Swift developers building for iOS 27, macOS 27, visionOS 27, or watchOS 27 (beta) who want to integrate Claude's capabilities into their apps using Apple's official foundation model frameworks.

Highlights

  • Native Integration: Uses the same API as Apple's on-device models for respond(to:) and streaming.
  • Secure Authentication: Supports Apple's App Attest to prove app authenticity without bundling API keys.
  • Server-Side Tools: Enables built-in Anthropic infrastructure for web search, web fetch, and code execution within a single round-trip.
  • Structured Output: Supports @Generable types for guided generation of specific data structures.
  • Model Fallbacks: Allows specifying a chain of fallback models to handle policy refusals seamlessly.
  • Effort Control: Maps Apple's reasoning levels to Claude's specific effort levels (low, medium, high, xhigh, max).

Related

  • Project
  • Project
  • Project
  • Project