apple-llm
Apple's on-device and Private Cloud Compute LLMs, from Python, plus the voices and speech recognition built into macOS. No API key, no account, no developer program membership.
pip install apple-llm
from apple_llm import AppleLLM, probe
probe()
# {"device": {"available": ..., "contextSize": ..., "variant": ...},
# "cloud": {"available": ..., "installed": ...}}
with AppleLLM(tier="device") as llm: # "device" | "cloud" | "auto"
llm.text("Summarize this", system="You are terse.")
llm.json("Extract the fields", schema={...}) # guaranteed to match, on device
Pure-Python wheel, no runtime dependencies, no build step. A small Swift
helper is compiled on first use (with the Xcode Command Line Tools) and cached,
so installing on Linux or an Intel Mac always succeeds and probe() explains
why the model is unavailable there.
Pydantic
from pydantic import BaseModel
class Person(BaseModel):
name: str
born: int
with AppleLLM(tier="device") as llm:
person = llm.json("Ada Lovelace, born 1815.", schema=Person)
person.born # 1815 — a validated Person, not a dict
Optional extra: pip install 'apple-llm[pydantic]'. Plain dict schemas need no
extras.
Async
from apple_llm import AsyncAppleLLM
async with AsyncAppleLLM(tier="device") as llm:
await llm.text("Summarize this")
await llm.stream("Count to three.")
Cleanup is registered with both atexit and weakref.finalize, so a wedged
helper never outlives the interpreter.
Speech
from apple_llm import listen, listen_once, list_voices, speak, synthesize, to_srt, transcribe
speak("Hello there") # out loud, in your System voice
speak("Bonjour", language="fr") # the best French voice on this Mac
speak("Faster", voice="Samantha", speed=1.5, pitch=1.1, volume=0.8)
voices = list_voices(language="en", novelty=False)
audio = synthesize("Hello there", format="wav").audio # bytes
synthesize(long_article, voice="Samantha", out="article.m4a") # or a file
words = synthesize("Every word has a time.", words=True).words
result = transcribe("meeting.mp4") # audio or video
result.text, result.segments, result.language
subtitles = transcribe(data, language="en-US", words=True).to_srt() # or the bytes of a file
said = listen_once().text # returns when you pause
with listen(continuous=True) as session: # until session.stop()
for event in session:
print(event.text, event.final)
None of this needs Apple Intelligence or costs quota, and it runs on your Mac; the only network use is downloading a recognition language the first time you use it.
- Length is not a limit. On an M4 Air, 30 minutes of speech renders in 18
seconds and transcribes in 28, and a read-aloud can run as long as you like. For
long text pass
out: 30 minutes is 11.3 MB as M4A and 80.4 MB as WAV, and withoutoutit is all in memory. - Voices.
voiceis a name or an id; an unknown one is an error suggesting close matches. The default is your System voice, and better ones are free downloads: search System Settings for "System voice". A few voices are only reachable throughsay(engine == "say"): those have speed, but no pitch, volume, SSML or word timings, and asking for those is an error. They can also lose words while Apple's language model is busy in another process, so a file is rendered twice and kept only when the two agree; speaking aloud cannot be checked that way.avspeechvoices are not affected. - Siri voices. Apple does not let apps choose them. Where macOS lists one under
the System voice setting, choose it there and
speak()with novoiceshould use it; this path has not been tested with a Siri voice selected. More. - Formats.
wav,m4a,aac,flac,aiff,cafandpcm(raw samples). macOS cannot encode MP3, Ogg or Opus. It reads WAV, AIFF, CAF, MP3, M4A, AAC, FLAC and MP4 or MOV video, but not WebM, Ogg or MKV. - Recognition. Name the
language, because it is not detected; the default is this Mac's. 68 languages on macOS 27; a missing one downloads on first use, in about 25 seconds, unlessdownload=False.words=Trueadds word timings,hintsnames terms it might miss, andon_segmentandon_progressreport on a long file. - The microphone. macOS asks once, on behalf of whichever app launched this. It
hears everything, including
speak()through your speakers.stop()finishes and keeps what it heard;cancel()discards it. Afinal=Falseevent is a guess the next one replaces. - Ctrl-C stops speech mid-word and raises
KeyboardInterruptas usual. - One at a time. The functions share one helper, which handles one request at a
time. Use
AppleSpeech()for work that must not wait; it has a helper of its own.AsyncAppleSpeechis the same API, awaitable.
The audio endpoints (/v1/audio/speech, /v1/audio/transcriptions) are on the npm
package's server. The repository README
has the measurements.
macOS's voices come with macOS's terms. Apple's licence allows them for personal, non-commercial use and rules out recording or publishing them in a commercial context. Read this before building a product on text to speech.
Read this before you use it
- macOS 26+ on Apple Silicon. No fallback anywhere else. Apple Intelligence has to be on for the models, but not for speech.
- The Xcode Command Line Tools (
xcode-select --install), for compiling the helper. Full Xcode is not needed. - The on-device model is small (~20B sparse, 1–4B active, 8192-token context on macOS 27). Good at classification, extraction, tagging, rewriting and short prose. Bad at code generation and long reasoning.
- The cloud tier is not local. It sends your prompt to Apple's Private Cloud
Compute, off your machine. Free but quota'd, reached through a private
Shortcuts action Apple can change in any OS release, and with no constrained
decoding — so
json()there is a request, not a guarantee. - The cloud tier is rate-limited per Mac, separately from the quota and
invisibly to
probe(): ten calls in about two minutes tripped it here, and every call was then refused for a few minutes, as aQuotaError. Use it for the calls that need it, not batch jobs, and let the device take over:AppleLLM(tier="cloud", fallback="device"). - Streaming is text-only, tools are Apple's built-ins.
stream()gives partials-as-they-arrive;tools=["ocr", "barcode", "spotlight"]enables on-device Vision/Spotlight tools. Generic user-supplied function calling is still a later version.
Two traps worth knowing
Never set temperature=0. Constrained decoding already guarantees the
schema, so greedy decoding buys nothing and reliably degenerates — it padded an
unbounded array forever, then ran away inside a single string (2.7KB of
"tasks-tasks-tasks-…"), turning a 2s call into 20s. The default is 0.4.
Apple honours maxItems but ignores maxLength: bound your arrays.
Keep the client alive. One long-lived helper process holds the model
resident; spawning one per call measured ~17s against ~1.5s. Use the context
manager, or construct once and close() when done. Both traps produce correct
output, only slower, so neither looks like a bug.
What macOS 27 adds
result = probe()
result["device"]["capabilities"] # {"vision", "guidedGeneration", "reasoning", "toolCalling"}
result["device"]["useCases"] # ["general", "contentTagging"]
result["cloud"]["quota"] # {"status": "belowLimit", "approachingLimit": False, ...}
On this machine the on-device model reports vision, guided generation and tool
calling, but not reasoning. The quota is real state read from
PrivateCloudComputeLanguageModel.quotaUsage — the entitlement that blocks PCC
inference does not block reading it — so an exhausted quota becomes an
immediate QuotaError rather than a wasted Shortcuts round trip.
Count tokens before sending, turning a ContextLengthError into arithmetic:
llm.count_tokens(prompt, system=...) # {"tokens": 64, "context_size": 8192}
Reproducible output without the temperature=0 trap. Greedy decoding is
deterministic and degenerates; seeded top-k is deterministic and does not:
from apple_llm import sampling_seeded
llm.text(prompt, sampling=sampling_seeded(42), temperature=0.9)
It works only because the helper uses a fresh session per request — reusing one changes the transcript and with it the output.
Vision, by path — optionally labelled for follow-up turns. A missing file is an error, never a silent drop:
llm.text("What is in this image?", images=["./photo.png"])
llm.text("What is in the image labelled chart?",
images=[{"path": "./scan.png", "label": "chart"}])
Streaming, conversations, tools, documents, and Write-with-Siri presets:
llm.stream("Count to three.", on_delta=print)
chat = llm.conversation("trip-planning")
chat.text("My cat is called Biscuit.")
chat.text("What is my cat called?") # Biscuit.
chat.history() # mirrored turns, oldest first
llm.text("Read the total.", images=["./receipt.png"], tools=["ocr"])
llm.text("Which notes mention the bridge?", tools=["spotlight"])
llm.text("Compare these quotes.", documents=["./a.md", "./b.md"])
llm.rewrite("gonna grab a bite", instruction="Make it formal.")
llm.proofread("Their going to the store...")
llm.summarize(long_text)
llm.ask_screen("What is on this schedule?")
A tagging-specialised model, permissive guardrails for rewriting, and
prewarm() to load model assets up front (worth little once they are resident —
0.31s against 0.36s here — but real on a cold system):
with AppleLLM(tier="device", use_case="contentTagging") as llm:
llm.json("A recipe for sourdough…", schema=tags_schema)
with AppleLLM(guardrails="permissive") as llm:
llm.text("Rewrite more formally: gonna grab a bite")
llm.prewarm()
Errors
ModelUnavailableError (.reason is appleIntelligenceNotEnabled /
modelNotReady / deviceNotEligible / …), SchemaRejectedError,
SchemaValidationError (a cloud reply with no JSON in it, after one repair;
.text is what the model said), ContextLengthError, QuotaError (Apple's
cloud rate limit or quota; .reset_date when Apple gives one), TimeoutError,
SetupRequiredError (including a speech language that is not installed),
RefusalError, UnsupportedError (an unknown voice, a language macOS cannot
recognise, an MP3 output file; also a ValueError), PermissionDeniedError (the
microphone), CancelledError — all subclasses of AppleLLMError.
Note apple_llm.TimeoutError deliberately shadows the builtin name; import it
explicitly.
CLI
apple-llm "What is the capital of Australia?" # short for run
git diff | apple-llm "Write a commit message" # piped text goes in before the prompt
apple-llm probe
apple-llm setup-cloud [--web-search] # one-time, generates + signs locally
apple-llm run --tier cloud --fallback device "…" # on device when the cloud says no
apple-llm run --tier device --system "You are terse." -
apple-llm run --tier cloud --schema schema.json "Extract the fields"
apple-llm run --image photo.png "What is in this image?"
apple-llm run --image scan.png::chart "What is in the image labelled chart?"
apple-llm run --tool ocr --image receipt.png "Read the total."
apple-llm run --document a.md --document b.md "Compare these."
apple-llm run --session trip --stream "What is my cat called?"
apple-llm history --session trip
apple-llm reset --session trip
apple-llm ask-screen "What is on this schedule?"
apple-llm rewrite "gonna grab a bite"
apple-llm run --use-case contentTagging --schema tags.json "A recipe for sourdough…"
apple-llm run --seed 42 "Reproducible output"
apple-llm count --system "You are terse." - # tokens before sending
apple-llm speak "Hello there" --voice Samantha # out loud; no quotes needed
apple-llm speak --file notes.txt -o notes.m4a # or save it, any length
apple-llm voices [--language fr] [--all] # the voices on this Mac
apple-llm transcribe meeting.mp4 -o meeting.srt # the extension picks text, json, srt or vtt
apple-llm listen [--once] # the microphone, live; Ctrl-C keeps what it heard
apple-llm languages [install|remove <code>] # what it can recognise
Schemas
json() runs your schema through to_apple_schema(), which rewrites it into the
restricted dialect Apple's GenerationSchema decoder accepts — nine rules
covering unions, x-order, enums, titles, $ref-by-title, additionalProperties,
string-typed const, empty objects and pattern. Rule 8 exists because
pydantic titles every property and Apple rejects a titled string. See the
full notes in the repo.
License
MIT. Not affiliated with or endorsed by Apple Inc. If apple-llm saved you time, a ⭐ on GitHub helps other Mac developers find it.
Metadata
Release files for apple-llm 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apple_llm-0.3.0.tar.gz | 116.2 kB | Without provenance | Details for apple_llm-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apple_llm-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for apple_llm-0.3.0-py3-none-any.whl |
Total release size: 213.6 kB
Release files / apple_llm-0.3.0.tar.gz
| Download URL | apple_llm-0.3.0.tar.gz |
|---|---|
| Size | 116.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
953438e673e7f57b9875afd202452298c6dad98c73fa045806dfade3fb32efc1
|
|
BLAKE2b-256 checksum How to use checksums |
aa07dd6f9cd53a81df76b5c266b4f2a2edd27ddc7008cc5e3fd6a8fe087a5022
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / apple_llm-0.3.0-py3-none-any.whl
| Download URL | apple_llm-0.3.0-py3-none-any.whl |
|---|---|
| Size | 97.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9278e9620c96099482e11a858f2c5e2e29b0c6492462da4fc4bb54f04835561f
|
|
BLAKE2b-256 checksum How to use checksums |
17eabb338200adc51d73254c6f4ef0dc39acd87e21eba449cf58a53f0795160e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for apple-llm 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.