Both consume the same GGUF files from Hugging Face, so you can switch later.
Sidecar: llama-server
- Bundle the binary. Download the prebuilt archive for each platform you ship from llama.cpp releases (
macos-arm64,win-cpu-x64/win-cuda-*,ubuntu-x64,ubuntu-vulkan-x64, β¦) and placellama-serverplus its shared libraries in your appβs resources. See the install guide for the binary matrix. - Launch it on startup with a free port and the model path, and wait for
GET /healthto return{"status":"ok"}. - Call
/v1/chat/completionswith any OpenAI client. Everything in Chat & Streaming, Function Calling, Structured Output, and Vision & Audio applies unchanged. - Kill the child process when your app exits.
- Node.js / Electron
- Python
- C# / .NET
In-process bindings
- Python (llama-cpp-python)
- Node.js (node-llama-cpp)
- C# (LLamaSharp)
create_chat_completion mirrors the OpenAI request shape (messages, tools, response_format, stream). The package bundles its own llama.cpp build, so upgrade it to pick up new architectures.llama-cpp-2), Go (go-llama.cpp), Java (java-llama.cpp), Dart/Flutter, and more β are listed in the llama.cpp README.
Hybrid on-device + cloud routing
Becausellama-server speaks the OpenAI protocol, one client can target a local model and a cloud model interchangeably: route short, latency-sensitive, or private prompts to the local endpoint and fall back to a hosted deployment (for example vLLM or a cloud provider) for the rest.
messages format, tool definitions, and streaming code are identical on both sides β only the base URL and the penalty field name (repeat_penalty for llama.cpp, repetition_penalty for vLLM/SGLang) differ.
Packaging checklist
- Model download on first launch, not at install time: GGUF files are hundreds of MB to several GB. Show progress, verify the file size, and store it in the user data directory.
- Use
-hfonly in development. In production pin the exact file (-m) so a model-card update cannot change behavior under your users. - Choose the binary per machine. CPU builds run everywhere; ship GPU variants (Metal is built into the macOS binary; CUDA / Vulkan on Windows and Linux) when you have tested them.
- Memory-map, donβt read. llama.cpp uses
mmapby default; keep the model on local disk (not a network share) for fast cold starts. - Benchmark with
llama-benchon representative hardware before deciding on quantization and context size. See Hardware Evaluation.