llama.cpp server: a local OpenAI-compatible endpoint without Ollama
Point a client at llama.cpp on 127.0.0.1:9931, set --alias, and pin -c before you trust a tutorial that still says port 8080.
The llama.cpp project ships a small HTTP server for a GGUF file. The server README calls the binary llama-server. The project README and the llama.app serve page call that job llama serve. Either command loads the file and answers HTTP. The OpenAI-shaped routes live under /v1. A browser chat (Llama Chat) is on unless you pass the flag that turns the UI off.
Ollama is a different program. It downloads a model by name and listens on port 11434. LM Studio is the window for the same kind of file, on port 1234. This note is the path for a GGUF you already have, or for llama serve -hf when you accept one download, and for a script or editor that needs a base URL you typed yourself.
The flags below are the ones printed on those three pages on 20 Nov 2026. Run --help on the binary you installed if a flag is missing. The pages move.
When this server is the right one
Use llama-server or llama serve when the client is a script, an editor plugin, or Open WebUI, and the model is a file on disk. Stay with Ollama when you want ollama pull and you already know the name. Stay with LM Studio when the person at the keyboard will not open a terminal, or when you want its memory hint before the download.
The server README lists OpenAI-compatible chat completions, completions, and embeddings, an Anthropic Messages route, and the built-in chat app. One process serves one model until you start the router on purpose. The llama.app page starts that router with llama serve and no model argument. In router mode the model field is required. Leave that until the single-file check below passes.

A new -hf repo uses the network once. A later request to 127.0.0.1 stays on the machine.
Start it, then read the port
The project README’s install lines are curl -LsSf https://llama.app/install.sh | sh and, on Windows, irm https://llama.app/install.ps1 | iex. The same page also points at pre-built binaries on the GitHub releases page, at Docker, and at a source build. After that install, the quick start it prints is:
llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF
That -hf value is the example on the README the day this note was written. Use the repo you actually want. The example string changes.
A build from the server README produces llama-server:
cmake -B build
cmake --build build --config Release -t llama-server
The binary is ./build/bin/llama-server. The quick start on that page is:
./llama-server -m models/7B/ggml-model.gguf -c 2048
models/7B/ggml-model.gguf is the page’s placeholder. Point -m at the GGUF you have. The next sentence says this server listens on 127.0.0.1:9931. The argument table matches that sentence: --host defaults to 127.0.0.1, and --port defaults to 9931.
The Docker block on the same page is a different port. It publishes 8080 and passes --host 0.0.0.0 --port 8080. A curl copied from that block, aimed at a binary you started without --port, reaches no process. The port in the command you saved is the number that matters.
curl -sS http://127.0.0.1:9931/health
curl -sS http://127.0.0.1:9931/v1/models
/health is public. The README says it skips the API key check, and /v1/health is the same check. HTTP 503 with the message Loading model means the weights are still loading. HTTP 200 means the process can take a request. In this single-model start, /v1/models returns one object. The id is the path you gave -m. meta can be null while the load is unfinished. When meta is present, n_ctx_train is the context the file was trained with. The example object on the page shows 131072 for one Llama 3.1 GGUF. That figure belongs to the example file.
Give the client a short name before you hand it the URL:
llama-server -m models/my-model.gguf -c 2048 --alias my-model
--alias is the flag the models section names for the id field. With it, /v1/models reports my-model. Without it, the id is the filesystem path, and the next config copies a path that breaks when the file moves.
If the install only put llama serve on the PATH, the llama.app page uses the same flags:
llama serve -m models/my-model.gguf -c 2048 --alias my-model
Point the client at that process
The base URL is http://127.0.0.1:9931/v1.
The server README’s Python sample sets api_key to sk-no-key-required. That string is filler in the sample. --api-key defaults to none, so a library that refuses an empty key can take any placeholder. Once you pass --api-key, the header has to be Authorization: Bearer plus that exact value. --api-key-file holds one key per line. Lines that start with # are comments.
In single-model mode the chat route ignores model. The README says the field is required in router mode and ignored in single model mode. Put the alias in the client anyway, so the name on the screen matches /v1/models.
curl http://127.0.0.1:9931/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"my-model","messages":[{"role":"user","content":"Reply with one word: ready"}]}'
The llama.app page’s first curl omits model and sends Hello!. The server README’s curl includes a model name and Authorization: Bearer no-key. Use the one-word prompt as the check. A long answer hides a template that ignored the roles.

A 503 on /health means the load is still running. Call /health again before you change a flag.
The argument table says --chat-template defaults to the template stored in the GGUF, and --jinja defaults to enabled. The chat-completions section on the same page says a supported template is what makes that route behave, and that ChatML is used by default. Those two sentences name different defaults. If the reply ignores the system line, pass --chat-template with a name from the list printed beside that flag (llama3, chatml, gemma, and the rest of the list on the page), or pass --chat-template-file with the template the model card publishes. Use a name that list already contains.
The training number is a property of the file
-c / --ctx-size defaults to 0. The argument table says 0 means the size is loaded from the model. The llama.app table says -c 0 uses the model’s full context window. --fit defaults to on, and the argument table says it adjusts unset arguments so they fit in device memory. --fit-ctx defaults to 4096, the smallest context --fit may set. The router section says that with --fit on, a loaded instance takes the largest context that fits at load time, and that a build with no GPU treats host memory as unlimited, so that cap does not apply.
n_ctx_train on /v1/models describes the file. The running server can be on a smaller window. The quick start pins the window with -c 2048. The llama.app configuration example pins -c 16384. Choose a size the document needs and the machine can hold, pass it as -c, and keep that flag in the command you will run tomorrow. A paste of a long file into a small window comes back as a summary of whatever still fit.
The native /completion response includes truncated when the prompt tokens plus the predicted tokens exceed n_ctx. On the chat route, the README counts tokens in context as prompt_n + cache_n + predicted_n inside timings. When that sum sits on the -c you passed and the answer drops the opening of the file, the window is the limit. Raise -c, or shorten the prompt, then run the one-word check again.
The llama.app parallel section says each slot holds one conversation and the context is shared across slots. -np defaults to auto (-1 on the server README). The example llama serve -m model.gguf -c 16384 -np 4 tells you the pool is shared. Read the startup log after you change -np and use the size that log reports.
--context-shift defaults to disabled. Its own line calls it a switch for infinite text generation. Leave it off for a normal chat request.
Who can open the port
--host defaults to 127.0.0.1. That default is the client on the same machine. The Docker quick start listens on every interface inside the container (--host 0.0.0.0) and publishes port 8080 on the host. That command leaves --api-key unset. A published 8080 on a cloud VM, or on a shared network, lets anyone who can reach the port use the model and the CPU.
The llama.app compose example sets LLAMA_ARG_HOST to 0.0.0.0 and maps 9931:9931. The host value is the door. That example also leaves the key unset.
For a second computer you trust, keep the server on 127.0.0.1 and open an SSH tunnel. If the process has to listen on a LAN address, pass --api-key or --api-key-file in the same command. The server README marks --tools and the agent flag as switches to leave off outside a trusted environment. An editor calling /v1/chat/completions can work with both of those left off.

Write the port into the command you save. The Docker snippet and the native quick start on the same README use different ports.
--offline forces the cache and blocks network access. Once the GGUF is on disk, that flag makes a later start stop when the file is missing, instead of downloading another copy.
What to connect
Open WebUI, an editor plugin, or a script can use http://127.0.0.1:9931/v1 with the alias as the model name. One model per process is the setup the checks above cover. Router mode, llama serve with no -m, is the llama.app way to load several repos on that port, and there the model field has to match an id from /v1/models.
-ngl defaults to auto (a number, auto, or all). The CUDA Docker example uses the image ghcr.io/ggml-org/llama.cpp:server-cuda and passes --n-gpu-layers 99. A slow run on a machine that has an NVIDIA GPU is the image or the build, and swapping the GGUF leaves those layers where the build put them.
Keep the job smaller than the one you would give a hosted frontier model: one function, one section of a file. Which tasks belong on the machine is local models for a private repo.
Related
- Ollama — pull by name, port 11434, and the context column in
ollama ps - LM Studio — a window, and port 1234
- Open WebUI — a browser in front of a local base URL
- Private chat stacks, Nov 2026 — which browser to put on top once the model answers
- Local models for a private repo — which tasks are worth keeping on the machine
Share