ai-sdk-llama-cpp has 91 recorded weekly downloads on npm, a decrease of 89.3% over the past 30 days.
It ranks #1683 of 2,256 tracked npm listings by weekly downloads.
Over 90 days, weekly downloads changed by -68.0%.
PluginStats has 121 daily observations since Jun 19, 2026; the latest is from Oct 17, 2026.
About ai-sdk-llama-cpp
ai-sdk-llama-cpp
Alpha Software - This package is in early development. The API may change between versions without notice.
macOS Only - This package currently only supports macOS with Apple Silicon or Intel processors.
A minimal llama.cpp provider for the Vercel AI SDK, implementing the LanguageModelV3 interface.
This package loads llama.cpp directly into Node.js memory via native C++ bindings, enabling local LLM inference without requiring an external server.
Features
• Native Performance: Direct C++ bindings using node-addon-api (N-API) • GPU Acceleration: Automatic Metal support on macOS • Streaming & Non-streaming: Full support for both generateText and streamText • Structured Output: Generate JSON objects with schema validation using generateObject • Tool/Function Calling: Support for AI SDK tools with automatic tool call detection • Chat Templates: Automatic or configurable chat template formatting (llama3, chatml, gemma, etc.) • ESM Only: Modern ECMAScript modules, no CommonJS • GGUF Support: Load any GGUF-format model
Prerequisites
Before installing, ensure you have the following:
• macOS (Apple Silicon or Intel) • Node.js >= 18.0.0 • CMake >= 3.15 • Xcode Command Line Tools
Installation
The installation will automatically:
1. Detect macOS and verify platform compatibility 2. Compile llama.cpp as a static library with Metal support 3. Build the native Node.js addon
Note: Installation on Windows or Linux will fail with an error. Only macOS is supported.
Usage
Basic Example
Streaming Example
Structured Output
Generate type-safe JSON objects that conform to a schema using generateObject:
The structured output feature uses GBNF grammar constraints to ensure the model generates valid JSON that conforms to your schema. This works with:
• Primitive types: string, number, integer, boolean, null • Objects: With properties, required, and additionalProperties • Arrays: With items, minItems, maxItems • Enums and constants: enum, const • Composition: oneOf, anyOf, allOf • String constraints: minLength, maxLength, pattern • Number constraints: minimum, maximum (for integers) • String formats: date, time, date-time, uuid • References: Local $ref to $defs/definitions
Tool Calling Example
Use AI SDK tools with local models. The model decides when to call tools based on the conversation context:
Tool calling also works with streamText. When tools are provided, the provider automatically detects tool call JSON output and emits proper tool-call events instead of streaming raw JSON as text.
Note: Tool calling quality depends heavily on the model. Models fine-tuned for function calling (e.g., Llama 3.1+, Hermes 2/3, Functionary, Qwen 2.5) work best. Generic models may produce inconsistent results.
Embedding Example
Configuration Options
Chat Templates
The chatTemplate option controls how messages are formatted before being sent to the model. Available templates include:
• chatml, llama2, llama2-sys, llama3, llama4 • mistral-v1, mistral-v3, mistral-v7 • phi3, phi4, gemma, falcon3, zephyr • deepseek, deepseek2, deepseek3, command-r • And more (see llama.cpp documentation for the full list)
Generation Parameters
The standard AI SDK generation parameters are supported:
Model Downloads
You'll need to download GGUF-format models separately. Popular sources:
• Hugging Face - Search for GGUF models • TheBloke's Models - Popular quantized models
Example download:
API Reference
llamaCpp(config)
Creates a new llama.cpp language model instance.
Parameters:
• config.modelPath (string, required): Path to the GGUF model file • config.contextSize (number, optional): Maximum context size. Default: 2048 • config.gpuLayers (number, optional): GPU layers to offload. Default: 99 • config.threads (number, optional): CPU threads. Default: 4 • config.debug (boolean, optional): Enable verbose llama.cpp output. Default: false • config.chatTemplate (string, optional): Chat template to use for formatting messages. Default: "auto"
Returns: LlamaCppLanguageModel - A language model compatible with the Vercel AI SDK
LlamaCppLanguageModel
Implements the LanguageModelV3 interface from @ai-sdk/provider.
Methods:
• doGenerate(options): Non-streaming text generation • doStream(options): Streaming text generation • dispose(): Unload the model and free GPU/CPU resources. Always call this when done to prevent memory leaks, especially when loading multiple models
Limitations
This is a minimal implementation with the following limitations:
• macOS only: Windows and Linux are not supported • No image inputs: Only text prompts are supported
Contributing
See CONTRIBUTING.md for development setup and contribution guidelines.
License
MIT
Acknowledgments
• llama.cpp - The underlying inference engine • Vercel AI SDK - The AI SDK framework • node-addon-api - N-API C++ wrapper
Description from the npm listing.
- ai
- llama
- llama.cpp
- vercel
- ai-sdk
- language-model
- gguf
Where ai-sdk-llama-cpp sits in the listing
Each band is one page of 20. Weekly downloads on a log scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Recent observations
Full history (121)Similar npm AI SDKs plugins
Data source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/ai-sdk-llama-cpp. First seen Oct 16, 2026; last successful collection Oct 19, 2026. See the methodology.