In ggml-org/llama.cpp, llama serve is the unified CLI subcommand featured in the project's installer quickstart, whereas llama-server is the standalone HTTP server binary built by CMake and shipped in release archives and official Docker images. They launch the same llama.cpp server engine with the same flags, OpenAI and Anthropic routes, and multi-model Router Mode, while production scripts usually invoke llama-server directly for explicit path and image pinning.
How llama-server and llama serve relate inside llama.cpp
Confusion between the two names comes from how llama.cpp packages its developer CLI alongside its standalone tools. Installing the project via its quickstart script gives you a unified llama front-end binary whose subcommands mirror the core tools: llama cli runs interactive prompts and llama serve launches the HTTP API server. Under the hood, llama serve targets the exact same server implementation documented in the llama-server README.
When you build llama.cpp from source, pull prebuilt release archives, or run containers such as ghcr.io/ggml-org/llama.cpp:server-cuda, the executable on PATH is llama-server. Both invocations accept identical flags like -hf, -m, -c, -np, --api-key, and --metrics. Treat llama serve as a convenient quickstart alias on a developer laptop, and standardize on llama-server inside systemd units, Dockerfiles, and CI scripts where deterministic binary paths matter.
# Unified CLI quickstart on a workstation
llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF --port 8080
# Direct server binary in automation or containers
llama-server -m /srv/models/qwen3-8b-q4_k_m.gguf --host 127.0.0.1 --port 8080
Single-model mode vs dynamic Router Mode
Passing -m /path/to/model.gguf or -hf user/repo:quant starts llama-server in single-model mode. The process allocates VRAM and KV cache once at boot for that specific model, binds every worker slot to it, and keeps latency flat because weights never swap out. Single-model mode is the right default when one dedicated model powers an application endpoint or benchmark harness.
Launching llama-server without -m or -hf switches it into Router Mode. In Router Mode, the parent process manages a pool of child model instances and dispatches each request according to the "model" field in JSON payloads (or the ?model= query parameter on GET endpoints like /props and /metrics). By default it discovers models in LLAMA_CACHE, or you can point it at a local directory with --models-dir containing single .gguf files, multimodal subdirectories with mmproj-*.gguf, or multi-shard GGUF folders.
Router Mode handles on-demand hot-swapping cleanly on constrained hardware. Models load automatically on the first matching request unless you pass --no-models-autoload, and you can cap concurrency across models with --models-max (default 4) or enforce GPU headroom with --models-memory-margin so idle least-recently-used instances unload before a larger model loads. For predictable per-model context sizes and GPU layer splits, pair Router Mode with an INI file via --models-preset. Memory budgeting for single and multi-model setups is detailed in the local LLM hardware guide.
# Router Mode scanning a local directory with LRU eviction headroom
llama-server \
--models-dir /srv/models \
--models-max 2 \
--models-memory-margin 1024 \
--host 127.0.0.1 --port 8080 \
--metrics --api-key-file /etc/llama/api-keys.txt
; /etc/llama/models.ini preset for Router Mode
version = 1
[*]
n-gpu-layers = all
flash-attn = on
cache-type-k = q8_0
cache-type-v = q8_0
[qwen3-8b]
model = /srv/models/qwen3-8b-q4_k_m.gguf
c = 32768
np = 4
load-on-startup = true
[qwen2.5-coder-14b]
model = /srv/models/qwen2.5-coder-14b-q4_k_m.gguf
c = 16384
np = 2
OpenAI and Anthropic API routes in one server
A standout practical advantage of llama-server is serving both OpenAI and Anthropic clients from one process without running an external translation proxy. On the OpenAI side, it exposes /v1/chat/completions, /v1/completions, /v1/embeddings, /v1/models, and /v1/responses. On the Anthropic side, it exposes /v1/messages and /v1/messages/count_tokens, supporting streaming SSE events, system prompts, and tools when --jinja is enabled (which is the default).
Requests to /v1/messages accept standard fields like max_tokens, temperature, top_p, top_k, and stop_sequences, plus an extra_params object for llama.cpp-specific sampling controls such as seed, min_p, or repeat_penalty. Authentication works seamlessly through either Authorization: Bearer or Anthropic's x-api-key header. Because template formatting and tool-call extraction vary across GGUF conversions and API dialects, verify both endpoints against your actual tool schemas using AI agent evals before switching coding agents onto a local endpoint.
# OpenAI-compatible request routed by model name
curl -s http://127.0.0.1:8080/v1/chat/completions \
-H "Authorization: Bearer $LLAMA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"qwen3-8b","messages":[{"role":"user","content":"Summarize HTTP 503."}],"temperature":0.2}'
# Anthropic-compatible request to the same llama-server process
curl -s http://127.0.0.1:8080/v1/messages \
-H "x-api-key: $LLAMA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"qwen3-8b","max_tokens":256,"messages":[{"role":"user","content":"Summarize HTTP 503."}],"extra_params":{"min_p":0.05}}'
Authentication, /metrics telemetry, and reverse-proxy hardening
Although llama-server defaults to --host 127.0.0.1 and supports built-in key checking via --api-key or --api-key-file, never expose its port directly to an untrusted network. According to the llama-server README, /health intentionally stays unauthenticated for readiness checks, and CORS headers reflect any incoming Origin by default unless you restrict them with --cors-origins.
Enable Prometheus telemetry by passing --metrics. In single-model mode, GET /metrics returns throughput and queue gauges including llamacpp:prompt_tokens_seconds, llamacpp:predicted_tokens_seconds, llamacpp:requests_processing, llamacpp:requests_deferred, and llamacpp:n_busy_slots_per_decode. In Router Mode, GET /metrics requires a ?model={model_id} query parameter and returns HTTP 400 if it is omitted, so configure per-model scrape targets or an internal collector that enumerates GET /models first.
Place Nginx or Caddy in front of llama-server to terminate TLS, enforce bearer tokens before requests hit the backend, disable response buffering for SSE streaming, and allowlist only /v1/ routes while keeping /metrics, /slots, and /props restricted to loopback or a private monitoring subnet. Follow the host firewall and SSH baseline in the Linux VPS hardening guide.
map $http_authorization $api_ok {
default 0;
"Bearer REPLACE_WITH_RANDOM_TOKEN" 1;
}
server {
listen 443 ssl;
server_name llm.internal;
ssl_certificate /etc/nginx/tls/llm.crt;
ssl_certificate_key /etc/nginx/tls/llm.key;
location /v1/ {
if ($api_ok = 0) { return 401; }
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_buffering off;
proxy_read_timeout 600s;
}
location / {
return 404;
}
}
When to switch to Ollama, vLLM, or SGLang
llama-server excels on CPUs, Apple Silicon, single consumer GPUs, and mixed VRAM/RAM workloads, yet three alternatives outperform it in specific operational regimes:
- Switch to Ollama when solo developers or laptops want tag-based pulls,
Modelfilepresets, and automatic five-minute idle unloading (Ollama FAQ) without managing GGUF files or flags, accepting that its OpenAI layer has no built-in API key auth and stateless/v1/responses(Ollama OpenAI compatibility). - Switch to vLLM when serving many concurrent users on data-center NVIDIA or AMD GPUs with Safetensors, FP8, AWQ, or GPTQ weights, where PagedAttention, tensor parallelism, and high-batch continuous batching beat
llama.cppslots on aggregate throughput. - Switch to SGLang when running complex multi-turn agent trees or heavy structured generation on data-center GPUs, where RadixAttention prefix caching and fast finite-state-machine constrained decoding minimize redundant prefill compute across shared system prompts and tool histories.
For a deeper side-by-side look at Ollama, llama-server, and vLLM across containerization and day-two operations, read the local LLM inference servers guide.
Deployment comparison and migration path
| Server | Primary model format | Multi-model handling | Native APIs | Auth & metrics | Best deployment fit |
|---|---|---|---|---|---|
llama-server (single) |
GGUF (local or -hf) |
One pinned model | OpenAI + Anthropic /v1/messages |
--api-key-file, /metrics |
Dedicated GPU/CPU box, low-overhead API |
llama-server (Router Mode) |
GGUF (--models-dir / INI) |
Dynamic load & LRU unload | OpenAI + Anthropic /v1/messages |
--api-key-file, /metrics?model= |
Multi-model workstation or small team host |
| Ollama | Registry tags, GGUF, Modelfile | Auto-load + OLLAMA_KEEP_ALIVE |
Native /api/* + OpenAI |
Reverse proxy required, /api/ps |
Solo developers, quick local prototyping |
| vLLM | Safetensors, FP8, AWQ, GPTQ | Multi-instance or LoRA adapters | OpenAI + Anthropic Messages | --api-key (proxy needed), /metrics |
High-concurrency production GPU clusters |
| SGLang | Safetensors, FP8, AWQ, GPTQ | RadixAttention KV prefix tree | OpenAI + native generate API | --api-key, Prometheus metrics |
Agentic trees, shared prefixes, datacenter GPUs |
A practical progression keeps client code untouched across stages. Start on a laptop with llama serve -hf ... to validate prompts and tool calling, graduate to llama-server --models-preset behind Nginx when a small team shares one workstation or VPS, and move to vLLM or SGLang behind the same OpenAI gateway only after /metrics shows sustained slot saturation and deferred queues on multi-GPU hardware.