macOS Sequoia 26.0+ Β· Apple Silicon Β· 100% On-Device Β· Zero Config

The Free AI Already on Your Mac.
Native Rust Speed.

macOS Sequoia ships with on-device Apple Intelligence FoundationModels. apfel-rs gives you an ultra-fast CLI and OpenAI-compatible HTTP daemon with one brew install. No model downloads, no API keys, zero network token costs.

Zero Token Costs 100% Private & Offline No Model Downloads OpenAI & MCP Compatible
2.30 MB Binary Size (-88.9%)
10.1 MB Idle RSS RAM
8.3k – 50.7k Server Req/Sec
0.13 ms Median Latency
brew install bhubbard/tap/apfel-rs

Rust fork of apfel by Arthur-Ficial · Requires: Apple Silicon · macOS Sequoia 26+ · Apple Intelligence enabled

$ apfel --stream "Write a haiku about compiling Rust" [FoundationModels SystemLanguageModel 0.1B | On-Device] Borrow checker smiles, Zero-cost safety unfolds, Binary runs swift. βœ” 18 tokens generated in 0.31s (58.1 tok/sec)
Multi-Backend Performance & Benchmarks

Default Mode vs. MLX Engine: How They Compare

apfel-rs offers two native on-device engines. Choose between zero-download Apple Intelligence for instant terminal tasks, or the MLX Engine for expanded 32k–128k context and custom open weights.

πŸ“Š View Full BENCHMARKS.md Report →
Default Mode • FoundationModels Built into macOS

Zero-Download Apple Intelligence

Runs directly against Apple Silicon's Neural Engine (ANE) with P-core priority scheduling. Zero weights to download, zero setup, and zero telemetry. Instant startup from your terminal.

  • 🍏 Weight Download: 0 MB (pre-installed with macOS Sequoia+)
  • ⚑ Context Window: 4,096 – 8,192 tokens
  • 🎯 Best For: Daily shell pipes, quick queries, git hooks, instant offline server
# Instant single-prompt generation
apfel "Explain Rust zero-cost abstractions"
# Launch daemon on 127.0.0.1:8080
apfel --serve
MLX Engine • Open Weights 32k–128k Context

Expanded Context & Custom Models

Accelerated by Apple's native MLX framework on Metal GPU and Unified Memory. Run specialized coding models like Qwen 2.5 Coder, Llama 3, or Mistral with massive context budgets.

  • πŸš€ Weight Download: Any HuggingFace or local GGUF/MLX repo
  • ⚑ Context Window: 32,768 – 131,072 tokens
  • 🎯 Best For: Zed/Cursor coding agents, large document synthesis, fine-tuned models
# Run Qwen 2.5 Coder with 32k context
apfel --engine mlx -m mlx-community/Qwen2.5-Coder-7B-Instruct-4bit "Write an async worker pool"
# Serve MLX model via OpenAI API
apfel --engine mlx -m mlx-community/Llama-3.2-3B-Instruct-4bit --serve
Benchmark Metric / Feature Original Swift (apfel) Rust Default (FoundationModels) Rust MLX Engine (--engine mlx) Advantage vs. Swift
Release Binary Footprint 20.75 MB 2.30 MB 2.30 MB 88.9% smaller distribution
Server Idle Memory (RSS) 22.2 MB 10.1 MB 10.1 MB 54.6% less resident RAM
Active Server Memory (100 workers) 24.0 MB 15.5 MB 11.3 MB 35% – 53% lower RAM footprint
Server Throughput (RPS) 12,156 req/s 15,240 req/s 50,779 req/s Pre-serialized zero-copy route cache
Tail Latency (p50 / p95) 0.25 ms / 5.71 ms 0.15 ms / 1.12 ms 0.13 ms / 0.64 ms Sub-millisecond p95 response
Token Counting & Preflight 2,949 ms (spikes to 22.7s) 0.17 ms cached (5,782 req/s) 6.35 ms 152.5× speedup on preflight
Token Counting Max Jitter 22,773 ms (ARC stalls) 0.24 ms (deterministic) 9.37 ms Zero reference-counting lockups
Supported Context Window 4,096 tokens 4,096 – 8,192 tokens (disclosed) 32,768 – 131,072 tokens 8× to 32× larger context budget
Release Binary Size 88.9% Smaller
Swift (apfel) 20.75 MB
Rust (apfel-rs) 2.30 MB
Server Idle RAM (RSS) 54.6% Less Memory
Swift (apfel) 22.2 MB
Rust (apfel-rs) 10.1 MB
Server Concurrency (RPS) Up to 50k req/s
Swift (Hummingbird) 12,156 req/s
Rust (Default / MLX) 8.3k – 50.7k req/s
Server Latency (p50 / p95) Sub-millisecond
Swift (apfel) 0.25 ms (p50)
Rust (TCP_NODELAY) 0.13 – 0.15 ms
Token Counting Under Load Zero ARC Stalls
Swift (Max Jitter) 22,773 ms
Rust (apfel-rs) 6.35 – 95 ms
Inference Generation Apple Silicon P-Core Priority
Swift (Default Thread) ~35.9 tok/s
Rust (Thread QoS Elevated) ~34.4 tok/s
Architecture & Features

Built for Performance, Privacy & Simplicity

Everything you love about Apple Intelligence, wrapped in a UNIX-first Rust binary that fits in your pocket.

πŸ”’

100% On-Device & Private

Executes completely against macOS FoundationModels on Apple Silicon. Zero network calls, zero telemetry, zero tokens leaking outside your machine.

⚑

OpenAI-Compatible Daemon

Drop-in replacement for OpenAI endpoints. Provides /v1/chat/completions with streaming SSE, /v1/responses, /v1/models, and /health.

πŸ› οΈ

Model Context Protocol (MCP)

Integrates directly with external MCP servers over stdio. Automatically negotiates tools, invokes scripts, and runs the self-healing re-prompting loop.

🧠

5 Context Trimming Strategies

Fine-tune conversation budgets with sliding-window, newest-first, oldest-first, summarize, or strict overflow protection.

πŸ›‘οΈ

Hardened Localhost Security

DNS rebinding and CSRF prevention, strict Origin header verification, constant-time Bearer token checks, and sanitized subprocess environments.

🍏

macOS Login Daemon

Manage seamlessly via Homebrew. Run brew services start apfel-rs to launch on login on 127.0.0.1:32185 with automated log rotation.

πŸ“œ

JSON Schema Self-Repair

Pass --schema <path|json> for structured outputs with automatic RFC 6901 $defs reference resolution and self-healing repair retries.

πŸ¦™

Full Ollama API Drop-In

Native Ollama protocol compatibility with streaming NDJSON for /api/chat and /api/generate, plus /api/version, /api/show, and /api/ps.

⚑

High-Performance Batch Pipelines

Process high-throughput JSONL streams over standard UNIX pipelines (jq | apfel --batch | jq) with fresh session isolation and zero string reallocation.

Drop-in OpenAI Compatibility

Use Your Favorite Tools & SDKs

Point any OpenAI-compatible app, Cursor, Open WebUI, Python script, or TypeScript SDK directly to http://127.0.0.1:8080/v1.

# POST /v1/chat/completions with SSE Streaming
curl -N -X POST http://127.0.0.1:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "apple-foundationmodel",
    "stream": true,
    "temperature": 0.7,
    "messages": [
      {"role": "system", "content": "You are a concise engineering assistant."},
      {"role": "user", "content": "How does Rust guarantee thread safety?"}
    ]
  }'
UNIX Ergonomics

Command-Line Reference

Powerful flags designed to pipe with cat, jq, and standard shell utilities.

Command / Flag Description Example Usage
apfel <PROMPT> Standard single-shot completion apfel "Explain DNS in one sentence"
--stream Real-time SSE token stream to stdout apfel --stream "Draft a quick release note"
-f, --file <PATH> Attach text, pdf, or image files into context apfel -f src/lib.rs "Summarize the exports"
--code Extract pure code block, stripping fences and prose (exits 7 if no code) apfel --code "Write a Python script to parse JSON"
--require-complete Require complete response; exit code 8 if truncated by budget or length apfel --require-complete --max-tokens 256 "Generate JSON"
--stop <SEQ> Stop sequence to truncate generation at custom delimiter (repeatable) apfel --stop "\nObservation:" "Agent prompt"
--chat Interactive REPL with slash commands (/info, /clear) apfel --chat
--serve Run the OpenAI-compatible HTTP server apfel --serve --port 8080
--mcp-server <CMD> Attach external stdio MCP server for tool calls apfel --mcp-server "./calc_mcp.py" "What is 42 * 10?"
--count-tokens Accurately measure tokens before executing apfel --count-tokens -f long_doc.txt
--benchmark Execute internal throughput and latency stress test apfel --benchmark
--batch Process streaming JSONL lines from stdin with fresh session isolation cat data.jsonl | apfel --batch | jq
--schema <SCHEMA> Enforce JSON Schema on output with self-repair reprompts (repeat up to 2x) apfel --schema schema.json "Generate profile"
--mcp-config <PATH> Load multi-server MCP config file (stdio tools for CLI & chat) apfel --mcp-config mcp.json "Query database"
--image <PATH> Analyze image using Apple Vision OCR and visual feature labeling apfel --image doc.png "Extract text & diagram"
--install-completions Detect shell ($SHELL) and install completions into user directories apfel --install-completions
--adapter <PATH> Load fine-tuned LoRA model adapter (exposed in /v1/models) apfel --adapter ./adapter.bin "Evaluate task"
Deep Dive

System Architecture

How apfel-rs bridges the macOS C-ABI with zero serialization overhead and predictable memory bounds.

Input Ingress

CLI & Axum HTTP

Piped stdin, CLI args, or /v1/chat/completions REST / SSE endpoints.

Rust Core

Session Engine

Sliding window context trimmer, token budgeter, MCP tool loop, and security guards.

Inter-Op Bridge

Swift C-ABI

Zero-copy C-ABI bridge providing memory safety between Rust FFI and Swift actors.

Apple Silicon

Dual Hardware Engines

FoundationModels on Neural Engine (ANE) or open-weights via native MLX on Metal GPU.

Extensibility

Model Context Protocol (MCP)

Equip Apple Intelligence with live external toolsβ€”from calculators to web search and database engines.

βš™οΈ

Automatic Tool Discovery

Launches any stdio MCP server (Python, Node.js, Go, or native executable) and negotiates JSON-RPC schemas automatically.

πŸ”„

Self-Healing Reprompt Loop

When the model triggers a tool call, apfel-rs executes the tool, feeds the output back into context, and reprompts for the final answer.

πŸ›‘οΈ

Process Isolation

Subprocesses run with scrubbed environment variables to prevent API token or credential leaks to external tools.

Developer Reference

Exit Codes

Standardized POSIX exit codes for predictable shell script automation.

Code Constant Meaning
0 SUCCESS Successful completion
1 RUNTIME_ERROR Internal runtime failure or Swift FFI exception
2 USAGE_ERROR Invalid arguments or malformed JSON input
3 GUARDRAIL System safety guardrail triggered
4 CONTEXT_OVERFLOW Prompt exceeds context budget with strict strategy
5 MODEL_UNAVAILABLE Apple Intelligence disabled or model not downloaded
6 RATE_LIMITED System capacity exhausted
7 NO_CODE --code requested but no code block returned
Frequently Asked Questions

Everything You Need to Know

Common questions regarding architecture, privacy, compatibility, and setup.

What is apfel-rs and how does it use Apple Intelligence? β–Ό
apfel-rs is a complete, native Rust implementation and high-performance fork of the original Swift apfel. It bridges directly into Apple's macOS FoundationModels framework on Apple Silicon to execute on-device LLM inference without any cloud latency or telemetry.
Does apfel-rs require an internet connection or cloud API keys? β–Ό
No. apfel-rs is 100% on-device. All inference runs locally through Apple Neural Engine / GPU cores. Zero data ever leaves your Mac, and no OpenAI or third-party subscription keys are needed.
How does apfel-rs achieve a 3.76x speedup over the Swift version? β–Ό
By migrating the HTTP server from Swift's Hummingbird to Rust's axum and tokio runtime, optimizing token counting with zero-allocation buffers, eliminating Swift runtime GC/pause jitter, and interfacing with Swift via a lean, zero-overhead C-ABI bridge.
Can I use apfel-rs as a drop-in local OpenAI backend in Cursor or Open WebUI? β–Ό
Yes! Start the server with apfel --serve --port 8080 (or run brew services start apfel-rs). Configure your client's OpenAI Base URL to http://127.0.0.1:8080/v1. Any arbitrary string can be passed for the API key.
What hardware and macOS versions are supported? β–Ό
You need an Apple Silicon Mac (M1, M2, M3, M4, or later) running macOS Sequoia 26.0 or higher with Apple Intelligence enabled in System Settings.
How does Model Context Protocol (MCP) tool execution work? β–Ό
Pass --mcp-server <COMMAND> to attach an external MCP tool server over standard input/output. apfel-rs performs JSON-RPC capability negotiation, presents tool definitions to the FoundationModel, runs tool calls in an isolated sanitized environment, and re-prompts the model with execution outputs until completion.
How do I run apfel-rs as an automatic login daemon? β–Ό
If installed via Homebrew, simply execute brew services start apfel-rs. Homebrew installs a launchd plist that starts the daemon automatically upon macOS user login on 127.0.0.1:32185.