Skip to Content

llama.cpp server mode

llama-server (also called llama.cpp server mode) exposes an OpenAI-compatible HTTP API so IDEs, scripts, and agents share one local model process instead of spawning CLI per request.

Hub: llama.cpp. Queries like llama cpp server and llamacpp server usually mean this surface.

Start the server

./llama-server \ -m models/llama-3.2-8b-instruct.Q4_K_M.gguf \ --host 0.0.0.0 \ --port 8080 \ -c 8192 \ -ngl 99
FlagPurpose
--host / --portBind address for LAN or Docker
-cContext size — see Memory & GGUF
-nglGPU layers; 99 = full offload on CUDA/Metal

Let --fit auto-size unset memory args: Memory guide.

OpenAI client wiring

import OpenAI from "openai"; const client = new OpenAI({ baseURL: "http://localhost:8080/v1", apiKey: "llama", });

Works with Cline, Aider, OpenCode BYOK, and custom agents — set baseURL to your server and pick a model name the server reports.

When to use server vs CLI

PatternTool
One-off script, pipe outputllama-cli
IDE + agent + scripts same modelllama-server
Docker sidecar for dev stackllama-server in container

Server mode amortizes model load time and keeps weights hot in VRAM/unified memory.

Metering

llama.cpp does not ship Prometheus metrics. Instrument at the client or proxy:

MetricHow to capture
Tokens in/outParse API usage fields or count locally
Wall-clock latencyMiddleware on OpenAI client
CPU/GPU utilizationtop, Activity Monitor, nvidia-smi

Tag spans with inference.backend=llama-cpp for fair comparison against Ollama and cloud APIs.

Guardrails

  • Set max_tokens on every API call — server does not cap output by default
  • Reverse-proxy rate limits when exposing on LAN
  • Auth or VPN — never bind 0.0.0.0 without access control on shared networks
  • One model per process; scale with multiple server instances behind a router
Last updated on