refusal rate
Subscribe

llama.cpp server reference: install llama-server, the flags that matter, router mode for multiple models, API endpoints, API keys and binding to 0.0.0.0.

[ fig. 01 — how-to ]48×5
[ fig. 01 — how-to ]16×5

Short answer

llama-server is the HTTP server that ships with llama.cpp. Start it with `llama-server -m model.gguf` (or `-hf user/repo`) and it serves OpenAI- and Anthropic-compatible endpoints plus a web UI on 127.0.0.1:9931. Start it with no model and it becomes a router that loads and unloads several GGUF models on demand. It has no authentication until you pass --api-key.

Default address
127.0.0.1:9931
Multi-model
Router mode, max 4 loaded by default
API styles
OpenAI, Anthropic, native
Docs checked
tools/server/README.md, 2026-10-28

Key takeaways

  1. The default port is now 9931, not 8080. Older guides and tool docs still assume 8080, so pass --port explicitly.
  2. Context size, GPU layers and slot count all default to auto: --fit picks the largest context that fits in memory.
  3. Launching llama-server without -m starts router mode, which serves several models from one port and unloads idle ones LRU-first.
  4. There is no auth by default and CORS reflects any origin. Set --api-key before binding to 0.0.0.0, and keep /health in mind: it is always public.
  5. Single-user coding setups usually pin -np 1 so one session gets the whole context.

The llama.cpp server, llama-server, is a single C/C++ binary that loads a GGUF model and exposes it over HTTP. This page is a working reference: install, the flags grouped by job, router mode for several models, the endpoints, and how to lock it down. Every flag and default below is quoted from the server README on master as fetched on 2026-10-28. The project moves weekly, so run llama-server --help on your own build before trusting any default, including ours.

What is llama-server, and when should you use it instead of Ollama?

Use llama-server when you want exact control over the GGUF file, the flags and the endpoints, and Ollama when you want a model catalog and one-word pulls. Both serve an OpenAI-style API on your machine. The difference is how much they decide for you. The full runtime trade-off lives in llama.cpp vs Ollama vs vLLM.

Community sentiment tracks that split. In an r/LocalLLaMA thread from December 2025, one user said they moved to llama.cpp because it was “not as easy to use but works better”, another cited Intel Arc support and speed, and a third went back to Ollama for its simpler interface (thread).

How do you install and start llama-server?

Install a prebuilt package, then point llama-server at a GGUF file or a Hugging Face repo. The install docs list one route per OS:

  • macOS and Linux: brew install llama.cpp. The formula updates automatically with releases.
  • Windows: winget install llama.cpp.
  • Any OS: conda-forge (conda install -c conda-forge llama.cpp, with CUDA, Vulkan or Metal builds), or the binaries on the releases page.
  • From source: build only the server target with CMake.
bash
# build from source (binary lands in ./build/bin/llama-server)
cmake -B build
cmake --build build --config Release -t llama-server

# start with a local file
llama-server -m ./models/qwen-coder-Q4_K_M.gguf

# or download from Hugging Face (defaults to the Q4_K_M quant if the repo has one)
llama-server -hf ggml-org/GLM-4.7-Flash-GGUF:Q4_K_M

On Windows the same flags apply to llama-server.exe. The README’s Docker image is ghcr.io/ggml-org/llama.cpp:server (and :server-cuda). In a container you must pass --host 0.0.0.0, or the port mapping reaches nothing.

Once it’s running, open the address in a browser for the built-in web UI, or check GET /health. It returns 503 while the model loads and {"status": "ok"} when it’s ready.

Note the port. The current default is 127.0.0.1:9931. Up to at least tag b6000 the default was 8080, and most blog posts, editor docs and Docker examples still use 8080. If a client can’t connect after an upgrade, this is the first thing to check. Pass --port explicitly and the question goes away.

Which llama-server flags matter most?

About fifteen flags cover nearly every setup. Most of the rest are sampling, RoPE and CPU-affinity knobs you can leave alone. Each flag also has an environment-variable form (LLAMA_ARG_*), which is handy in Docker and systemd units.

JobFlagWhat it doesDefault (2026-10-28)
Load a model-m, --model FNAMEPath to a GGUF filenone (none = router mode)
Load a model-hf user/model[:quant]Download from Hugging Face, plus mmproj if presentunused
Name it-a, --aliasModel name(s) the API reports, comma-separatedunset
Context-c, --ctx-size NContext window in tokens0 = from model, then fitted
Fit to memory-fit on/off, --fit-ctx NShrinks unset options until the model fitson, minimum context 4096
GPU offload-ngl N/auto/allLayers kept in VRAMauto
Attention-fa on/off/autoFlash Attentionauto
KV cache type-ctk, -ctvCache precision (f16, q8_0, q4_0…)f16
Concurrency-np, --parallel NNumber of slots (simultaneous requests)-1 = auto
Concurrency-kvu / -no-kvuOne shared KV pool for all slotson when slots are auto
Templates--jinjaUse the model’s Jinja chat template (needed for tool use)enabled
Network--host, --portBind address(es) and port127.0.0.1, 9931
Auth--api-key, --api-key-fileRequired key(s), comma-separated or one per linenone
Ops--metrics, --slotsPrometheus endpoint, slot monitoroff, on
Ops--sleep-idle-seconds NUnload the model after N idle seconds-1 = never

Three of these trip people up most.

Context. -c 0 no longer means a small fixed window. With --fit on, the server takes the largest context that fits the free memory at load time. That is convenient on a dedicated GPU and surprising on a shared one. Pin -c if you need headroom, and see context length settings for how much memory each step costs.

Slots. -np splits work across parallel slots. When you set it explicitly, the context is divided between slots unless the KV cache is unified. GitHub issue #17989 shows how easily this confuses people: a user passed --parallel 1, still got 4 slots (the log read setting n_parallel = 4 and kv_unified = true), and closed the issue with a linked fix. If you depend on the slot count, read the startup log or GET /slots rather than assuming.

Offload. Mixture-of-experts models have their own CPU-offload flags (--cpu-moe, --n-cpu-moe), covered in MoE offloading in llama.cpp. Draft-model flags are in speculative decoding in llama.cpp.

How do you serve several models from one llama-server?

Start llama-server without -m and it runs in router mode: one process that loads and unloads models on demand and forwards each request to a child llama-server per model. The README calls this “Using multiple models”. It answers the old complaint that llama.cpp serves one model at a time. One Hacker News commenter corrected a project README that still said so in October 2026 (HN).

[ fig. 01 — Router mode request flow. Source: llama.cpp tools/server/README.md, fetched 2026-10-28 ]
In router mode, one llama-server with no model loaded routes each request by its model field to a child process per model and unloads idle models least-recently-used first.
bash
# serve every GGUF in a folder (multi-file models go in their own subfolder)
llama-server --models-dir ./models --models-max 2 -c 32768 -np 1

# or define per-model settings in an INI file
llama-server --models-preset ./my-models.ini

How it behaves, per the README:

  • Sources. The router finds models in three places: the Hugging Face cache (anything you fetched with -hf), --models-dir, and --models-preset. Restart the router after adding files to the cache.
  • Routing. POST endpoints route by the "model" field in the JSON body. GET endpoints such as /props route by a ?model= query parameter.
  • Limits. --models-max caps loaded models (default 4, 0 = unlimited) and evicts the least recently used. --models-memory-margin N also unloads idle models until the new one fits with N MiB left free per device. A model that is serving a request is never unloaded.
  • Presets. In the INI file, keys are flag names without dashes (n-gpu-layers = 123, c = 4096), a [*] section holds shared defaults, and command-line flags win over both. Host, port and API key belong to the router and are stripped from presets.
  • Autoload. Models load on first request unless you pass --no-models-autoload or add ?autoload=false per request.

Router mode doesn’t add VRAM. One HN commenter described a coding agent that, on its own initiative, spawned a subagent on a lighter model. Their machine fits one model at a time, so llama-server ended up thrashing between the two models (HN). If your harness can pick models, either give it one model name or set --models-max 1 and expect reload pauses.

Which API endpoints does llama-server expose, and how do you secure them?

llama-server speaks three API dialects on one port, and none of them is authenticated until you set a key. The main routes:

RouteStyleUse
GET /health, /v1/healthnativeReadiness probe, always public
GET /v1/modelsOpenAIModel list (and /models with load state in router mode)
POST /v1/chat/completionsOpenAIChat, tools, JSON schema output
POST /v1/completions, /v1/responses, /v1/embeddingsOpenAIRaw completion, Responses API, embeddings
POST /v1/messages, /v1/messages/count_tokensAnthropicClients built for Claude’s API
POST /infillnativeFill-in-the-middle code completion
GET /slots, /metricsnativePer-slot state, Prometheus (needs --metrics)

To expose the server beyond localhost, do these four things in order:

  1. Set a key. Use --api-key (or --api-key-file, one key per line). Clients then send Authorization: Bearer <key>, or x-api-key on the Anthropic route. A bad key gets an OpenAI-style 401 Invalid API Key.
  2. Bind deliberately. --host 0.0.0.0 listens on every IPv4 interface. You can pass a comma-separated list or a .sock path instead to bind only where you need it.
  3. Tighten CORS. By default the server reflects any Origin with credentials allowed. The README recommends setting --cors-origins to your frontend’s origin on a LAN, and an API key plus a reverse proxy for anything public. TLS is available natively only if you build with -DLLAMA_OPENSSL=ON and pass --ssl-key-file/--ssl-cert-file. Otherwise terminate TLS at the proxy.
  4. Leave agent tools off. --tools, --agent and the MCP proxy flags are marked experimental: “do not enable in untrusted environments”. They expose file read/write and shell execution over the API.

A common pattern among HN commenters is to keep the server on a private network rather than the internet. One runs llama-server on a stronger machine on the LAN, reaches it over Tailscale, and keeps the coding agent itself in a Docker container with a single workspace mount (HN).

How do you connect editors and coding agents to llama-server?

Point any OpenAI-compatible client at http://<host>:<port>/v1, with any non-empty key if you didn’t set one. The README’s own examples use base_url="http://localhost:9931/v1" and api_key="sk-no-key-required".

bash
curl http://127.0.0.1:9931/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLAMA_API_KEY" \
  -d '{"model": "qwen-coder", "messages": [{"role": "user", "content": "Write a Python retry decorator"}]}'

Some practical notes:

  • The model field. In single-model mode the server answers whatever model name you send. In router mode the name selects the model, so set -a aliases or preset names that match what your editor sends.
  • Tool calling. Agent harnesses need tool calls parsed from the chat template. --jinja is on by default now, but older builds and some blog commands pass it explicitly. Tool use on /v1/messages requires it.
  • Claude Code and other Anthropic clients. Use the /v1/messages route. The setup is covered in using a local LLM with Claude Code.
  • Tracking token use. One HN commenter points agent users to GET /slots for up-to-date per-session token counts when a harness reports context use vaguely (HN).

What do developers report in practice?

The recurring pattern in public reports: people pin the flags that defaults get wrong for their workload, and the bugs they hit are usually multi-GPU or slot accounting, not the API. These are community reports, not our tests.

  • A long-context, single-user coding setup. One HN commenter posted their full command for Qwen 3.8 27B (Unsloth UD-Q4_K_XL) at 131k context: --ctx-size 131072 --parallel 1 --cache-type-k q8_0 --cache-type-v q8_0 --host 0.0.0.0 --port 8080, plus a draft model for speculative decoding (HN). Three choices stand out: one slot so the whole window serves one agent, a q8_0 KV cache instead of the f16 default, and an explicit port.
  • Row split on old multi-GPU rigs. A user running a 32B Q8_0 model across three Tesla P100s got garbled output from the second chat turn onward with --split-mode row. Removing the flag fixed the output but cut speed sharply. Disabling Intel VT-d (IOMMU) in the BIOS fixed it, after a contributor pointed at GPU peer-to-peer access (issue #16517). The default layer split avoids this.
  • Slot counts that don’t match the flag. See issue #17989 above. Verify with /slots.
  • Model thrash under agents. See the router section above. One loaded model plus an agent that calls a second model means reloads on every switch.

FAQ

What is the default port for llama.cpp server?

On current builds, 9931, bound to 127.0.0.1. Older releases (for example tag b6000) used 8080, which is why many guides and client configs still show 8080. Set --port explicitly to avoid the ambiguity.

How do I make llama-server reachable from other machines?

Pass --host 0.0.0.0 (or a specific interface address) and open the port in your firewall. Set --api-key first, because the server has no authentication by default, and consider a reverse proxy with TLS.

Can llama.cpp server run multiple models at once?

Yes. Start it without -m to use router mode, give it --models-dir or --models-preset, and requests route by their model field. By default up to 4 models stay loaded, with least-recently-used eviction.

Is llama-server OpenAI-compatible?

It serves /v1/chat/completions, /v1/completions, /v1/responses, /v1/embeddings and /v1/models, and the README says compatibility “suffices to support many apps” without claiming full spec parity. It also serves the Anthropic Messages API at /v1/messages.

How do I see the llama-server arguments for my version?

Run llama-server --help. The README flag tables are generated from the same help output, but your installed build may be older or newer than the docs you’re reading.

Sources (9)
  1. llama.cpp HTTP Server README (tools/server/README.md, master, fetched 2026-10-28)
  2. llama.cpp server README at tag b6000 (port default 8080)
  3. llama.cpp docs: Install pre-built version (docs/install.md)
  4. Homebrew formula: llama.cpp
  5. GitHub issue #17989: --parallel 1 initializes 4 slots (Dec 13, 2025)
  6. GitHub issue #16517: Garbled output with --split-mode row (Oct 11, 2025)
  7. Hacker News comment: full llama-server command for Qwen 3.8 27B at 131k context (Oct 25, 2026)
  8. Hacker News comment: agent subagent forces llama-server to thrash between models (Sep 30, 2026)
  9. r/LocalLLaMA thread: users on switching from Ollama to llama.cpp (Dec 2025)

Keep reading

[ fig. 02 — comparison ]18×8

Ollama vs llama.cpp vs vLLM: which should you use for local coding models?

Oct 29, 2026 · Comparison

Use Ollama if you are one developer who wants a local coding model running in a few commands. Use llama.cpp when you want direct control over GGUF files, quantization and server flags. Use vLLM when many people or agents share GPUs and you need batching. All three expose OpenAI-compatible endpoints, so your editor tooling rarely decides the choice; concurrency and hardware do.

Read
[ fig. 03 — how-to ]18×8

How do you set the context length in Ollama, LM Studio and llama.cpp?

Nov 2, 2026 · How-to

In Ollama, set the context length with the OLLAMA_CONTEXT_LENGTH environment variable, the app's slider, or a num_ctx parameter in a Modelfile or API request. In LM Studio, set it in the model's load settings or with lms load --context-length. In llama.cpp, pass -c. Ollama defaults to 4k tokens on GPUs under 24 GiB of VRAM, and its docs recommend at least 64k for coding agents.

Read
[ fig. 04 — how-to ]18×8

How does speculative decoding work in llama.cpp, and does it speed up coding?

Nov 2, 2026 · How-to

Speculative decoding in llama.cpp lets a cheap drafter (a small model, the main model's own MTP head, or an n-gram lookup) guess several tokens, then has the main model verify them in one batched pass. Output is identical to normal decoding. On code, where tokens are predictable, reported speedups run from about 1.6x to 2x; with a mismatched or slow drafter it can make generation several times slower.

Read