A high-performance inference server for MLX models, providing an OpenAI-compatible API for running large language models on Apple Silicon.
- OpenAI-Compatible API - Drop-in replacement for OpenAI API calls
- Streaming Support - Server-Sent Events for real-time token streaming
- Tool Calling - Support for function calls (OpenAI-compatible format)
- Multi-Model Support - LLM and VLM model support
- macOS 14.0+ (Sonoma or later)
- Apple Silicon (M1, M2, M3, M4)
- Xcode 26.2 or later (what CI selects;
Package.swiftdeclaresswift-tools-version: 5.12) - At least 8GB of unified memory
From the repo root:
# Builds with xcodebuild, then stages the binary and its Metal bundle into
# src-tauri/resources/bin/ - the same path the app and `make dev` use
make build-mlx-serverOr build it directly:
cd mlx-server
xcodebuild build -scheme mlx-server -destination 'platform=OS X' -configuration ReleaseBuild products land in the mlx-server-*/Build/Products/Release directory under Xcode's
DerivedData. Use xcodebuild, not swift build: mlx-swift's Metal shaders are compiled
by its PrepareMetalShaders plugin, which only runs under Xcode, so a swift build
binary has no default.metallib and fails at inference time.
# Run the staged build against a local MLX model directory
./src-tauri/resources/bin/mlx-server \
--model "/path/to/your/model" \
--port 8080--model takes a local path. A directory is used directly when it has a config.json,
otherwise its parent directory is tried; no model is downloaded from Hugging Face.
| Option | Default | Description |
|---|---|---|
-m, --model |
Required | Path to a local model directory, or to a file inside it |
--port |
8080 | HTTP server port |
--ctx-size |
4096 | Context window size |
--api-key |
"" |
API key for authentication (optional) |
--model-id |
"" |
Model ID reported by the API; empty derives it from the model path |
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "model",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, how are you?"}
],
"temperature": 0.7,
"max_tokens": 100
}'curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "model",
"messages": [{"role": "user", "content": "Tell me a story."}],
"stream": true
}'curl -X POST http://localhost:8080/v1/cancelcurl http://localhost:8080/v1/modelscurl http://localhost:8080/healthmlx-server/
├── Sources/
│ └── MLXServer/
│ ├── MLXServerCommand.swift # CLI entry point
│ ├── ModelRunner.swift # Core inference engine
│ ├── Server.swift # HTTP server & API handlers
│ ├── OpenAITypes.swift # API type definitions
│ ├── AnthropicTypes.swift # Anthropic-compatible request/response types
│ ├── ReasoningSplitter.swift # Splits reasoning_content from content on think markers
│ ├── TokenizerAdapter.swift # Adapts swift-transformers to MLXLMCommon's TokenizerLoader
│ └── Logger.swift # Logging utilities
├── Package.swift # Swift package manifest
└── README.md # This file
- ModelRunner - Manages model loading and inference (streaming and non-streaming)
- MLXHTTPServer - HTTP server with OpenAI-compatible endpoints
- ActiveGenerations - Tracks and manages cancellable generation tasks
- The server binds to
127.0.0.1(localhost only) for security - Client disconnects automatically cancel the active generation
- VLM (vision-language models) are supported via image/video URL inputs
Ensure the model directory contains:
config.json- Model configurationtokenizer.json- Tokenizer vocabularymodel.safetensorsormodel.safetensors.index.json- Model weights- Optional:
generation_config.json,chat_template.jinja
Change the port:
--port 8081Use the mlx-lm server benchmark script to measure throughput and latency:
python server_benchmark.py --url http://localhost:8080/v1/chat/completions --model modelThis project is part of Jan - an open-source desktop AI application.
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request