Apple Foundation Models CLI (fm)
fm is a command line interface (/usr/bin/fm, ships with macOS) to Apple's on-device Foundation Model. Everything runs locally, so there is no API key and no network call.
Key Points / Features
- Single model:
system(on-device Apple Foundation Model, the default) fm availablechecks that the model is available on the machinefm respondis a one-shot prompt; it streams by default and accepts stdinfm chatis an interactive session; sessions are saved to~/.fm/sessions/fm servestarts a Chat Completions API server (OpenAI-style)fm schemagenerates a JSON schema for structured outputfm count-tokenscounts tokens for a prompt, instructions or a saved transcript (on-device model only)fm licenseshows and accepts the Legal Notice & Terms
Commands
| Command | Purpose |
|---|---|
available | Check model availability |
chat | Interactive chat session |
count-tokens | Count tokens in a prompt or instructions |
license | Show and agree to the Legal Notice & Terms |
respond | Generate a response to a prompt |
schema | Generate a structured output generation schema |
serve | Start a Chat Completions API server |
respond
fm respond 'What is Swift?'
fm respond --use-case content-tagging 'Analyze this text'
fm respond --image photo.jpg --text 'What is in this image?'
echo 'What is Swift?' | fm respond
Useful options:
-i, --instructions <text>: system-style instructions--schema <file>: constrain output to a structured output schema--tool <name>: enable a built-in tool (barcode,ocr; repeatable)--image <path>with--label <name>: multimodal input--save-transcript <file>/--resume <file>: persist and continue a conversation--use-case <general|content-tagging>and--guardrails <default|permissive-content-transformations>-g, --greedy: greedy sampling (deterministic);--[no-]stream
Structured output
fm schema object --name Person --string name --int age > person.json
fm respond --schema person.json 'Alice is 30 years old'
The generated schema is plain JSON schema (type: object, properties, required, x-order).
serve
fm serve --port 1976
fm serve --socket /tmp/fm.sock # Unix domain socket, recommended for local Python bindings
Endpoints: GET /health, GET /v1/models, POST /v1/chat/completions (streaming and non-streaming). Because it speaks the Chat Completions format, existing OpenAI-compatible clients can point at it.
count-tokens
fm count-tokens -q 'Hello world' # bare integer
fm count-tokens -i 'Answer concisely' 'What is Swift?'
fm count-tokens --transcript session.json
Links
- Models
- Building LLM apps
- Run
fm <command> --helpfor full options