help-calc

08 Numbers and Units

Llama.cpp Llama Server: What It Is & How to Use It

Card 08-0232 · Updated · Standard formula, shown below

Est. speed 96 tok/s
Context length
4096 tokens
Input
CPU threads
8
Input
Max predictions
512 tokens
Input
Temperature
Low
Input
You enter
Context length (tokens), CPU threads, Max predictions (tokens), Temperature
You get
Est. speed (tok/s)
Rounding
0 dp

Llama.cpp’s llama-server is a built-in HTTP server that lets you run large language models locally and interact with them through a web interface or API. You start it from the command line, point it at a GGUF model file, and it gives you a localhost URL you can open in a browser or call programmatically. It is the simplest way to turn a downloaded model into a usable chat application without writing any code.

What Is llama.cpp?

llama.cpp is an open-source project that implements the LLaMA model architecture in plain C/C++ with no dependencies. Its main goal is to run LLMs efficiently on consumer hardware—CPUs, Apple Silicon, and modest GPUs—by using quantization to shrink model sizes and memory usage. The project was created in March 2023, shortly after Meta released the original LLaMA models, and quickly became the standard way to run LLMs locally. It supports a wide range of models beyond LLaMA, including Mistral, Phi, Gemma, and many fine-tuned variants, as long as they are converted to the GGUF format.

What Is llama-server?

llama-server (formerly called llama.cpp’s server example) is one of the executables that ships with llama.cpp. It embeds the inference engine into a lightweight HTTP server that listens on a port (default 8080) and exposes a REST API plus a simple web chat UI. This means you can:

  • Open http://localhost:8080 in a browser and chat with the model directly.
  • Send POST requests to /completion or /chat/completions to get text completions from your own scripts.
  • Use the OpenAI-compatible API endpoint to plug into tools like SillyTavern, Open WebUI, or custom Python code.

The server handles batching, context management, and multiple concurrent requests, making it a practical choice for local development, prototyping, and personal use.

How to Install and Run llama-server

You can get llama-server in two ways: build from source or download a prebuilt binary. Prebuilt binaries are available for Windows, Linux, and macOS from the project’s GitHub releases page. For most users, downloading the latest release is easiest—just unzip and run the executable.

  1. Download a GGUF model (e.g., from Hugging Face). Popular choices include llama-2-7b-chat.Q4_K_M.gguf or mistral-7b-instruct.Q4_K_M.gguf.
  2. Run the server with a command like: llama-server -m model.gguf --port 8080
  3. Open your browser to http://localhost:8080 and start chatting.

You can also specify the context size (-c 4096), number of threads (-t 8), and GPU layers (-ngl 35) to tune performance. The server prints a log showing the model load time and the URL to access.

Key Features of llama-server

llama-server is not just a toy—it includes several production-relevant features:

  • OpenAI-compatible API: Endpoints like /v1/chat/completions accept the same JSON structure as OpenAI’s API, so you can switch clients with minimal changes.
  • Multi-user support: Multiple clients can connect simultaneously; the server queues requests and manages slots.
  • Grammar-constrained generation: You can force the model to output valid JSON or follow a custom grammar using the grammar parameter.
  • Embeddings endpoint: /embedding returns vector representations of text, useful for RAG or similarity tasks.
  • Metrics endpoint: /metrics exposes Prometheus-style metrics for monitoring.

These features make it a viable backend for local AI applications, not just a chat demo.

How to Choose the Right Model and Settings

Model selection depends on your hardware and task. A 7B parameter model quantized to 4-bit requires roughly 4–5 GB of RAM and runs well on a modern CPU. A 13B model needs about 8–10 GB, and 70B models are only practical on high-end GPUs or with heavy quantization (e.g., 2-bit). For chat, use instruct-tuned models; for code, use CodeLlama or DeepSeek Coder variants.

Key settings to adjust:

  • Context length: Larger contexts use more memory. Start with 4096 and increase only if needed.
  • Temperature: Lower (0.2) for factual answers, higher (0.8) for creative writing.
  • GPU layers: Move as many layers to GPU as your VRAM allows (-ngl flag).
  • Threads: Set to your CPU’s physical core count for best CPU inference.

There is no universal best setting—experiment to find the balance between speed and quality for your specific model and hardware.

Common Problems and Troubleshooting

New users often hit a few predictable issues:

  • Server won’t start: Usually missing model file or wrong path. Double-check the -m argument.
  • Out of memory: Reduce context size or use a smaller quantized model. Check your RAM/VRAM usage.
  • Slow generation: Lower context, increase threads, or offload more layers to GPU.
  • API returns errors: Ensure you’re sending the correct JSON format. For chat completions, include "messages" array.
  • Browser shows blank page: Try a different browser or clear cache; the UI is a single HTML file served by the server.

Most issues are resolved by reading the server log output—it prints detailed error messages.

Security and Privacy Considerations

Running llama-server locally means your data stays on your machine, which is a major privacy advantage over cloud APIs. However, the server does not enforce authentication by default—anyone who can reach the port can use it. If you bind to 0.0.0.0 (default), it’s accessible on your network. For sensitive work, bind to 127.0.0.1 only, or put a reverse proxy with authentication in front. Also be aware that models can generate biased or incorrect content; always review outputs for critical tasks.

Frequently Asked Questions

Q: What is the difference between llama-server and llama-cli?
llama-cli is a terminal-based chat interface that runs a single conversation. llama-server provides an HTTP API and web UI, allowing multiple clients and programmatic access. Use cli for quick tests, server for building applications.

Q: Can I use llama-server with a GPU?
Yes. Build with CUDA or Metal support, then use the -ngl flag to offload layers to GPU. The server will automatically use GPU if available and compiled with support.

Q: Does llama-server support OpenAI’s API format?
Yes, it provides /v1/chat/completions and /v1/completions endpoints that are compatible with OpenAI’s request/response format, so you can use it as a drop-in replacement in many tools.

Q: How do I stop the server?
Press Ctrl+C in the terminal where it’s running. On Windows, you may need to close the window.

Q: What is GGUF and why do I need it?
GGUF is the file format used by llama.cpp to store quantized models. It contains the model weights and metadata in a single file. You must download a GGUF version of a model to use it with llama-server.

Q: Can I run multiple models simultaneously?
Not with a single server instance. You can start multiple server processes on different ports, each with a different model, but they will share system resources.

Related

Formula used
in ctx | Context length | tokens | 4096 | 256 | 131072
in threads | CPU threads | - | 8 | 1 | 128
in pred | Max predictions | tokens | 512 | 1 | 8192
sel temp | Temperature | Low=0.2, Medium=0.7, High=1.0
out speed | Est. speed | tok/s | threads * 12 | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More on this shelf

The whole Numbers and Units shelf →