AnyLanguageModel

Hugging Face's drop-in replacement for Apple's Foundation Models API that also works with other local and cloud model providers.

View on GitHub ↗
Stars
★ 952
Last commit
19 Oct 2026
Maintenance
Active
Licence
Apache-2.0
Category
On-device AI SDKs
GitHub
huggingface/AnyLanguageModel

Overview

AnyLanguageModel from Hugging Face is a Swift package that works as a drop-in replacement for Apple's Foundation Models framework while supporting many other model providers. You keep the same session API and can switch between Apple's models, local models through Core ML, MLX or llama.cpp, and cloud APIs. It's for app developers who want a choice of which model runs behind their code.

Features

  • Supports Apple Foundation Models and Private Cloud Compute
  • Local models through Core ML, MLX and llama.cpp (GGUF)
  • Ollama, Anthropic, Google Gemini and OpenAI APIs
  • Guided generation for on-device models, image inputs and tool calling
  • Token usage reporting per response and per session
  • Swift package traits keep heavy dependencies optional

Requirements

  • Swift 6.3 or later (Xcode 26.4 or later)
  • iOS 17.0+, macOS 14.0+, visionOS 1.0+ or Linux
  • API keys for any cloud providers you use

Install

  1. Add the package to Package.swift

    .package(url: "https://github.com/huggingface/AnyLanguageModel", from: "1.0.0")

Example

Create a LanguageModelSession with an MLX model, ask it to "Explain how rainbows form." and read the token counts from response.usage.

Works with

Not stated by the source

Listed in

GitHub search

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