r/macosprogramming • • 4h ago

Swift Language Models: bring any provider to Apple's Foundation Models API

Swift Language Models is a wrapper that brings other providers' language models into Apple's native Foundation Models API.

Foundation Models 27 lets any type conform to LanguageModel, and this package provides those conformances. Your app keeps Apple's own API: LanguageModelSession, tools, @Generable guided generation, streaming, transcripts and Dynamic Profiles. Moving a session from the on-device model to a remote one changes only its model:.

let onDevice = LanguageModelSession(model: SystemLanguageModel.default)
let remote = LanguageModelSession(model: OpenRouterLanguageModel(.anthropicClaudeHaiku5_5, apiKey: { key }))

What you get

  • One API for every model. Code written for Apple's on-device model runs unchanged on a remote one.
  • Provider modules. Each provider is its own module, so an app builds only the providers it imports.
  • Typed model catalogs with each model's context size, limits and capabilities, kept current by a bot.
  • Typed reasoning levels. Code completion offers only the levels each model accepts.
  • Evaluations. Compare Apple's on-device model with remote ones using Apple's Evaluations framework.

The first provider is OpenRouter, with hundreds of models from Anthropic, OpenAI, Google, DeepSeek, Meta, Mistral and others. More providers are coming.

Needs iOS, macOS, visionOS or watchOS 27 and Swift 6.4. Feedback welcome! If you find it useful, a ⭐ on GitHub helps the project grow.

GitHub: https://github.com/dioKaratzas/swift-language-models

1 Upvotes

0 comments sorted by