Skip to main content

CLI and OpenAI-compatible HTTP server for Apple Foundation Models (Apple Intelligence)

Project description

apple-fm-cli

A small command-line interface and local HTTP server that drive Apple’s on-device Foundation Models (Apple Intelligence) from Python. The repo bundles a ctypes-based apple_fm_sdk wrapper around the system model plus apple_fm_cli, which adds prompting, optional tools, JSON-schema-guided output, and an OpenAI-shaped API for clients like Codex.

Requirements

  • macOS with Foundation Models available (the SDK checks availability and reports a reason if not).
  • Python ≥ 3.14

Install

From PyPI (macOS, Python 3.14+):

pip install apple-fm-cli
# or: uv pip install apple-fm-cli

From a git checkout (editable):

pip install -e .
# or: uv pip install -e .

Entry point: apple-fm-cli.

The published wheel includes a prebuilt libFoundationModels.dylib (Apple silicon / arm64). To rebuild it after changing foundation-models-c, run swift build -c release in src/apple_fm_sdk/foundation-models-c and copy .build/*/release/libFoundationModels.dylib to src/apple_fm_sdk/lib/ before building distributions.

Publishing to PyPI (maintainers)

CI (recommended): GitHub Actions workflow .github/workflows/publish.yml runs on published releases and on manual dispatch. One-time setup: in PyPI → Account → Publishing, add a trusted publisher for this repo with workflow file publish.yml (no GitHub Environment unless you configure both sides to use one). Then:

  1. Bump the version in pyproject.toml and merge.
  2. Rebuild and commit src/apple_fm_sdk/lib/libFoundationModels.dylib if the Swift bridge changed.
  3. Create a GitHub Release from a tag (or use Actions → Publish to PyPI → Run workflow after a tag points at the release commit).

Manual upload: uv run --with build python -m build then uv run --with twine twine upload dist/* using an API token. Prefer trusted publishing in CI over storing long-lived tokens in ~/.pypirc or GitHub secrets.

CLI

Query the model (plain text or structured JSON):

apple-fm-cli query "Summarize this idea in one sentence."
apple-fm-cli query --format json --schema '{"type":"object","properties":{"title":{"type":"string"}}}' "Name this topic."

Optional tools (comma-separated): bash (local shell), google_search (DuckDuckGo lite + page fetch).

apple-fm-cli query --tools bash,google_search "What’s in README.md in the cwd?"

Legacy-style flags are still accepted: -q / --query, --output, --output-schema.

Server

Starts a FastAPI app that mimics parts of the OpenAI Chat Completions and Responses APIs (including SSE for streaming), so tools that expect those endpoints can point at your machine instead of a cloud provider. Large agent system prompts are truncated heuristically to fit smaller local context windows.

apple-fm-cli server --host 0.0.0.0 --port 8000
  • POST /v1/chat/completions
  • POST /v1/responses

Codex

  1. Start the server (see above), e.g. on port 8000.

  2. Add a provider and profile to ~/.codex/config.toml:

    [model_providers.apple]
    name = "apple"
    base_url = "http://localhost:8000/v1"
    env_key = "OPENAI_API_KEY"
    
    [profiles.apple]
    model = "fm"
    model_provider = "apple"
    model_context_window = 4096
    
  3. Run Codex with that profile:

    codex -p apple
    

env_key is the environment variable Codex uses for the bearer token. The local server does not need a real OpenAI key; set OPENAI_API_KEY to any non-empty placeholder if your Codex build requires it to be present.

Other agent harnesses

Anything that can target an OpenAI-compatible HTTP API (Chat Completions and/or Responses, including SSE) can point base_url at http://<host>:<port>/v1 and use a model id string of your choice—the server echoes the requested model name. Prefer a context window that matches what the on-device model can handle (4096 is a reasonable default for local sessions). If the client insists on an API key, keep using a dummy value in the configured env var unless you add auth in front of the server yourself.

Layout

Path Role
src/apple_fm_sdk/ Session, tools, guided generation, tokenizer, native bridge bindings
src/apple_fm_cli/ query / server, built-in tools, schema → Generable helpers
notes/ Design notes (Responses SSE lifecycle, native bridge, e2e testing)

Licensing

apple_fm_sdk source files carry Apple Inc. copyright headers; refer to any accompanying license text distributed with that SDK.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apple_fm_cli-0.1.2.tar.gz (157.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apple_fm_cli-0.1.2-py3-none-any.whl (134.5 kB view details)

Uploaded Python 3

File details

Details for the file apple_fm_cli-0.1.2.tar.gz.

File metadata

  • Download URL: apple_fm_cli-0.1.2.tar.gz
  • Upload date:
  • Size: 157.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apple_fm_cli-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d4514f2b0c020cb0991cdbbf36db0191d0a1208a29c803071c4529ab386de921
MD5 c1970c31292c22eb009f2149ac3cb910
BLAKE2b-256 c91de974a2128f4224bda9589b2a37bc143faa6c5105b3b953be802ddce57a28

See more details on using hashes here.

Provenance

The following attestation bundles were made for apple_fm_cli-0.1.2.tar.gz:

Publisher: publish.yml on sohail288/apple-fm-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apple_fm_cli-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: apple_fm_cli-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 134.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apple_fm_cli-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0014f39e7074231caf859d8e31234c9ff5074383c7cc6cce39a2621d36bd122
MD5 734473d90a6be45349e83ab6534c2577
BLAKE2b-256 224ef086513fd979d0bbb006416cbcf7252cc02657d1314edce38f4d567b74bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for apple_fm_cli-0.1.2-py3-none-any.whl:

Publisher: publish.yml on sohail288/apple-fm-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page