MLX-LM Server exposes a locally running language model via an OpenAI-compatible HTTP API on your Mac, enabling fully offline agentic AI workflows β tool calling, multi-step reasoning, and concurrent subagents β with no cloud dependency. New in macOS 26, MLX targets dedicated Neural Accelerators on M5 for up to 4Γ faster prompt processing.
β’ Run agentic coding workflows (write, build, debug) entirely on-device: your source code never leaves your Mac
β’ MLX-LM Server is a drop-in replacement for OpenAI-compatible APIs, so any agent framework (OpenCode, Xcode Intelligence, custom scripts) works without modification
β’ M5 Neural Accelerators deliver ~4Γ prompt-processing speedup automatically β no code changes required β and distributed inference across multiple Macs via Thunderbolt RDMA supports models up to 1.6T parameters
A minimal SwiftUI view that sends a chat message to a locally running MLX-LM Server and streams the assistant reply using the OpenAI-compatible completions endpoint β no API key required.
import SwiftUI
import Foundation
// MARK: - OpenAI-compatible request/response models
struct ChatMessage: Codable {
let role: String
let content: String
}
struct ChatRequest: Codable {
let model: String
let messages: [ChatMessage]
let stream: Bool
}
struct ChatChoice: Codable {
struct Delta: Codable {
let content: String?
}
let delta: Delta
}
struct ChatStreamChunk: Codable {
let choices: [ChatChoice]
}
// MARK: - MLX Local LLM client
actor MLXLocalClient {
/// Base URL of the running mlx_lm.server (default port 8080)
private let baseURL = URL(string: "http://127.0.0.1:8080/v1/chat/completions")!
private let modelName = "mlx-community/Qwen3-4B-4bit"
func streamChat(prompt: String) -> AsyncThrowingStream<String, Error> {
AsyncThrowingStream { continuation in
Task {
let body = ChatRequest(
model: modelName,
messages: [ChatMessage(role: "user", content: prompt)],
stream: true
)
var request = URLRequest(url: baseURL)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONEncoder().encode(body)
let (bytes, _) = try await URLSession.shared.bytes(for: request)
for try await line in bytes.lines {
// SSE lines are prefixed with "data: "
guard line.hasPrefix("data: "),
let jsonData = line.dropFirst(6).data(using: .utf8),
let chunk = try? JSONDecoder().decode(ChatStreamChunk.self, from: jsonData),
let token = chunk.choices.first?.delta.content
else { continue }
continuation.yield(token)
}
continuation.finish()
}
}
}
}
// MARK: - SwiftUI View
struct LocalAgentChatView: View {
@State private var prompt: String = "Summarize what MLX is in one sentence."
@State private var reply: String = ""
@State private var isLoading = false
private let client = MLXLocalClient()
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Text("Local MLX Agent")
.font(.title2.bold())
TextField("Enter prompt", text: $prompt, axis: .vertical)
.textFieldStyle(.roundedBorder)
.lineLimit(3...6)
Button(action: sendPrompt) {
Label(isLoading ? "Thinkingβ¦" : "Ask Local Model", systemImage: "brain")
}
.buttonStyle(.borderedProminent)
.disabled(isLoading || prompt.isEmpty)
if !reply.isEmpty {
ScrollView {
Text(reply)
.font(.body)
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(.secondarySystemBackground, in: RoundedRectangle(cornerRadius: 12))
}
}
Spacer()
}
.padding()
}
private func sendPrompt() {
reply = ""
isLoading = true
Task {
defer { isLoading = false }
do {
for try await token in await client.streamChat(prompt: prompt) {
reply += token
}
} catch {
reply = "Error: \(error.localizedDescription)\n\nMake sure mlx_lm.server is running on port 8080."
}
}
}
}
#Preview {
LocalAgentChatView()
}Foundation Models is a new Apple framework introduced in iOS 27 that gives developers on-device access to the same Apple Intelligence language model powering system features, enabling text generation, structured output, and tool-calling entirely on-device without a network connection.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, enabling anyone to integrate custom, server-based, or open-source models using the same Swift API as Apple's on-device system model.
App Schemas let developers describe their app's content and actions using pre-defined domain schemas (like the Calendar domain) so Siri can understand, search, and act on app data without custom NLP. Entities conforming to IndexedEntity are donated to Spotlight's semantic index, enabling natural-language queries over app content.
In-depth guide
iOS 27 On-Device AI & Apple Intelligence βMLX and MLX-LM are open-source Python packages installed via pip, not part of the Xcode SDK β Swift/SwiftUI code interacts with the server over HTTP using URLSession or URLSession async/await against the OpenAI-compatible REST API. The server must already be running (mlx_lm.server) before your app makes requests. Tool-calling and streaming require appropriate request flags. Xcode Intelligence integration uses the 'Locally Hosted' provider option in Xcode Settings β Intelligence tab.
Requires Apple Silicon Mac; Neural Accelerator 4Γ speedup is M5-specific; distributed inference requires multiple Macs connected via Thunderbolt or Ethernet; very large models (800 GB+) require multiple high-RAM Macs
Visual Intelligence brings iOS 17's Visual Look Up capabilities to a new developer-facing API surface in iOS 27, letting apps pipe live camera frames or static images through on-device scene understanding to extract subjects, text, barcodes, and rich semantic labels without any cloud round-trip.