Free · Daily brief + weekly playbookDaily 60-sec AI Voice Brief + Weekly Production AI Agent PlaybookGet the brief →
PLAYBOOK · 2026 EDITION

Local LLM with llama.cpp and Open WebUI: a Private Chat with Web Search

A private, ChatGPT-style stack on your own hardware: llama.cpp serves a Qwen3 or DeepSeek-R1-Distill GGUF model over an OpenAI-compatible API, Open WebUI adds chats, RAG and users, and SearXNG brings web search. Conversations never leave the machine.

Intermediate7 min readSetup time: 1 hUpdated: Author: Zhemal Khamidun
Key takeaways
  • llama-server runs the GGUF model behind an OpenAI-compatible /v1 API; Open WebUI is the chat UI; SearXNG does the web search.
  • On a 24 GB RTX 4090, Qwen3-32B Q4_K_M at 16K context needs ≈ 23.4 GiB; a q8_0 KV cache cuts it to ≈ 21.5 GiB.
  • Always pass --port 8080: llama-server now listens on 127.0.0.1:9931 by default.
  • Enable SearXNG's json format, give the model 16K+ context, and register the admin account first.
Step-by-step plan
  1. Check the memory budgetSum weights, KV cache and overhead for your model, quant and context.
  2. Install llama.cppUse a release archive, brew, winget, or a source build with -DGGML_CUDA=ON.
  3. Start llama-serverRun Qwen3-32B Q4_K_M via -hf on port 8080 with a 16K context, q8_0 KV cache and an API key.
  4. Test the APIWait for /health to return ok, then send one chat completion with the key.
  5. Configure SearXNGCreate searxng/settings.yml with the json format enabled.
  6. Start the containersFill in the secrets in docker-compose.yml and run docker compose up -d.
  7. Create the admin accountRegister the first user on port 3000 and set the connection provider to llama.cpp.
  8. Turn on web searchEnable Web Search on the model and in a chat; check the sources under the answer.

Why run the model locally

A local stack trades peak model quality for control: prompts, documents and chats stay on your hardware, there is no per-token bill or rate limit, and the model changes only when you change it. The price is upfront — a GPU or a Mac with enough memory.

We use open-weight GGUF models: Qwen3 (14B, 30B-A3B, 32B) and DeepSeek-R1-Distill, which brings R1-style reasoning to 32B and 70B sizes. For frontier-size models, use a cloud API. In Russia the recommended cloud stack is Hermes Agent + DeepSeek API.

Architecture: three services on one machine

llama-server loads the GGUF file into GPU memory and serves an OpenAI-compatible API. Open WebUI keeps users, chats and documents and calls llama-server as an OpenAI endpoint. SearXNG is a metasearch engine on the Docker network: when the model calls its search tool, Open WebUI pulls JSON results from it and feeds the pages into the context.

  • :8080 — llama-server, native on the host for direct GPU access (Docker image: ghcr.io/ggml-org/llama.cpp:server-cuda).
  • :3000 — Open WebUI, the only port your LAN needs.
  • searxng:8080 — SearXNG, visible only inside the Docker network.
Your browser talks to Open WebUI, which sends prompts to llama-server on the GPU and, when the model searches, calls out to SearXNG for JSON results.Browseryou, any LAN deviceOpen WebUI:3000 · chats, RAG, usersllama-server:8080 · OpenAI-compatible /v1GPU / unified memoryGGUF weights + KV cacheSearXNGlocal web search, JSON
Your browser talks to Open WebUI, which sends prompts to llama-server on the GPU and, when the model searches, calls out to SearXNG for JSON results.

Hardware and VRAM: what fits in 24 GB

GPU memory = weights + KV cache + overhead. Weights scale with parameters × bits per weight (Q4_K_M ≈ 4.85, Q8_0 8.5), the KV cache with context × parallel chats; overhead is ≈ 0.5 GiB runtime plus 0.35–0.55 GiB compute buffers. One chat, 16K context, f16 KV unless noted:

Model · quantWeightsKV @ 16KTotal
Qwen3-14B · Q8_014.6 GiB2.5 GiB≈ 18.0 GiB · fits
Qwen3-30B-A3B · Q4_K_M17.2 GiB1.5 GiB≈ 19.6 GiB · fits
Qwen3-32B · Q4_K_M18.5 GiB4.0 GiB≈ 23.4 GiB · too big
Qwen3-32B · Q4_K_M, q8_0 KV18.5 GiB2.1 GiB≈ 21.5 GiB · tight
R1-Distill-Llama-70B · Q4_K_M39.9 GiB5.0 GiB≈ 45.9 GiB · Mac only

DeepSeek-R1-Distill-Qwen-32B has the same 256 KiB-per-token KV cache as Qwen3-32B — plan it like those rows. The VRAM calculator uses the same formula; R1-Distill-Llama-70B matches its Llama-3.3-70B row.

Install llama.cpp

Pick one route: the release archives (CUDA builds for Windows and Ubuntu, arm64 for macOS), Homebrew or winget, or a source build with the CUDA Toolkit for the newest commits.

Package manager or source build
# Package managers
brew install llama.cpp      # macOS and Linux (Metal on Mac)
winget install llama.cpp    # Windows

# Build from source with CUDA (needs the CUDA Toolkit)
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release -j
# binaries: build/bin/ (Windows: build/bin/Release/)

# Check the install
llama-server --version

Run llama-server with Qwen3-32B

-hf downloads the GGUF from Hugging Face on first start and caches it (LLAMA_CACHE moves the cache). This loads Qwen3-32B Q4_K_M fully on the GPU:

Start llama-server (RTX 4090, 24 GB)
# Windows PowerShell: end lines with ` instead of \ or write one line
llama-server -hf unsloth/Qwen3-32B-GGUF:Q4_K_M \
  --host 0.0.0.0 --port 8080 \
  -ngl all -c 16384 -np 1 \
  -fa on -ctk q8_0 -ctv q8_0 \
  --api-key <LLAMA_API_KEY>
  • --host 0.0.0.0 --port 8080 — reachable from the Open WebUI container; without --port you get 9931.
  • -ngl all -c 16384 -np 1 — all layers on the GPU, one chat slot with the full 16K window.
  • -fa on -ctk q8_0 -ctv q8_0 — Flash Attention plus a q8_0 KV cache: 2.1 GiB instead of 4.0 GiB.
  • --api-key — make one with openssl rand -hex 32; every endpoint except /health then needs it.
Check that the model answers
curl http://127.0.0.1:8080/health
# {"status":"ok"} once loaded; 503 while the model is still loading

curl http://127.0.0.1:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <LLAMA_API_KEY>" \
  -d '{"messages":[{"role":"user","content":"Reply with one word: ready?"}]}'

Open WebUI and SearXNG in Docker Compose

Put this file in an empty folder. OPENAI_API_KEY is the llama-server key; generate the other two secrets with openssl rand -hex 32. Create the SearXNG settings (next section) before the first start.

docker-compose.yml
services:
  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    ports:
      - "3000:8080"
    volumes:
      - open-webui:/app/backend/data
    extra_hosts:
      - host.docker.internal:host-gateway
    environment:
      - OPENAI_API_BASE_URL=http://host.docker.internal:8080/v1
      - OPENAI_API_KEY=<LLAMA_API_KEY>
      - ENABLE_OLLAMA_API=False
      - WEBUI_SECRET_KEY=<WEBUI_SECRET_KEY>
      - ENABLE_WEB_SEARCH=True
      - WEB_SEARCH_ENGINE=searxng
      - SEARXNG_QUERY_URL=http://searxng:8080/search
      - WEB_SEARCH_RESULT_COUNT=3
    depends_on:
      - searxng
    restart: unless-stopped

  searxng:
    image: docker.io/searxng/searxng:latest
    volumes:
      - ./searxng:/etc/searxng
      - searxng-cache:/var/cache/searxng
    environment:
      - SEARXNG_SECRET=<SEARXNG_SECRET>
    restart: unless-stopped

volumes:
  open-webui:
  searxng-cache:

Open http://<host-ip>:3000 and register at once: the first account becomes the admin. The llama-server connection is already in Settings → Connections → OpenAI; under Advanced, set Provider to llama.cpp to see and manage the loaded model.

Linux

Traffic from the container arrives over the Docker bridge, not loopback — hence --host 0.0.0.0. Block port 8080 from other machines in your firewall.

Apple Silicon: Metal and unified memory

On a Mac, brew install llama.cpp gives a Metal build and the same command works: -ngl all puts every layer on the GPU, which shares unified memory with the CPU. macOS caps how much memory the GPU may wire — llama.cpp logs it as recommendedMaxWorkingSetSize — and you can raise the cap:

macOS: raise the GPU memory limit
# 64 GB Mac: let the GPU wire up to 52 GiB, keep 12 GiB for macOS and Docker
sudo sysctl iogpu.wired_limit_mb=53248

Per Apple's MLX docs, the value should exceed the model size in megabytes and stay below total memory; it resets on reboot. That fits R1-Distill-Llama-70B Q4_K_M: ≈ 45.9 GiB at 16K, ≈ 43.6 GiB with a q8_0 KV cache.

Tuning and security

  • Parallel chats. -c is the KV budget for all slots: two 16K chats need -np 2 -c 32768 and twice the KV memory.
  • Auto-fit. With the default -fit on, llama.cpp sizes unset arguments like -ngl and -c to free memory.
  • MoE offload. --n-cpu-moe N keeps the expert weights of the first N layers in system RAM.
  • Expose only port 3000 to your LAN; keep 8080 and SearXNG off the internet.
  • Set WEBUI_SECRET_KEY yourself: the auto-generated key lives inside the container, so recreating it logs everyone out.

Common gotchas and fixes

SymptomCauseFix
llama-server starts, but nothing answers on port 8080.Current builds listen on 127.0.0.1:9931 by default.Pass --port 8080, plus --host 0.0.0.0 for containers.
Every web search fails with 403 Forbidden.SearXNG serves only html unless json is enabled.Add json to search.formats and restart the searxng container.
On Linux, Open WebUI cannot reach host.docker.internal.Docker Engine on Linux lacks that name, and traffic comes over the bridge, not loopback.Keep extra_hosts: host.docker.internal:host-gateway and run llama-server with --host 0.0.0.0.
Web search broke after switching the KV cache to q4_0.A q4_0 KV cache degrades tool calling, and search is a tool call.Return to -ctk q8_0 -ctv q8_0; save memory with a shorter context or a smaller quant.
With search on, answers ignore most of the page or lose the question.Results and fetched pages overflow a context below 16K tokens.Give each chat -c 16384 or more and keep WEB_SEARCH_RESULT_COUNT low.
Someone else on the LAN registered first and became the admin.The first account on a fresh instance gets admin rights.Register right after the first start, before sharing port 3000, and set WEBUI_SECRET_KEY explicitly.
A changed env var in docker-compose.yml has no effect.ConfigVar settings are saved to the database on first start, and the database wins (ENABLE_PERSISTENT_CONFIG=True).Change it in the admin Settings, or set ENABLE_PERSISTENT_CONFIG=False.

Frequently asked questions

Which model should I start with on an RTX 4090?

Qwen3-30B-A3B Q4_K_M (≈ 19.6 GiB at 16K), an MoE model with about 3B active parameters per token. For the strongest dense model: Qwen3-32B Q4_K_M with a q8_0 KV cache.

Is the stack fully private?

Prompts, files and chats stay on your machines. Web search sends the query to public engines via SearXNG and fetches the pages the model opens; turn it off for sensitive chats.

Does it work on Windows?

Yes: llama-server runs natively from the CUDA archive or winget, Open WebUI in Docker Desktop, where host.docker.internal works out of the box.

Can I run the full DeepSeek R1 locally?

Not on this hardware — it has 671B parameters. The R1-Distill models (Qwen-32B, Llama-70B) bring its reasoning style to sizes that fit.

Free · Daily AI brief

The AI brief engineers actually read

The day’s most important AI stories — models, tools, prices and agents — in five minutes. Free, unsubscribe in one click.

Jemal Hamidun

Editor-in-chief · Cite this analysis

Jemal Hamidun

Head of AI at Alpina Digital · Academic Supervisor of the Tech Entrepreneurship Department at MIPT

Head of AI & CPO of AlpinaGPT at Alpina Digital, Academic Lead of Tech Entrepreneurship at MIPT. Founder of Hamidun News and Vibe Academy.

Ready-to-paste citation for journalists, blogs and Telegram channels

Source: Hamidun News — Local LLM: llama.cpp + Open WebUI + SearXNG (2026) — Hamidun News https://news.hamidun.com/en/guides/local-llm-llama-cpp-open-webui-2026