Getting Started
Requirements
- macOS 26 (Tahoe) or later, Apple Silicon
- Apple Intelligence enabled in System Settings
- Node.js 20+
Installation
bash
npm install tsfm-sdkA prebuilt libFoundationModels.dylib is bundled with the package — Xcode is not required. If your machine needs a different build, see Building from Source.
Quick Start
ts
import { SystemLanguageModel, LanguageModelSession } from "tsfm-sdk";
const model = new SystemLanguageModel();
const { available } = await model.waitUntilAvailable();
if (!available) process.exit(1);
const session = new LanguageModelSession({
instructions: "You are a concise assistant.",
});
const reply = await session.respond("What is the capital of France?");
console.log(reply); // "The capital of France is Paris."
session.dispose();
model.dispose();Key Concepts
- Model —
SystemLanguageModelrepresents the on-device model. Check availability before creating sessions. - Session —
LanguageModelSessionmaintains conversation state. All generation methods go through a session. - Dispose — Native resources must be released by calling
dispose()when you're done.
What's Next
- Model Configuration — Use cases, guardrails, availability
- Sessions — Creating and using sessions
- Streaming — Token-by-token response streaming
- Structured Output — Typed generation with schemas
- Tools — Function calling
- Error Handling — Error types and recovery
Building from Source
If you need to rebuild the native library:
bash
git clone https://github.com/codybrom/tsfm.git
cd tsfm
npm run buildThis requires Xcode 26+ to compile the Swift bridge.