Run large language models (LLMs) locally from Node.js using llama.cpp bindings. Version 3.18.1 provides pre-built binaries for macOS, Linux, and Windows (Metal, CUDA, Vulkan) with automatic fallback to source build via cmake (no node-gyp or Python required). Supports JSON schema enforcement, function calling, embedding, reranking, and chat sessions. Full TypeScript types included. Active development with frequent releases synced to upstream llama.cpp. Key differentiator: zero-config GPU acceleration and safe token injection prevention.
npm install node-llama-cppNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Loads a GGUF model and performs a simple chat prompt, showing file setup, model loading, and session creation.
Use import syntax or dynamic import() inside CommonJS modules.
Upgrade Node.js to a version >=20.
Use llama.loadModel() instead of llama.load().
Ensure cmake and build tools are installed, or set NODE_LLAMA_CPP_SKIP_DOWNLOAD=true to force source build.
Use path.resolve(__dirname, 'model.gguf') or path.join with __dirname.
Switch to import syntax or use dynamic import(): const { getLlama } = await import('node-llama-cpp');Use import { getLlama } from 'node-llama-cpp' instead of import getLlama from 'node-llama-cpp'.Use an absolute path: path.resolve(__dirname, 'model.gguf').
Reinstall package, force source build: npm rebuild node-llama-cpp --build-from-source