LLMs are already essential tools for modern apps, but integrating them in the Apple ecosystem can still be painful. Why is that? Because you often end up mixing local models, cloud APIs, and Apple Foundation Models — each with its own contract, its own way to initialize sessions, and its own learning curve.
Today Hugging Face presents AnyLanguageModel, a Swift package that aims to solve that pain: a drop-in implementation compatible with the Foundation Models API that supports multiple providers, both local and remote. The idea is simple and powerful: swap import FoundationModels for import AnyLanguageModel and keep the same Swift ergonomics.
What is AnyLanguageModel and why it matters
AnyLanguageModel is a compatibility layer that unifies access to models on Apple platforms (iOS, macOS on Apple Silicon, etc.). It’s designed for developers who want to experiment with local models (privacy, offline, low latency) without giving up the option to use cloud providers as a fallback.
Why use it? Because it reduces friction: fewer conceptual changes between models, less time lost adapting different SDKs, and a clear path to try open-source models in production.
Minimal code changes
Example with the system model (Foundation Models):
let model = SystemLanguageModel.default
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: "Explain quantum computing in one sentence")
print(response.content)
And the exact same pattern with a local model via MLX:
let model = MLXLanguageModel(modelId: "mlx-community/Qwen3-4B-4bit")
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: "Explain quantum computing in one sentence")
print(response.content)
The API keeps familiar abstractions: LanguageModelSession, generation, and utilities for streaming or persistence. That makes it easy to compare providers by changing only the model instance.
Providers and technical support
AnyLanguageModel covers a wide range of backends:
- Apple Foundation Models (system, macOS 26+ / iOS 26+)
- Core ML (converted models and Neural Engine acceleration)
- MLX (quantized models for Apple Silicon)
- llama.cpp (loading GGUF models via llama.cpp / llama.swift backends)
- Ollama (connect to models served locally by Ollama)
- OpenAI, Anthropic, Google Gemini (cloud as fallback)
- Hugging Face inference providers (various cloud models)
The approach favors models you can download from the Hugging Face Hub and run locally. Cloud integrations exist to help you get started and to offer a migration path: make it work first, optimize later.
Dependency control: Swift 6.1 traits
A key decision is avoiding bloat from multi-backend support. AnyLanguageModel uses Swift package traits so you only pull the backends you need. Example dependency where you enable only MLX:
dependencies: [
.package(
url: "https://github.com/mattt/AnyLanguageModel.git",
from: "0.4.0",
traits: ["MLX"] // Only brings dependencies needed for MLX
)
]
Available traits: CoreML, MLX, Llama (for llama.cpp / llama.swift). By default it doesn’t include heavy dependencies; the base API and cloud providers only use URLSession.
If you use Xcode and it doesn’t yet support traits in your workflow, the recommended workaround is to create an internal Swift package that depends on AnyLanguageModel with the required traits, and then add that package to your project.
Pragmatic extensions: vision and beyond Foundation Models
Foundation Models today don’t accept images in prompts. AnyLanguageModel makes a practical choice: extend the API to support vision+language now, even if that might differ from Apple’s future implementation. Example sending an image to Claude:
let model = AnthropicLanguageModel(
apiKey: ProcessInfo.processInfo.environment["ANTHROPIC_API_KEY"]!,
model: "claude-sonnet-4-5-20250929"
)
let session = LanguageModelSession(model: model)
let response = try await session.respond(
to: "What's in this image?",
image: .init(url: URL(fileURLWithPath: "/path/to/image.png"))
)
Yes, there’s a risk Apple may change its API later. But the bet is pragmatic: vision+language is too useful to wait.
Current status and technical roadmap
AnyLanguageModel is pre-1.0. The core API is stable, but the team is still working on parity with Foundation Models and optimizations for all adapters. Development priorities:
- Consistent tool calling across providers
- MCP integration for tools and elicitation
- Guided generation for structured outputs
- Performance optimizations for local inference (quantization, efficient Neural Engine use, streaming)
The long-term vision is to provide a unified inference API on top of which you can build agentic flows on macOS/iOS: models that use tools, access system resources, and complete complex tasks.
Practical example: chat-ui-swift
To see AnyLanguageModel in action, check out chat-ui-swift, a reference SwiftUI app that demonstrates:
- Integration with Apple Intelligence (Foundation Models)
- Hugging Face authentication for gated models
- Streaming responses
- Chat persistence
Fork it, switch the model, try it with MLX or llama.cpp, and compare latencies and costs.
What this means for you, developer
Curious and want to try local models without reworking your architecture? AnyLanguageModel gives you a clear path. Responsible for a product and need privacy and cost options? Start with a cloud provider and migrate to local later without rewriting the app.
Practically, it lowers experimentation friction and prevents the cost of trying from stopping you from discovering that an open model running on-device can be enough — and sometimes better — for your use case.
