{"slug": "llama-cpp-local-inference-on-cpu-and-gpu-gguf-models-and-the-built-in-http", "title": "llama.cpp: local inference on CPU and GPU, GGUF models and the built-in HTTP server", "summary": "Llama.cpp, the open source C/C++ inference engine started by Georgi Gerganov and maintained under the ggml-org organisation, lets developers run GGUF-quantised language models locally on CPUs, consumer GPUs or Macs, with fine control over quantisation, context size and CPU/GPU layer offloading. Its llama-server binary exposes an OpenAI-compatible HTTP API, a /health readiness endpoint and, with the --metrics flag, Prometheus metrics prefixed with llamacpp: that surface token counts, throughput and deferred requests as a saturation signal.", "body_md": "llama.cpp is the engine that brought local LLM inference to everyone: a C/C++ implementation with no heavy dependencies, able to run a language model on an ordinary CPU, a consumer GPU or a Mac. Started by Georgi Gerganov and now maintained under the ggml-org organisation, it is one of the most-followed open source projects on GitHub, and a building block for many tools, including Ollama.\n\nUsing llama.cpp directly rather than through a wrapper has several benefits: fine control over quantisation, context size and how layers are split between CPU and GPU, lightweight binaries that are easy to package, and a built-in HTTP server that speaks the OpenAI API dialect.\n\nIn this article we cover the key concepts (GGUF, quantisation, GPU offloading), build and start `llama-server`, then look at how to monitor it: health endpoint, Prometheus metrics, logs and OpenTelemetry traces on the application side, all the way to a backend such as Dynatrace.\n\nThree concepts are enough to get started.\n\n`Q8_0` or `Q4_K_M`.\nThe project ships several tools: `llama-cli` to chat in the terminal, `llama-server` to serve a model over HTTP, `llama-quantize` to produce quantised variants, and `llama-bench` to measure performance on your own hardware.\n\nThe quickest route is a package (Homebrew, winget…) or the prebuilt binaries published with every release on GitHub. To enable a specific backend, build with CMake:\n\n```\ngit clone https://github.com/ggml-org/llama.cpp\ncd llama.cpp\ncmake -B build                  # CPU only\n# cmake -B build -DGGML_CUDA=ON # with CUDA\ncmake --build build --config Release -j\nls build/bin/                   # llama-cli, llama-server, ...\n```\n\nBuild options and the prerequisites for each backend are described in the build guide in the [official llama.cpp repository](https://github.com/ggml-org/llama.cpp).\n\nYou can download a `.gguf` file from Hugging Face, or let llama.cpp do it with the `-hf` option, which takes a Hugging Face repository (and optionally a quantisation variant):\n\n```\nbuild/bin/llama-cli -hf ggml-org/gemma-3-1b-it-GGUF\n```\n\nPick the quantisation according to the memory available: a 7 to 8 billion parameter model in 4-bit fits in a few gigabytes, whereas the 16-bit version needs several times more.\n\n```\nbuild/bin/llama-server \\\n  -m models/my-model-Q4_K_M.gguf \\\n  --host 127.0.0.1 --port 8080 \\\n  -c 8192 \\\n  -ngl 99 \\\n  --metrics\n```\n\n`-c` sets the context size, `-ngl` the number of layers offloaded to the GPU (a high value puts them all there if memory allows), and `--metrics` enables the Prometheus endpoint. An `--api-key` option protects access, and a parallelism option sets how many requests are served at once. Option names change over time: `llama-server --help` is the authority.\n\nThe server also offers a small web interface at its root, handy for a quick test. An official container image is published on the project’s GitHub registry.\n\n```\ncurl -s http://127.0.0.1:8080/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"messages\": [{\"role\": \"user\", \"content\": \"Give three causes of network latency.\"}]}'\n```\n\nResponses include token counts and, on the native endpoint, timing information for prompt processing and generation.\n\nThe `/health` endpoint tells you whether the server is ready; it returns an error while the model is still loading. It is the natural target for a Kubernetes readiness probe or a synthetic monitor.\n\nWith `--metrics`, the `/metrics` path exposes metrics prefixed with `llamacpp:`: counters for prompt tokens and generated tokens, average throughput, requests being processed and requests deferred for lack of a free slot, plus the average number of busy slots per decode call and the highest context size observed. Query your instance to see the exact list:\n\n```\ncurl -s http://127.0.0.1:8080/metrics | grep '^llamacpp'\n```\n\nDeferred requests are the saturation indicator to watch first: they mean every slot is busy and clients are waiting.\n\nllama-server writes to standard output: hardware detection, model loading, how layers are split between CPU and GPU, then one timings line per request (prompt processing time, tokens per second during generation). These lines are invaluable for understanding a degradation; an OpenTelemetry Collector or a host agent can centralise them.\n\nTo our knowledge, the server does not emit OpenTelemetry traces. Since it is OpenAI-compatible, the simplest approach is to instrument the calling application with an OpenAI instrumentation for OpenTelemetry (for example those from OpenLLMetry), with the client pointed at the llama-server URL. Each call becomes a span carrying the model, the tokens and the duration, attached to the trace of the user request.\n\nThe pipeline is the same as for vLLM: an OpenTelemetry Collector scrapes `/metrics` with the `prometheus` receiver, converts the counters to delta, receives OTLP traces from the application and exports to the Dynatrace OTLP endpoint with an API token. We detail this configuration in [vLLM in production](https://span.observer/en/vllm-production-metrics/); you only need to change the scrape target. On a host running OneAgent, process and GPU metrics complete the picture.\n\nUseful indicators: generated tokens per second, deferred requests, client-side latency per request, GPU utilisation and memory, and number of restarts. To correlate this data with the rest of the chain, apply the principles from our article [end-to-end OpenTelemetry](https://span.observer/en/opentelemetry-end-to-end-dynatrace/).\n\n`llama-bench` on your hardware before choosing a quantisation.`--metrics` and a probe on `/health` as soon as a server is shared.`--host 127.0.0.1` by default and add an API key or a reverse proxy before exposing anything.\nOllama is built on llama.cpp and adds simplified model management. llama.cpp gives you more control and more options, with a little more configuration. See our guide [Ollama locally](https://span.observer/en/ollama-local-llm-monitoring/).\n\nYes, that is in fact where it started. Performance then depends heavily on the CPU, memory bandwidth and the quantisation chosen.\n\nStart the server with the `--metrics` option; the metrics are then exposed on `/metrics`, on the same port as the API.\n\nllama.cpp remains the reference for lightweight local inference, from a laptop to a small GPU server. Its built-in server, OpenAI-compatible and equipped with Prometheus metrics, makes it easy to integrate and to observe. To see how it compares with Ollama, vLLM and the other building blocks, read our [comparison of self-hosted open source AI stacks](https://span.observer/en/self-hosted-open-source-ai-stack/).\n\n*span.observer is an independent community blog, not affiliated with Dynatrace LLC or with the projects mentioned. Trademarks belong to their respective owners. Tools change quickly: check commands and options in their official documentation.*\n\n*Originally published on [span.observer](https://span.observer/en/llama-cpp-local-inference-gguf/). French version: [https://span.observer/fr/llama-cpp-inference-locale/](https://span.observer/fr/llama-cpp-inference-locale/).*", "url": "https://wpnews.pro/news/llama-cpp-local-inference-on-cpu-and-gpu-gguf-models-and-the-built-in-http", "canonical_source": "https://dev.to/spanobserver/llamacpp-local-inference-on-cpu-and-gpu-gguf-models-and-the-built-in-http-server-4p3p", "published_at": "2026-11-23 11:30:16+00:00", "updated_at": "2026-11-23 11:42:19.014921+00:00", "lang": "en", "topics": ["large-language-models", "ai-infrastructure", "ai-tools", "mlops", "developer-tools"], "entities": ["llama.cpp", "ggml-org", "Georgi Gerganov", "Ollama", "Hugging Face", "Dynatrace", "llama-server", "GGUF"], "also_reported_by": [], "takeaway": "Run llama-server with --metrics and watch the llamacpp: deferred-request counter first, since it signals every slot is busy and clients are queuing.", "recommendation": {"advice": "Enable --metrics on llama-server and alert on deferred requests, which indicate all slots are saturated and clients are waiting.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/llama-cpp-local-inference-on-cpu-and-gpu-gguf-models-and-the-built-in-http", "markdown": "https://wpnews.pro/news/llama-cpp-local-inference-on-cpu-and-gpu-gguf-models-and-the-built-in-http.md", "text": "https://wpnews.pro/news/llama-cpp-local-inference-on-cpu-and-gpu-gguf-models-and-the-built-in-http.txt", "jsonld": "https://wpnews.pro/news/llama-cpp-local-inference-on-cpu-and-gpu-gguf-models-and-the-built-in-http.jsonld"}}