Swift Language Models
A Swift package that plugs other providers' models into Apple's Foundation Models API, so OpenRouter and OpenAI models run in the same LanguageModelSession as Apple's on-device model.
View on GitHub ↗- Stars
- ★ 24
- Last commit
- 2 Dec 2026
- Maintenance
- Active
- Licence
- Apache-2.0
- Category
- On-device AI SDKs · Cloud-capable
- GitHub
- ironsparrows/
swift-language-models
Overview
Swift Language Models lets an app keep Apple's LanguageModelSession, with its transcripts, tools, @Generable guided generation, Dynamic Profiles and reasoning levels, and use models from other services inside it. Switching between Apple's on-device model and, say, Claude, GPT, Gemini, DeepSeek, Qwen, Llama or Mistral changes only the model: argument.
There are now two provider modules: OpenRouterLanguageModels (one key reaches many hosts) and OpenAILanguageModels (OpenAI's Responses API directly). Each provider module re-exports the shared core, LanguageModels.
Swift Language Models is licensed under the Apache License 2.0.
Features
- Two provider modules: OpenRouter and OpenAI, each with a typed model catalogue.
- Typed reasoning levels, checked when the code compiles.
- Routing, fallback models and prompt caching (OpenRouter).
- Server tools: web search, web fetch, advisors and subagents on OpenRouter; web search, image generation and file search on OpenAI.
- Attachments: images, and from OS 27.2 also PDFs, text, and audio and video through OpenRouter. Generated images come back as data.
- Errors map to Apple's LanguageModelError (rate limits, oversized contexts, guardrails, refusals).
- Works with Apple's Evaluations framework, and includes a scripted model for offline tests.
- A showcase app in the Example folder.
- Docs on GitHub Pages for each module.
Requirements
- iOS, macOS, visionOS or watchOS 27.0.
- Xcode 27.0, with Swift 6.4.
- OS 27.2 and Xcode 27.2 for PDF, audio, video and text attachments, and for generated images.
- An OpenRouter and/or OpenAI API key, depending on the module.
- It doesn't support tvOS or Linux, because Foundation Models' LanguageModel isn't available there.
Install
Xcode. Choose File > Add Package Dependencies and enter https://github.com/ironsparrows/swift-language-models.
Package.swift. Add the package from version 2.0.0, then add OpenRouterLanguageModels and/or OpenAILanguageModels to each target that uses them.
Example
Import FoundationModels and OpenRouterLanguageModels. Create an OpenRouterLanguageModel with a catalogue model, such as .anthropicClaudeHaiku5_5, and your key. Pass it to LanguageModelSession(model:) and call respond(to:) as you would with SystemLanguageModel.default.
The README warns never to ship an API key inside an app, and shows how to route requests through your own server instead.
Works with
Listed in
- github.com/ironsparrows/swift-language-models
- github.com/ironsparrows/swift-language-models/blob/main/README.md
- ironsparrows.github.io/swift-language-models/documentation
Read the code before you install anything. SwiftAgents doesn't review or endorse the tools listed here. Active: a commit in the last 90 days. Slowing: last commit within the past year. Stale: older than a year, or archived.
More in this category
apfel
Command-line tool, chat mode and local OpenAI-compatible server for the on-device model in Apple's FoundationModels framework. Needs macOS 26 and Apple silicon.
Argmax OSS Swift (WhisperKit)
Argmax's open-source on-device speech toolkit for Apple silicon, and the home of WhisperKit.
MLX Swift Examples
Example apps and code showing how to use MLX Swift.
SwiftAgents