Apple Foundation Models
9 hours ago
- #Claude
- #Swift Package
- #Foundation Models
- Claude for Foundation Models is a Swift package that integrates Claude as a server-side language model within Apple's Foundation Models framework.
- It uses the LanguageModelSession API for tasks like responding to prompts, streaming, guided generation, and tool calling.
- Requests are sent directly to the Claude API, with usage billed to the user's Anthropic account and no involvement from Apple.
- The package allows apps to choose between Claude and Apple's on-device model by swapping the model passed to each session.
- Setup involves adding the package via Swift Package Manager or Xcode, importing FoundationModels and ClaudeForFoundationModels, and configuring ClaudeLanguageModel with authentication.
- Authentication options include API keys for development and proxied requests for production to secure credentials.
- The package supports features like streaming responses, structured output generation, server-side tools (e.g., web search, code execution), and image input via vision capabilities.
- Error handling maps Claude API errors to LanguageModelError, with specific cases for rate limits and context size, and includes custom ClaudeError for provider-specific issues.
- It is currently in beta, targeting Foundation Models APIs introduced in OS 27 betas, with potential changes before general availability.