Skip to main content
coreydaley.dev
Docs menu

The fm command: Apple's Foundation Models from Terminal

macOS 27 comes with fm, a command-line tool for the same Apple Foundation Models that power Apple Intelligence. It’s already installed at /usr/bin/fm. You can prompt the on-device model, send it an image, get JSON back, or run it as a local API that tools built for OpenAI-style servers can talk to.

Tested on a MacBook Pro with M2 Pro, macOS 27.2.

Turn it on once

The first time, fm refuses to run:

YOU HAVE NOT AGREED TO THE FOUNDATION MODELS CLI LEGAL NOTICE & TERMS.
Agreeing to the Foundation Models CLI Legal Notice & Terms applies to every
user on the machine, so it must be run as a privileged user (e.g. 'sudo fm license').

Read the terms first with fm license --show. They’re short: the macOS software license, plus an agreement not to access Apple’s models programmatically except as Apple permits. Then agree as an administrator:

sudo fm license

fm license --status confirms it. Mine reads “Agreed to license FM1 version 1.1”. fm asks again when the terms change; I’d agreed on this Mac before and it asked again.

See which models you have

% fm models
  Apple Foundation Models
  ✓ system (AFM 3 Core)
  ✓ pcc (AFM 3 Cloud)

system is the on-device model, and it’s the default. pcc is the larger model on Apple’s Private Cloud Compute servers; add -m pcc to any command to use it.

Run it in Terminal.app. From an AI agent’s shell, pcc showed as unavailable, and other programs’ shells probably will too: “Private Cloud Compute is not available in this context. Please use the Terminal app.” The on-device model works from anywhere.

Private Cloud Compute has usage limits, and Apple doesn’t publish them. fm quota-usage is meant to report them, but on my Mac it only ever said “PCC: ✓ Available”, with no numbers, even while every pcc request was being refused. The limit that actually stopped me was in the system log, from the service that sends requests to Apple’s servers:

% /usr/bin/log show --last 24h --style compact --predicate 'process == "privatecloudcomputed" AND eventMessage CONTAINS "rate limit"'
... [com.apple.privatecloudcompute:RateLimiter] rate limit applied for rate with count=140, duration=86400.000000

That’s 140 requests in 86,400 seconds, a rolling 24 hours, on my Mac with macOS 27.2. Other developers on Apple’s forums have logged different numbers, so yours may differ. A rolling window means the limit doesn’t reset at midnight: each request stops counting 24 hours after you made it. (Type /usr/bin/log, not log: in zsh, log is a different, built-in command.)

Ask it something

% fm respond "In one sentence, what is a haiku?"
A haiku is a traditional Japanese poem consisting of three lines with a
5-7-5 syllable structure, capturing a moment or emotion.

That took about two seconds on-device. With -m pcc, under a second.

It reads standard input, and -i sets instructions:

% echo "Summarize: The quick brown fox jumps over the lazy dog. It was a sunny day and the fox was happy." | fm respond -i "Reply in under 15 words."
A fox jumped over a dog on a sunny day.

fm chat starts a conversation instead. Per its help, sessions are saved in ~/.fm/sessions/ and fm chat --continue picks up where you left off; I didn’t try chat.

Give it an image

The model in macOS 27 takes images. I made a picture of a shopping list and asked about it:

% fm respond --image list.png --text "What's on this list? Answer as a comma-separated list."
2 lemons, 1 dozen eggs, oat milk, coffee beans

Both models got it right. --tool ocr adds Apple’s text recognition as a tool the model can call, and --tool barcode does the same for barcodes. On a photo, the on-device model described one of the Mac’s wallpapers as “a grid of blue and purple pill-shaped objects with gradients and two circular shapes”, which is fair.

Get JSON back

fm schema writes a JSON schema for you, and --schema makes the model fill it in:

% fm schema object --name Item --string name --int quantity > item.json
% fm respond --schema item.json "Two lemons"
{"name": "lemons", "quantity": 2}

There’s also a tagging mode, tuned for pulling topics out of text:

% fm respond --use-case content-tagging "I just got back from hiking in Yosemite and my feet are sore but the waterfalls were amazing."
hiking, Yosemite, waterfalls, feet

fm count-tokens counts tokens for a prompt (9 for “Hello there, how are you today?”) and works only with the on-device model.

Run it as a local API

fm serve starts a server that speaks the Chat Completions API, the format many AI tools and libraries already support:

% fm serve --port 1976
Foundation Models Serve
  url    http://127.0.0.1:1976
  access loopback-only

Then, from another terminal:

curl -s localhost:1976/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"system","messages":[{"role":"user","content":"Name three primary colors."}]}'

The answer, “Red, yellow, blue”, came back in under a second, streamed in chunks. /v1/models lists the models and /health reports which are available. For pcc to work, start fm serve from Terminal.app too.

When pcc hits its limit, fm serve answers HTTP 429 with "type":"insufficient_quota" and a Retry-After of 900 seconds. Don’t trust either Retry-After or /health: on my Mac, /health kept reporting "limit_reached": false while every request was refused, and waiting 15 minutes didn’t help. With streaming on (the default), the same error comes back inside an HTTP 200 response as an error event, so check the body, not just the status code.

By default it listens only on your Mac. It doesn’t ask for an API key: requests with none, or a made-up one, both worked. So --host 0.0.0.0 would let anyone on your network use your Mac’s model. Don’t, unless that’s what you want.

Using it from other tools

I pointed three things at fm serve with the on-device model: OpenAI’s Python library and two open-source command-line tools, llm and aichat. They mostly worked, with one difference from OpenAI’s API to know about.

Ask for a non-streaming answer explicitly. OpenAI’s API answers with a single block of JSON unless the request says "stream": true. fm serve does the opposite: a request that doesn’t say "stream": false gets a stream. A client that leaves the field out and expects JSON breaks. OpenAI’s Python library handed back the raw stream as a string, so reading the reply failed with “‘str’ object has no attribute ‘choices’”, and aichat in non-streaming mode (-S) failed with “error decoding response body”. The fix is to send "stream": false; in Python:

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:1976/v1", api_key="unused")
reply = client.chat.completions.create(
    model="system",
    stream=False,
    messages=[{"role": "user", "content": "Name three primary colors."}],
)
print(reply.choices[0].message.content)

fm serve ignores the key, but set one anyway: without it, the library falls back to your OPENAI_API_KEY and would send your real OpenAI key to the local server. The library also handled system messages, conversations several turns long, streaming, JSON-schema answers (response_format with json_schema) and tool calls, including sending the tool’s result back for a final answer. Some things aren’t there:

  • response_format of type json_object is refused: “Use ‘json_schema’ instead.”
  • max_tokens is ignored; max_completion_tokens works, though an answer cut short still reports finish_reason as "stop", not "length".
  • There’s no embeddings endpoint, and no Responses API (/v1/responses), only Chat Completions.

llm 0.36 worked with everything I tried: streaming, --no-stream, -s system prompts, --schema, a tool call and -c to continue a conversation. Add the model to extra-openai-models.yaml in llm’s configuration folder (dirname "$(llm logs path)" prints where that is):

- model_id: apple
  model_name: system
  api_base: "http://127.0.0.1:1976/v1"
  supports_schema: true
  supports_tools: true

Then llm -m apple "Name three primary colors.". With --no-stream, llm sends "stream": false, so that works too. llm saves every prompt and answer to a local database by default; llm logs off turns that off.

aichat 0.30 worked for streaming answers, a system prompt with --prompt, and files with -f, set up as an openai-compatible client in its config.yaml (on a Mac, in ~/Library/Application Support/aichat/):

model: fm:system
clients:
  - type: openai-compatible
    name: fm
    api_base: http://127.0.0.1:1976/v1
    models:
      - name: system

Its -S (no streaming) option is the one that failed, because it leaves out the stream field.

I tested these with the on-device model only, not pcc.

Use another model

fm can also talk to models that aren’t Apple’s. --model-provider points it at any server that speaks the same Chat Completions API fm serve provides, such as a model running locally in Ollama. I tested it with Ollama 0.40.13 and its llama3.2:3b model (a 2 GB download), which Ollama serves at http://localhost:11434/v1:

% fm models --model-provider http://localhost:11434/v1
  http://localhost:11434/v1
  ✓ llama3.2:3b
% fm respond --model-provider http://localhost:11434/v1 --model llama3.2:3b "In one sentence, what is a haiku?"
A haiku is a traditional Japanese poem consisting of three lines with a
syllable count of 5-7-5, often capturing a moment or image from nature.

--model is required, and fm sends the name exactly as you type it. The first answer took a few seconds while Ollama loaded the model, later ones under a second.

Most of fm respond carries over, with differences. I pointed it at a small test server that logged every request to see what it sends:

  • Instructions (-i) arrive as a system message.
  • --schema is sent as a JSON schema for the answer, so it only works if the server supports structured output. Ollama does: the Item schema from above came back as {"name": "Two lemons", "quantity": 2} (the details vary from run to run). The schema’s fields arrive in a different order on each request, with the order you wrote kept only in an extra x-order key, which Ollama ignores. A small model may then fill the fields in an awkward order: with a four-field schema, Llama 3.2 3B got 6 of 20 answers right through fm and 11 to 15 sent to Ollama directly, fields in order. If the order matters, send the request yourself.
  • --image is converted to a JPEG and sent inline. A text-only model can’t take it: with Llama 3.2 3B, Ollama answered HTTP 400, “model does not support multimodal requests.”
  • --tool ocr and --tool barcode were offered to the model only when an image was attached.
  • --greedy isn’t supported (“Greedy sampling is not supported”), --use-case is accepted but does nothing, and fm count-tokens only works with Apple’s model.
  • fm always streams from the server, even with --no-stream, which only changes how fm prints the answer.

I didn’t try a hosted service or fm chat this way. A hosted service usually wants an API key, which --model-provider-header adds to every request:

fm respond --model-provider https://api.example.com/v1 \
  --model-provider-header "Authorization: Bearer $API_KEY" \
  --model some-model "Hi"

Save it as a default

fm config stores a provider under a name, and can make it the default:

fm config add model-provider local http://localhost:11434/v1
fm config set default-model-provider local
fm config set default-model llama3.2:3b

After that, fm respond "Hi" goes to Ollama with no flags, and fm respond -m system still uses the on-device model. fm config list shows the settings.

They’re saved in ~/.fm/config.json, always in your real home folder (changing $HOME didn’t move it). Headers are saved in plain text, so --model-provider-header with fm config add writes your API key into that file, and fm creates it readable by everyone (-rw-r--r--). On my Mac, that meant other user accounts could read it, not just my own apps. If you store a key there, lock it down:

chmod 700 ~/.fm
chmod 600 ~/.fm/config.json

fm kept those permissions when it saved the file again. Passing the key on the command line instead isn’t private either: other accounts can see a running command’s arguments.

Behind fm serve

fm serve --model-provider <url> puts Apple’s models and the other server’s behind one local address. /v1/models then lists system, pcc and the other server’s models, and a request for any other model name is passed through:

% fm serve --port 1976 --model-provider http://localhost:11434/v1

Then, from another terminal:

curl -s localhost:1976/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"llama3.2:3b","messages":[{"role":"user","content":"Name three primary colors."}]}'

That’s useful when a tool accepts only one base URL and you want it to see Apple’s models and your own side by side. If the other server needs a key, remember that fm serve doesn’t ask for one: anything on your Mac that can reach the port can use it.

Going further