AnyLanguageModel
A Swift package that acts as a drop-in replacement for Apple's Foundation Models framework with support for custom language model providers.
At a Glance
About AnyLanguageModel
AnyLanguageModel is an open-source Swift package from Hugging Face that mirrors Apple's Foundation Models API while adding support for other model providers. Developers switch from import FoundationModels to import AnyLanguageModel and can then run the same session, tool-calling and guided-generation code against local or remote models. The latest listed release is 1.1.1, under the Apache 2.0 license.
What It Is
AnyLanguageModel is a Swift library for apps on Apple platforms and Linux that need to talk to language models through one API. It keeps the Foundation Models programming model, including LanguageModelSession, Tool, @Generable and @Guide, and extends it beyond Apple's system model. Additions beyond Apple's API are marked as extensions in its documentation, and the README summarizes them in a Differences from Foundation Models section.
Providers and Backends
The README lists these backends:
- Apple Foundation Models and Private Cloud Compute
- Any
FoundationModels.LanguageModelconformer, including Core AI models - Core ML
- MLX
- llama.cpp with GGUF models
- Ollama
- Anthropic Messages API
- Google Gemini API
- OpenAI Chat Completions and Responses APIs
- Open Responses-compatible endpoints
Heavy local backends (Core ML, MLX, llama.cpp) are opt-in through Swift package traits, which the README says keeps binary size and build times down. A separate AsyncHTTPClient trait swaps the default networking layer.
Session Features
Sessions support guided generation into typed Swift structures, and tool calling across all providers. Tool calling can be observed or controlled with a tool execution delegate. Other documented capabilities:
- Image inputs and prompt attachments (support varies by provider)
- Dynamic instructions and dynamic profiles
- Tool-calling modes
- Reasoning entries in the transcript
- Token usage tracking
- Pluggable HTTP transports, including custom ones for WASI
Provider-specific options, such as MLX KV-cache settings, llama.cpp runtime parameters, Anthropic thinking and Gemini server tools, are set per request through custom generation options.
Setup and Credentials
The package requires Swift 6.3+ (Xcode 26.4+) and targets iOS 17+, macOS 14+, visionOS 1+ and Linux. It is added through Swift Package Manager. For third-party APIs, the README advises against hardcoding credentials and describes two approaches: user-supplied keys stored in the Keychain, or a proxy server that issues short-lived tokens.
Community Discussions
Be the first to start a conversation about AnyLanguageModel
Share your experience with AnyLanguageModel, ask questions, or help others learn from your insights.
Pricing
Open Source
Swift package released under the Apache License 2.0, free to use, modify and distribute.
- Drop-in replacement for Apple's Foundation Models framework
- Supports Apple Foundation Models, Core ML, MLX, llama.cpp, Ollama, Anthropic, Google Gemini, OpenAI and Open Responses providers
- Licensed under Apache License 2.0
- Third-party provider API usage (e.g. OpenAI, Anthropic, Gemini) is billed separately by those providers
Capabilities
Key Features
- Drop-in replacement for Apple's Foundation Models API
- Multiple provider backends (Apple, Core ML, MLX, llama.cpp, Ollama, OpenAI, Anthropic, Gemini, Open Responses)
- Guided generation with @Generable and @Guide
- Tool calling with execution delegates
- Image inputs and prompt attachments
- Dynamic instructions and dynamic profiles
- Reasoning entries in transcripts
- Token usage tracking
- Pluggable HTTP transports
- Swift package traits for opt-in backends
